Skip to content

Instantly share code, notes, and snippets.

@javikalsan
Created February 10, 2014 11:20
Show Gist options
  • Save javikalsan/8914210 to your computer and use it in GitHub Desktop.
Save javikalsan/8914210 to your computer and use it in GitHub Desktop.
Trigger for postgis to calculate geometry area on hectares
SELECT AddGeometryColumn('geoms', 'the_geom', 25830, 'MULTIPOLYGON', 2 );
Trigger sup. ha
BEGIN
IF (TG_OP = 'INSERT') THEN
NEW.supha := area(NEW.the_geom)/10000;
ELSIF (TG_OP = 'UPDATE') THEN
IF NOT (NEW.the_geom ~= OLD.the_geom) THEN
NEW.supha := area(NEW.the_geom)/10000;
END IF;
END IF;
RETURN NEW;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment