Changes between Initial Version and Version 1 of UsersWikiNewbieDistanceMeasurement


Ignore:
Timestamp:
Apr 15, 2009, 8:02:43 AM (15 years ago)
Author:
pracine
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiNewbieDistanceMeasurement

    v1 v1  
     1= Newbie Question =
     2
     3
     4'''What is the measurement returned by ST_Distance?'''
     5
     6
     7ST_Distance always returns in the units of the projection.
     8
     9So if for example you chose SRID 4326 - then your measurement would be in degrees.
     10
     11It is best to use a meter based or feet based projection for measurement.
     12
     13Unfortunately you can not do that unless you are dealing with regional data such as country, state etc.
     14
     15To get meters when using 4326 or other degree projection - use ST_Distance_Sphere or ST_Distance_Spheroid.  These unfortunately only work with point geometries.
     16
     17Faster but less precise
     18
     19
     20{{{
     21SELECT ST_Distance_Sphere(
     22    ST_GeomFromText('POINT(5.0 52.0)', 4326),
     23    ST_GeomFromText('POINT(6.0 56.0)', 4326) );
     24
     25SELECT ST_Distance_Sphere(t1.the_geom, t2.the_geom)
     26FROM t1 INNER JOIN t2 ON t1.somefield1 = t2.somefield2;
     27
     28}}}
     29
     30Slower but more precise
     31
     32{{{
     33SELECT ST_Distance_Spheroid(
     34       ST_GeomFromText('POINT(5.0 52.0)', 4326),
     35       ST_GeomFromText('POINT(6.0 56.0)', 4326),
     36         'SPHEROID[wiki:UsersWiki"WGS 84",6378137,298.257223563 "WGS 84",6378137,298.257223563]'
     37     );
     38
     39SELECT ST_Distance_Spheroid(t1.the_geom, t2.the_geom,  'SPHEROID[wiki:UsersWiki"WGS 84",6378137,298.257223563 "WGS 84",6378137,298.257223563]')
     40FROM t1 INNER JOIN t2 ON t1.somefield1 = t2.somefield2;
     41
     42}}}