[postgis-users] building a polygon with variables
Gold, Jack L (US SSA)
jack.gold at baesystems.com
Tue May 8 07:26:48 PDT 2012
I'm not even sure how to express this properly, but I'll try. I'm trying to build a query which will select positions within a specified polygon. I have the query:
SELECT * FROM positions WHERE ST_Within(geometry(positions.location), ST_GeomFromText('POLYGON((l b, r b, r t, l t, l b))'::text, 4326));
I want to be able to replace l, b, r, and t with variable values in a plpgsql function like so:
$BODY$
DECLARE
l integer;
r integer;
b integer;
t integer;
BEGIN
SELECT pli_config.filter_left_longitude INTO l FROM pli_config;
SELECT pli_config.filter_right_longitude INTO r FROM pli_config;
SELECT pli_config.filter_bottom_latitude INTO b FROM pli_config;
SELECT pli_config.filter_top_latitude INTO t FROM pli_config;
SELECT * FROM positions
WHERE st_within(geometry(positions.location), st_geomfromtext('POLYGON((l b,r b,r t,l t,l b))'::text, 4326));
END;
$BODY$
The problem I have is I don't know the proper syntax to replace the variables in the single-quoted statement or even if it is possible. Any ideas?
--Jack Gold
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20120508/4a7a3f20/attachment.html>
More information about the postgis-users
mailing list