Changes between Initial Version and Version 1 of UsersWikiNewbieMeasurementInMeters


Ignore:
Timestamp:
04/15/09 08:10:21 (16 years ago)
Author:
pracine
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiNewbieMeasurementInMeters

    v1 v1  
     1= Newbie Question =
     2
     3'''How to get distance measurement in meters?'''
     4
     5ST_Distance returns measurement in the spatial ref system units.  If you have data in long lat your measurements will be in degrees which is not terribly helpful.
     6
     7If you have point data you can simply use: st_distance_sphere which always returns in meters
     8but only works for points.
     9
     10If you have more complex geometries such as lines and polygons, you need to transform
     11your data into a meter-based projection so you can get measurement in meters.  If for example you are in the U.S, SRID 2163 US National Atlas Equal Area works pretty good for measurement.  It is not as accurate as UTM or State Plane, but its pretty good and covers all of US I believe and probably works for some of Canada as well (not sure about non-continental e.g. Hawaii, Alaska).
     12
     13e.g.
     14
     15
     16{{{
     17SELECT road.rd_name, ht.ht_name, ST_Distance(ST_Transform(roads.the_geom,2163) , ST_Transform(hotel.the_geom,2163))  as dist_meters
     18FROM road, hotel
     19WHERE <some criteria here>
     20
     21}}}
     22
     23
     24If you are somewhere else and your locations are within that projection, you can use that.  Look at the utmzone function in the wiki that will help you determing the right UTM zone SRID for your data
     25
     26[wiki:UsersWikiplpgsqlfunctions plpgsqlfunctions]
     27
     28So you would use something liek
     29SELECT utmzone(ST_Centroid(the_geom)) as srid
     30
     31to get the right UTM zone SRID.