[postgis-users] within/contains

Matthew Perry perrygeo at gmail.com
Thu Sep 15 01:40:12 PDT 2005


Nicol,

On 9/15/05, Nicol Hermann <postgis at geoworld.de> wrote:
> 
> i wonder why the following statements returns different results:
> 
> select within(GeomFromText('POLYGON((10 10,30 10,30 20,10 20,10 10))',
> -1), GeomFromText('POLYGON((0 0, 40 0, 40 30, 30 0, 0 0))', -1) );
> => FALSE



If you are trying to test intesections between two rectangles, I believe you 
have your X&Y switched in the 4th coordinate of your second geometry:

instead of:

select within(GeomFromText('POLYGON((10 10,30 10,30 20,10 20,10 10))',
-1), GeomFromText('POLYGON((0 0, 40 0, 40 30, 30 0, 0 0))', -1) );
=> FALSE

it should be:

select within(GeomFromText('POLYGON( (10 10,30 10,30 20,10 20,10 10))',
-1), GeomFromText('POLYGON((0 0, 40 0, 40 30, 0 30, 0 0))', -1) );
=> TRUE

According to the original geometry as defined in your query, geos was 
returning the correct result. (A simple sketch on graph paper will show you 
why... does anyone use graph paper anymore or am I the only one ??)

-- 
Matt Perry
perrygeo at gmail.com
http://www.perrygeo.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20050915/7b5e974b/attachment.html>


More information about the postgis-users mailing list