[postgis-users] st_contains() function with polygon doesn´t work

zhang zhe luckyclare at hotmail.com
Fri Mar 11 01:55:06 PST 2011

I am programming php application with postgres. I need to select the points which locate inside the polygon. Here is my code
$stringPolygonCoordinate="(35.1343 24.15454, 35.2454 24.2565,35.35675 24.3565,35.1343 24.15454)";
$query1 = "select attribute1, the_geom from table1 where st_contains(st_geomfromtext('POLYGON($stringPolygonCoordinate)'), table1.the_geom);
$result1= pg_query($query1) or die('Query failed: ' . pg_last_error());
pg_query("select sum(attribute2) from table2 where st_contains(st_geomfromtext('POLYGON($stringPolygonCoordinate)'), table2.the_geom) group by attribute3;") or die('Query failed: ' . pg_last_error());
But it doesn´t work. I wonder, does the polygon()function only take integer/float as input? Sinct $stringPolygonCoordinate variable is string? I also tried to modify the code like this
$query1 = "select attribute1, the_geom from table1 where st_contains(st_geomfromtext('POLYGON(to_number($stringPolygonCoordinate))'), table1.the_geom);
It also doesn´t work. If Polygon() doesnot accept string as input, how can I convert the string to Integer without using complicated for loop? Is there ready function in postgres? 
Can anyone help me?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20110311/48ae076e/attachment.html>

More information about the postgis-users mailing list