# [postgis-users] Re: st_dwithin in SRID 4269

nicklas.aven at jordogskog.no nicklas.aven at jordogskog.no
Sat Apr 25 11:05:19 PDT 2009

```Hallo

Someone have to correct me if I'm wrong but as I remamber it from my nautical experience from quite along ago:
A nautical mile is 1852 meters yes. But not a degree. the distance of a degree is depending on if you are talking about a longitude or latitude degree. A latitude degree can be converted to meters. I think one degree is divided in 60 minuites. And one miniuite is divided in 60 seconds and if I remember right on second is the same as one nautical mile; 1852 meter. But if we are talking about longitude degrees it depends on how close you are to the poles. If you are just one meter from the pole you just have to take a walk of some meters to pass all 360 degrees but if you are walking at the equator you will have to walk and swim about 40000 km.

This is why you have to transform your geometry to a meter-based srid before calculating distances right.

What you first have to do is to tell the system what srid your data originally has if that isn't already done when loaded. That you do with st_setsrid:
http://www.postgis.org/documentation/manual-svn/ST_SetSRID.html

then when the system knows what you have (that is stored together with your geometry), then you can transform it to desired meterbased srid with st_transform:
http://www.postgis.org/documentation/manual-svn/ST_Transform.html

Hope things get clearer (and hope I'm right)

/Nicklas

2009-04-25 Sachin Srivastava  wrote:

>
>>
2009/4/25 Sean Fulton <seanasy at gmail.com>
>>
On 2009-04-25 09:50:55 -0400, Sachin Srivastava <sachin.srivastava1984 at gmail.com> said:
>
>I am a newbie, could somebody explain what distance transformation  should i
>use to eliminate discrepancy in results for the following 2 queries
>
>1) SELECT * from table1 where st_dwithin(geom1, geom2, distance);
>*(Note, geom1 and geom2 are in SRID 4269)
>*
>2) SELECT * from table1 where st_dwithin(transform(geom1, 2163),
>transform(geom2,2163), distance);
>*
>Note:Here distance is in meters
>
>The things that i understood so far are, distance has to be in the same SRID
>as the two geoms, I knew distance in meters, so the second query will give
>me correct results however what transformation should i do in the first
>query distance value to get the same result as of query 2.
>
>Sachin,
>
>I believe the answer is that you use query 2 that you provided.  Query 1 will always give you distance in degrees which is going to be meaningless.   You will never get meters out of Query 1 without transforming the coordinates as you did in Query 2.  You could try to convert the result of Query 1 from degrees to meters but that's really doing it backwards and I wouldn't trust the results.  Query 2 is the correct approach.
>
> Sean
>
>
>_______________________________________________
>postgis-users mailing list
>postgis-users at postgis.refractions.net
>postgis.refractions.net/mailman/listinfo/postgis-users
>
>Sean,
>
>
>1 degree is 1852 meters, so if i do distance/1852, in the Query1 i should get the correct results, but that is not happening.
>I guess that conversion has to do a lot with what SRID i am using.
>
>So what you suggest is the best way to find whether two geoms are at'dist' distance apart.  Whether the following query will do in allcases.
>
>SELECT * FROM table where st_dwithin(transform(geom1, 2163), transform(geom2, 2163), dist);
>
>Or It will again depend on which SRID i am using?
>
>
>
>
>--
>An Expert is the one who has made all the mistakes that are possible within a narrow field.
>       ---------- Sachin
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20090425/74097fb1/attachment.html>
```