I am newbie in postgreSQL. I have 2 tables, observation and landcover, i want to create a trigger which would allowed to update the column observation.land based on the spatial information according to the second layer (table) landcover.code_06.
I mean, If I update point layer observation in QGIS , I want to have in the attribute table same information in column LAND as in the column CODE_06.
I've created this, but i have no idea, what's wrong or why it doesn't work.
ALTER TABLE observation ADD COLUMN land varchar (20)
CREATE OR REPLACE FUNCTION landinfo_land()
RETURNS trigger AS
$BODY$
BEGIN
NEW.land := observation.land
FROM observation.land AS b, landcover.code_06 AS w
WHERE w.geom && NEW.geom AND
ST_Intersects(ST_PointOnSurface(NEW.geom), b.geom);
RETURN NEW;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
ALTER FUNCTION landinfo_land() OWNER TO postgres;
CREATE TRIGGER update_land_value
BEFORE INSERT OR UPDATE
ON observation
FOR EACH ROW
EXECUTE PROCEDURE landinfo_land();
Aucun commentaire:
Enregistrer un commentaire