Skip to content

Commit 4ded3bc

Browse files
committed
Adding a trigger to get missing latitude and longitude fields filled.
If Tilia adds a site with missing latitude and longitude, then this should get the fields added.
1 parent 0c537db commit 4ded3bc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

function/triggers/sitegeoms.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CREATE OR REPLACE FUNCTION ti.site_bounding() RETURNS TRIGGER
2+
AS $$
3+
BEGIN
4+
IF NEW.latitudenorth IS NULL AND NEW.geom IS NOT NULL THEN
5+
UPDATE ndb.sites
6+
SET (longitudeeast, latitudenorth, longitudewest, latitudesouth) =
7+
(ST_XMax(geog::geometry),
8+
ST_YMax(geog::geometry),
9+
ST_XMin(geog::geometry),
10+
ST_YMin(geog::geometry));
11+
END IF;
12+
RETURN NEW;
13+
END;
14+
15+
$$ LANGUAGE plpgsql;
16+
17+
CREATE TRIGGER updatelocations
18+
AFTER INSERT ON ndb.sites
19+
FOR EACH ROW
20+
EXECUTE PROCEDURE ti.site_bounding()

0 commit comments

Comments
 (0)