Yancho
By: a guest | Jan 26th, 2008 | Syntax:
SQL | Size: 0.69 KB | Hits: 121 | Expires: Never
-- Function: give_source(text, integer, integer)
-- DROP FUNCTION give_source(text, integer, integer);
CREATE OR REPLACE FUNCTION give_source(text, integer, integer)
RETURNS integer AS
$BODY$
DECLARE
pojnt ALIAS FOR $1;
box ALIAS FOR $2;
dist ALIAS FOR $3;
r_source INTEGER;
BEGIN
SELECT source INTO r_source
FROM streets s
WHERE
(
the_geom && expand (pointfromtext(pojnt),box) AND
distance (s.the_geom , pointfromtext(pojnt)) < dist
)
ORDER BY distance (s.the_geom , pointfromtext(pojnt)) ASC
LIMIT 1;
RETURN r_source;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION give_source(text, integer, integer) OWNER TO yancho;