1 Mar 2004 05:10
Re: Triggers and Spatial
Romi Hardiyanto <rodin <at> ewesewes.net>
2004-03-01 04:10:49 GMT
2004-03-01 04:10:49 GMT
For about 8 months, i have been using this trigger:
CREATE OR REPLACE FUNCTION "public"."tr_position_geopoint" () RETURNS
trigger AS'
BEGIN
IF (NEW.longitude IS NOT NULL OR NEW.longitude = 0) AND (NEW.latitude
IS NOT NULL OR NEW.latitude = 0) THEN
BEGIN
NEW.geopoint=''POINT('' || NEW.longitude || '' '' || NEW.latitude
|| '')'';
-- rough a hundred meter (3 sec)
SELECT INTO NEW.location_road_name name FROM t_location_road
WHERE the_geom && expand(NEW.geopoint,0.000278) ORDER BY
distance(the_geom,NEW.geopoint) ASC LIMIT 1 OFFSET 0;
IF NEW.location_road_name IS null THEN
-- rough 30 meters (1 sec)
SELECT INTO NEW.location_road_name name FROM t_location_road
WHERE the_geom && expand(NEW.geopoint,0.000833) ORDER BY
distance(the_geom,NEW.geopoint) ASC LIMIT 1 OFFSET 0;
END IF;
RETURN NEW;
END;
END IF;
END;
'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
the geopoint is geometry type (POINT), longitude and latitude is double
the t_location_road.the_geom is database of linestrings
Romi H
(Continue reading)
RSS Feed