Skip to main content
Tweeted twitter.com/StackDBAs/status/822895038774607873
grammar, spelling
Source Link
Andriy M
  • 23.2k
  • 6
  • 59
  • 103

Trigger to automatically calculatingcalculate area when adding polygon in PostgisPostGIS

I need help with writing a trigger to automatically update and insert into a column the area of a polygon being created using PostgreSQL/PostGIS and QGIS.

This is what I have but itsit's not updating when I add new features.

CREATE OR REPLACE FUNCTION calc_area()
RETURNS trigger AS
$BODY$
BEGIN
NEW.area_ha := ROUND((st_area(NEW.geom::geography)/10000)::numeric,2);
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql;


CREATE TRIGGER area_calculate AFTER INSERT OR UPDATE ON public."Guyana_Coastal_Zone"
    FOR EACH ROW EXECUTE PROCEDURE calc_area();

Trigger to automatically calculating area when adding polygon in Postgis

I need help with writing a trigger to automatically update and insert into a column the area of a polygon being created using PostgreSQL/PostGIS and QGIS.

This is what I have but its not updating when I add new features.

CREATE OR REPLACE FUNCTION calc_area()
RETURNS trigger AS
$BODY$
BEGIN
NEW.area_ha := ROUND((st_area(NEW.geom::geography)/10000)::numeric,2);
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql;


CREATE TRIGGER area_calculate AFTER INSERT OR UPDATE ON public."Guyana_Coastal_Zone"
    FOR EACH ROW EXECUTE PROCEDURE calc_area();

Trigger to automatically calculate area when adding polygon in PostGIS

I need help with writing a trigger to automatically update and insert into a column the area of a polygon being created using PostgreSQL/PostGIS and QGIS.

This is what I have but it's not updating when I add new features.

CREATE OR REPLACE FUNCTION calc_area()
RETURNS trigger AS
$BODY$
BEGIN
NEW.area_ha := ROUND((st_area(NEW.geom::geography)/10000)::numeric,2);
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql;


CREATE TRIGGER area_calculate AFTER INSERT OR UPDATE ON public."Guyana_Coastal_Zone"
    FOR EACH ROW EXECUTE PROCEDURE calc_area();
Slight reformatting - changed code into code
Source Link

I need help with writing a trigger to automatically update and insert into a column the area of a polygon being created using PostgreSQL/PostGIS and QGIS.

This is what I have but its not updating when I add new features.

CREATE OR REPLACE FUNCTION calc_area() RETURNS trigger AS $BODY$ BEGIN NEW.area_ha := ROUND((st_area(NEW.geom::geography)/10000)::numeric,2); RETURN NEW; END; $BODY$ LANGUAGE plpgsql;

CREATE TRIGGER area_calculate AFTER INSERT OR UPDATE ON public."Guyana_Coastal_Zone" FOR EACH ROW EXECUTE PROCEDURE calc_area();

CREATE OR REPLACE FUNCTION calc_area()
RETURNS trigger AS
$BODY$
BEGIN
NEW.area_ha := ROUND((st_area(NEW.geom::geography)/10000)::numeric,2);
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql;


CREATE TRIGGER area_calculate AFTER INSERT OR UPDATE ON public."Guyana_Coastal_Zone"
    FOR EACH ROW EXECUTE PROCEDURE calc_area();

I need help with writing a trigger to automatically update and insert into a column the area of a polygon being created using PostgreSQL/PostGIS and QGIS.

This is what I have but its not updating when I add new features.

CREATE OR REPLACE FUNCTION calc_area() RETURNS trigger AS $BODY$ BEGIN NEW.area_ha := ROUND((st_area(NEW.geom::geography)/10000)::numeric,2); RETURN NEW; END; $BODY$ LANGUAGE plpgsql;

CREATE TRIGGER area_calculate AFTER INSERT OR UPDATE ON public."Guyana_Coastal_Zone" FOR EACH ROW EXECUTE PROCEDURE calc_area();

I need help with writing a trigger to automatically update and insert into a column the area of a polygon being created using PostgreSQL/PostGIS and QGIS.

This is what I have but its not updating when I add new features.

CREATE OR REPLACE FUNCTION calc_area()
RETURNS trigger AS
$BODY$
BEGIN
NEW.area_ha := ROUND((st_area(NEW.geom::geography)/10000)::numeric,2);
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql;


CREATE TRIGGER area_calculate AFTER INSERT OR UPDATE ON public."Guyana_Coastal_Zone"
    FOR EACH ROW EXECUTE PROCEDURE calc_area();
Source Link
Acid
  • 41
  • 1

Trigger to automatically calculating area when adding polygon in Postgis

I need help with writing a trigger to automatically update and insert into a column the area of a polygon being created using PostgreSQL/PostGIS and QGIS.

This is what I have but its not updating when I add new features.

CREATE OR REPLACE FUNCTION calc_area() RETURNS trigger AS $BODY$ BEGIN NEW.area_ha := ROUND((st_area(NEW.geom::geography)/10000)::numeric,2); RETURN NEW; END; $BODY$ LANGUAGE plpgsql;

CREATE TRIGGER area_calculate AFTER INSERT OR UPDATE ON public."Guyana_Coastal_Zone" FOR EACH ROW EXECUTE PROCEDURE calc_area();