[postgis-users] DWithin when distance is 0

Tobias Sauerwein tobias.sauerwein at camptocamp.com
Thu Apr 1 06:34:31 PDT 2010


Hi,

I am having some troubles using DWithin when the passed-in distance is 0. My
query should return all geometries that are within or within a given
distance of a rectangle. DWithin works fine as long as the distance not
equals 0. If so, no geometries are returned. If I choose a very small
distance it works somehow.

select AsText(the_geom) from points where ST_DWithin(the_geom,
ST_GeomFromText('POLYGON((-180 -90, 180 -90, 180 90, -180 90, -180 -90))',
4326), 0);
 astext
--------
(0 rows)

select AsText(the_geom) from points where ST_DWithin(the_geom,
ST_GeomFromText('POLYGON((-180 -90, 180 -90, 180 90, -180 90, -180 -90))',
4326), 0.000000000000000000000000000000000000000000000000000001);
            astext
-------------------------------
 POINT(56.25 32.34375)
 POINT(-45 47.8125)
 POINT(-26.71875 -54.140625)
 POINT(116.3671875 61.171875)
 POINT(131.8359375 -21.796875)
(5 rows)


I am using version 1.3.3, so according to the manual [1] and this workshop
[2], ST_DWithin is just translated into a combination of ST_Expand, && and
ST_Distance. But if I make a query that looks like the definition of
ST_DWithin, the points are returned.

select AsText(the_geom) from points
where
  the_geom && ST_Expand(GeomFromText('POLYGON((-180 -90, 180 -90, 180 90,
-180 90, -180 -90))', 4326), 0)
AND
  GeomFromText('POLYGON((-180 -90, 180 -90, 180 90, -180 90, -180 -90))',
4326) && ST_Expand(the_geom, 0)
AND
  ST_Distance(the_geom, GeomFromText('POLYGON((-180 -90, 180 -90, 180 90,
-180 90, -180 -90))', 4326)) <= 0;
            astext
-------------------------------
 POINT(56.25 32.34375)
 POINT(-45 47.8125)
 POINT(-26.71875 -54.140625)
 POINT(116.3671875 61.171875)
 POINT(131.8359375 -21.796875)
(5 rows)


Is this behaviour intented?

Thank you,
Tobias


[1]: http://www.postgis.org/documentation/manual-1.5/ST_DWithin.html
[2]: http://workshops.opengeo.org/postgis-spatialdbtips/click-analyze.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20100401/21f5e953/attachment.html>


More information about the postgis-users mailing list