[postgis-users] DWithin when distance is 0

Paul Ramsey pramsey at cleverelephant.ca
Thu Apr 1 08:28:42 PDT 2010


No, it's not intended, but in your second test case you actually
modify the SQL being used... the SQL in the st_dwithin function
definition tests st_distance() < tolerance, which is incorrect, and
you test <= which is correct. So that's why there's a discrepancy. If
you upgrade to a later member of the 1.3 series you should find things
work. Or just upgrade all the way to 1.5 :)

P

On Thu, Apr 1, 2010 at 6:34 AM, Tobias Sauerwein
<tobias.sauerwein at camptocamp.com> wrote:
> 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
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
>



More information about the postgis-users mailing list