23

I wonder what the unit is of the float being returned from ST_Distance.

In the documentation it says:

...cartesian minimum distance (based on spatial ref) between two geometries in projected units.

What are these projected units?

The geometry is stored in a field: geometry(Point,4326).

34

I think this is the most frequent question on PostGIS list over time :-)

If your data is in SRID 4326 and you use geometry type the result will not give any meaning. It is in degrees.

To get the result in meters just cast to geography type and ST_Distance will calculate the distance along the great circle instead and return in meters.

geometry(Point,4326)::geography

Another option is to project your data to some local projection based on a suitable unit. Then the answer will be in that unit.

  • 2
    Here is an example to find the distance between two rows in a table SELECT ST_Distance(a.geom::geography, b.geom::geography) FROM pure_gis a, pure_gis b WHERE a.id='1' AND b.id='2'; – Brian McCall Sep 22 '17 at 20:35
4

From http://postgis.net/docs/ST_Distance.html

--Geometry example - units in planar degrees 4326 is WGS 84 long lat unit=degrees

If ST_Distance is given two geometries, it assumes those geometries are really in cartesian (or planar) coordinates. Thus, the units are the same as those in the coordinates -- usually metres or feet.

Your problem seems to be that your spatial reference system, 4326, actually uses (angular) geographic coordinates -- degrees long-lat -- so the results are in (somewhat meaningless) degrees.

  • 1
    Results are entirely meaningless, not even somewhat. – Paul Ramsey Nov 10 '13 at 20:41
  • @PaulRamsey. Wouldn't they be the same as what i'd get "measuring" distances on a PlateCaree projection? – Martin F Nov 11 '13 at 3:17
  • On a PC, you'd get linear units back and could at least say "OK, I know these units are subject to serious distortion". Getting "degrees" back, people might be tempted to think "aha, I have an angular distance here, just need to multiply by 2R and I'll have a linear distance". The units make a bad measurement potentially even more terribly misleading. And PC is so terrible I don't know why it gets a projection name... does't preserve distance, doesn't preserve direction, doesn't preserve area... – Paul Ramsey Nov 11 '13 at 13:21
  • PC preserves distances along the equator and perpendicular to the equator. Aside from the required radians and radius conversions (admittedly, a very major inconvenience), the results of using ST_Distance on 4326 geometries will have the same general mixture of disadvantages and benefits that must be considered when using ST_Distance with projection geometries. Maybe the better debate should be (not "somewhat" versus "entirely" meaningless but) "Should ST_Distance and ST_Area even be allowed to return results given 4326 geometries?" – Martin F Nov 11 '13 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.