[postgis-users] Re: st_dwithin in SRID 4269

Sean Fulton seanasy at gmail.com
Sun Apr 26 16:47:41 PDT 2009


On 2009-04-25 12:10:33 -0400, Sachin Srivastava 
<sachin.srivastava1984 at gmail.com> said:

> 
> 
> 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
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>> 
> 
> Sean,
> 
> Thanks a lot for your answer.
> 
> 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.

1 degree = 1 nautical mile = 1852 meters along any meridian.  That 
might work for latitude but it won't work for longitude.

> 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 all cases.
> 
> SELECT * FROM table where st_dwithin(transform(geom1, 2163),
> transform(geom2, 2163), dist);
> 
> Or It will again depend on which SRID i am using?

You choose the SRID based on the region and your preference for getting 
accurate distances.  Any projection will distort distance, area or 
shape.  Projections designed for one region will show greater 
distortion in areas for which it wasn't designed.

The U.S. National Atlas Equal Area, as the name implies, is optimized 
to maintain accurate area measurements over the entire U.S.  For the 
U.S., the appropriate state plane coordinate system will give more 
accurate distance results.

Of course, depending on your application you may not be overly 
concerned about the accuracy of your measurements.  In that case, you 
could choose one projection for the whole U.S.  If you do need a fairly 
high level of accuracy, you use a different projection depending on 
where your query is being done.

  Sean 





More information about the postgis-users mailing list