[postgis-users] Simple question: How to get projected distance?
Paul Ramsey
pramsey at refractions.net
Fri Aug 12 13:28:16 PDT 2005
Substitude money for effort, and buy DB2 Geodetic. Calculate your
buffers and intersections and everything else directly on the spheroid.
Only $50K :)
If you are not super concerned about accuracy, create a planar project
for your region of interest (CONUS, right?) and use that instead of
figuring out the right UTM zone on the fly. I think there are some nice
Lambert parameterizations that do all of CONUS. You can just insert the
relevant definnitions into spatial_ref_sys and go from there.
P.
Lance Arlaus wrote:
> Thanks Gustavo. Simple oversight on my part - long/lat, not lat/long -
> arggghh!! Works like a charm now. Told you, I'm new to this.
>
> One last question - Is this cycle of WGS84 -> UTM -> WGS84 considered best
> practice i.e. is this the easiest way to accomplish what I need? It would
> imply that I need to add logic to figure the right intermediate UTM zone.
>
> -Lance
>
> -----Original Message-----
> From: postgis-users-bounces at postgis.refractions.net
> [mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Gustavo
> Henrique Sberze Ribas
> Sent: Friday, August 12, 2005 1:17 PM
> To: PostGIS Users Discussion
> Subject: RE: [postgis-users] Simple question: How to get projected distance?
>
> Hi,
>
>
>
>>Here's what I've tried and the problems I've encountered:
>>1. Tagging the points with an SRID of 4326 (WGS 84) and
>>directly querying for the distance. Since it's not a projected coordinate
>
>
>>system, it just gives the Cartesian distance. Pretty useless.
>
>
> Don't apply 2D planar formulas to an ellipsoidal coordinate system.
> It makes no sense.
>
>
>
>>2. Use distance_sphere() to calculate the distance. Great, I
>>get distances, but can't create shapes, etc.
>
>
> Why not? If you don't need much precision you can say
> that 1 degree ~ 100km.
>
>
>>3. Transform the points into a UTM projection and create
>>polygons and query for distance on the transformed points.
>>This works, however the system must work across the US and
>>I'd have to have a table for each UTM zone and add a
>>lot of logic to accommodate not to mention separate indexes,
>>etc. Very ugly option.
>
>
> Agreed.
>
>
>>4. Transform into UTM, perform the operations, and transform the UTM
>>coordinates back into WGS 84 lat/long, storing the resulting
>>points in one table with the appropriate indexes attached for efficient
>
> querying.
>
>>Ideally, I'd like to end up with a set of WGS 84 defined geometries that
>
> I
>
>>can query. Unfortunately, this doesn't work. Transforming the points
>
> back
>
>>into WGS 84 yields nonsense results.
>
>
> That's strange, I do exactly that and it works just fine. Here's an
> example that
> creates a circle of radius 100m around a lat/long point:
>
> select
> transform(
> setSRID(
> buffer(
> transform(
> 'SRID=4326;POINT(-47.2407989501953 -22.7394008636475)',32723
> ),
> 100
> ),
> 32723
> ),
> 4326
> )
>
>
> I project the point to UTM using the same WGS84 ellipsoid, then I buffer
> it
> to create a "circle" (32 sided polygon). Finally I translate the circle
> coordinates
> back to lat/lon WGS84.
>
>
>
>>I thought this would be very simple. At this point, I'm
>>quite frustrated. What am I doing wrong??
>
>
> Remember: Point(Longitude Latitude).
>
>
> --
> Gustavo
>
>
>>Some of my results:
>>-- Create WGS84 point and transform into UTM zone 18N
>>ASText(Transform(PointFromText('POINT(40.8117 -74.218)',
>>4326), 32618));
>>Result: "POINT(2192975.52043048 -10779305.4033352)"
>>
>>-- Create WGS84 point, transform into UTM zone 18N, and transform back
>>ASText(Transform(Transform(PointFromText('POINT(40.8117
>>-74.218)', 4326),
>>32618), 4326));
>>Result: "POINT(-75 -90)"
>>
>>
>>Thanks,
>>Lance
>>
>>Lance Arlaus wrote:
>>
>>>I know this is a simple question, but I'm just getting started with
>>>PostGIS and I can't seem to perform a simple calculation.
>>>
>>>I just need to calculate the distance between two points.
>>
>>What am I
>>
>>>doing wrong?
>>>
>>>
>>>
>>>Query:
>>>
>>> SELECT distance(PointFromText('POINT(40.8117 -74.218)', 32617),
>>>PointFromText('POINT(40.8272 -74.1242)', 32617))
>>>
>>>Returns:
>>>
>>> 0.095.
>>
>>This is the distance in the input units. Since the values you
>>are using
>>are decimal degrees the result is 0.095... decimal degrees
>>and probably
>>assumes that you are computing this in a flat X-Y plane.
>>
>>
>>>Of course if I do the following, I get a reasonable answer
>>
>>(about 10km),
>>
>>>but it's not exactly what I want
>>
>>OK, what is it that you want?
>>
>>
>>> SELECT distance_sphere(PointFromText('POINT(40.8117 -74.218)',
>>>32617), PointFromText('POINT(40.8272 -74.1242)', 32617))
>>
>>This is better than you first try because this is computing the arc
>>distance along the great circles between the two points.
>>
>>
>>>Even constructing a line and taking the length doesn't work
>>
>>and I've
>>
>>>tried all SRIDs.
>>>
>>
>>SRIDs are an attribute associated with the geometry, like,
>>red, green,
>>blue. Changing them will not change the answer unless you
>>pass them to a
>>utility that is actively aware of them. They are there to you
>>don't try
>>to compare or manipulate two points that were stored in
>>different SRIDs.
>>
>>The standard use of them is to use them to perform
>>projections from the
>>objects stored SRID to some common workspace that would be good for
>>manipulation.
>>
>>The SRID for WGS84 is I believe 4326
>>
>>To do things right you need to understand the projection
>>space that you
>>data is in and how it effects calculations and the postGIS functions.
>>
>>
>>>Sorry to ask such a simple question.
>>>
>>>Also, is there a document that describes the well known
>>
>>SRIDs? I'm not
>>
>>>sure which one to use. For example, the data I've got
>>
>>references WGS
>>
>>>84, but there's a ton of SRIDs defined. I've found docs
>>
>>describing the
>>
>>>format of the specification, but how are the SRIDs created
>>
>>(who serves
>>
>>>as the clearinghouse for this info)?
>>
>>HTH,
>> -Steve
>>_______________________________________________
>>postgis-users mailing list
>>postgis-users at postgis.refractions.net
>>http://postgis.refractions.net/mailman/listinfo/postgis-users
>>
>>_______________________________________________
>>postgis-users mailing list
>>postgis-users at postgis.refractions.net
>>http://postgis.refractions.net/mailman/listinfo/postgis-users
>>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
> _______________________________________________
> 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