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

Nicklas Avén nicklas.aven at jordogskog.no
Fri Mar 11 02:13:53 PST 2011


Hallo

What is the error message that you got?

I don't think this is a PostGIS issue but an issue when building the
string.

If I don't misunderstand this, what you are sending to the database is:

select attribute1, the_geom from table1 where
st_contains(st_geomfromtext('POLYGON($stringPolygonCoordinate)'),
table1.the_geom);

instead of:

select attribute1, the_geom from table1 where
st_contains(st_geomfromtext('POLYGON((35.1343 24.15454, 35.2454
24.2565,35.35675 24.3565,35.1343 24.15454))'), table1.the_geom);

What you should do is something like:
select attribute1, the_geom from table1 where
st_contains(st_geomfromtext('POLYGON(". $stringPolygonCoordinate.")'),
table1.the_geom);


/Nicklas



On Fri, 2011-03-11 at 09:55 +0000, zhang zhe wrote:

> Hello,
>  
> I am programming php application with postgres. I need to select the
> points which locate inside the polygon. Here is my code
> <?php
> $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?
> Thanks
>  
> 
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20110311/0e7a28ce/attachment.html>


More information about the postgis-users mailing list