[postgis-users] Simple question: How to get projected distance?
Stephen Woodbridge
woodbri at swoodbridge.com
Wed Aug 10 09:04:58 PDT 2005
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
More information about the postgis-users
mailing list