# [postgis-users] ST_DWithin with radius 0.000001

=?UTF-8?Q?Nicklas_Av=E9n?= nicklas.aven at jordogskog.no
Tue May 25 01:22:20 PDT 2010

```Hallo

What you are doing with ST_Dwithin is to check if your geom and geometry have parts closer to (or exactly) 0.00001 mapunits from eachother. If you are using a meter based SRID then you are checking if they are within 0.00001 meters from eachother. So actually in this case your points can be just outside the polygon and returning true. If you want to use st_dwithin you should use 0 instead of 0.00001 . But I don't think that is any faster than ST_Intersects. The important thing in both cases is to have working spatial indexes.

put an index on geom column in my_neighbour table and analyze the table.

Create index idx_mn_geom
on my_neighbour
using gist(geom);
analyse my_neighbour;

Then try:
SELECT id, geom
FROM my_neighbour
WHERE ST_Intersects (geom, geometry);

I guess that is the best solution.

Hope that helps

Nicklas

2010-05-25 nguyen liem  wrote:

Hi all
>
>At the first time i used ST_Contains but it take a long time, so I used ST_Dwithin to improve the performance for the query statement but i don't know it is correct or not.
>I would like to know my points are within in polygon or not:
>
>SELECT id, geom
>FROM my_neighbour
>WHERE ST_Dwithin (geom, geometry, 0.00001)
>
>geometry: is a polygon(input parameter).
>0.00001: I means the radius of geometry is 1 meters, is it right?
>
>
>Cheers.
>
>--
>Liem Nguyen
>Developer
>Axon Active Corp.
>----------------------------------------------------------------------------
>Direct Line      : +84 38 948 4645
>Fax                  : +84 38 811 3489
>Mobile Phone  : +84 168 994 8897
>Skype ID         : liemnguyendl2204
>Email               : liem.nguyen at axonactive.net / liemnguyendl at gmail.com
>Web Site          : axonactive.vn
>Address           : 87 Thang Long Street,Gate 2 Ward 4,
>                          Tan Binh District, HCM city, Vietnam.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20100525/4f05b758/attachment.html>
```