[OSM-dev] projection for calculating distances in PostGIS
Stephen Cavilia
ailivac at gmail.com
Wed May 19 16:29:06 BST 2010
Marcus Wolschon wrote:
> On Wed, May 19, 2010 at 2:53 PM, Emilie Laffray
> <emilie.laffray at gmail.com> wrote:
>> The page is interesting due to the utmzone function. This will allow to know
>> what projection to use if you want a good approximation. It return a SRID
>> that you can use to do a ST_Transform.
>
> Ah, with only the line "Find UTM (WGS84) SRID for a point (in any SRID)"
> I was not quite sure what it was supposed to do. Thanks for the clarification.
>
>
>> But what you want to do is going to be very painfully slow especially if you
>> are going to work with geometries other than points, since it means that you
>> have to reproject the data for each geometries you are going to work with
>> potentially.
>
> Why should that be slow?
> I´m calculating a projected bounding-box for each element once ahead of time
> and storing these. When doing the queries I only need to project my
> query-location
> to find the few elements where my query-loction is within the bounding-box.
> Then I transform the few geometries found to compare the distance and sort.
>
But the bounding boxes you have are stored in degrees, right? That means
you can't do distance calculations without projecting every feature to
an appropriate UTM. And reprojecting your entire database will take a
long time.
> The following page will work in any units that you want.
>> http://www.bostongis.com/PrinterFriendly.aspx?content_name=postgis_nearest_neighbor_generic
>
> Only if the reference-point and the bounding-boxes have the same projection
> and the distance()-function will use that projection to calculate the distance.
> So this will be highly distorted for WGS84 as 1 meter is not the same distance
> in lat as it is in lon.
> So basically back to square one. Finding a good projection.
>
>> One other possibility
>> instead of using a nearest neighbour functionality is to do a search with
>> ST_DWithin applying a ratio depending on the latitude.
>
> That could work.
> Calculate a WGS4-bounding box with a width and height depending on the loction
> of the reference-point and select all geometries who intersect it.
> Could I use utmzone() to calculate a good projection, then project my
> reference-point
> to it, create a bounding-box with that SRID of +- N meters, project that back to
> WGS84 and do the range-query?
> Then use that SRID in the distance-calculation of the resulting elements that
> where found to intersect the bounding-box?
>
This is what I would do. Calculate a rough lat-lon bounding box that
approximates the area you want, filter any features that intersect that
box, then reproject just those into UTM for calculating the actual
distances. Or a more accurate geodesic/great circle distance, but UTM
will be close enough over relatively small areas.
Steve
More information about the dev
mailing list