Bayu Kurniawan R
Bikin Trigger untuk Insert/Update the_geom
Apabila kita mempunyai Layer yang bertipe point, maka kita bisa menambahkan/mengupdate point tersebut dalam database PostgreSQL.
Misal kita mempunyai tabel map_point yang mempunyai field2 sebagai berikut:
TABLE map_point
(
id character varying(254),
nama character varying(254),
x double precision,
y double precision,
the_geom geometry,
)
dimana x dan y adalah koordinat titik tersebut dan the_geom adalah koordinat dalam format PostGIS.
Kita bisa menambah/mengupdate titik tersebut tanpa menyentuh field the_geom dengan membuat Trigger.
Pertama kita membuat function yang bernama map_point_change(), seperti dibawah ini :
CREATE OR REPLACE FUNCTION map_point_change()
RETURNS trigger AS
$BODY$DECLARE
the_geom_insert text;
the_geom_update text;
BEGIN
IF (TG_OP = ‘INSERT’) THEN
the_geom_insert = ST_GeomFromText(’POINT(’|| new.x || ‘ ‘ || new.y ||’)', 4326);
UPDATE map_aset SET the_geom = the_geom_insert WHERE gid=new.gid;
ELSIF (TG_OP = ‘UPDATE’) THEN
IF new.x <> old.x OR new.y <> old.y THEN
the_geom_update = ST_GeomFromText(’POINT(’|| new.x || ‘ ‘ || new.y ||’)', 4326);
UPDATE map_aset SET the_geom = the_geom_update WHERE gid=new.gid;
END IF;
RETURN NEW;
END IF;
RETURN NEW;
END;
$BODY$
LANGUAGE ‘plpgsql’ VOLATILE
COST 100;
ALTER FUNCTION map_point_change() OWNER TO postgres;
Lalu buat Trigger seperti dibawah ini :
CREATE TRIGGER map_point_change
AFTER INSERT OR UPDATE
ON map_point FOR EACH ROW
EXECUTE PROCEDURE map_point_change();
About
Planet Geo Indonesia is a GIS/geo- related blog aggregator, written by Indonesian bloggers and mostly in Indonesian Language... read on »
Contributors
Except otherwise noted BK and Geografiana.com has no affiliation whatsoever with the authors. All materials, links, copyrights, opinions expressed in each blog solely belongs to the original authors.
Link to this site
Feel free to use this image to promote this planet on your website/weblog, you can simply copy-and-paste the code below:

All opinions belong to their respective owners, others, copyright © 2006-2007 Buana Katulistiwa.




