I have a simple question about calculating distances in PostGIS.

I would like to get the distance between two geometries. I am using this sid : 4269 in meters what i am doing now is this : ST_Distance((a.geom,b.geom)) FROM ... but I am getting result in degrees. I think that I should work with geography but how can I cast a geom to a geography? I tried with (a.geom::geography) but i am getting an error.

What can I do to get my result in meters?

Thank You


with ST_Distance_Sphere you can achieve that:

  • ERREUR: la fonction st_distance_spheroid(geometry, geometry) n'existe pas ... i just added (a.geom,b.geom, 'SPHEROID["WGS 84",6378137,298.257223563]') and now it is working fine thank you very much ! – YassineGeoma Apr 19 '12 at 17:07
  • 1
    well, you used a different function, st_distance_spheroid which is slower than st_distance_sphere but more precise. – Francisco Valdez Apr 19 '12 at 17:28
  • What about the maximum distance between 2 geometries ? – vasilakisfil Jun 4 '15 at 11:08
  • 1
    @don-prog It works for 3D and 2D point : SELECT ST_Distance_Sphere(ST_GeomFromEWKT('SRID=4326;POINT(-72.1235 42.3521 4)'), ST_GeomFromEWKT('SRID=4326;POINT(-72.1260 42.45 15)')) – Francisco Valdez Apr 17 '18 at 23:00
  • 1
    As of PostGIS 2.2.0, it's been renamed ST_DistanceSphere. You'll get warnings if you use the old name. – Brad Koch Jun 13 '18 at 12:44

The units of SRID 4269 (NAD 83) are not metres - this is a geodetic projection, i.e. the co-ordinates are degrees (geographic co-ordinates).

pacofvf's answer will give you the distance in metres, but if you really did have your intial co-ordinates specified in metres then then you should use a projected co-ordinate system. Probably for North America you want something like State Plane Coordinate System which has a number of different projections depending on which region you want to map.

I suspect though that you are just using lat/lon values so probably this second paragraph isn't relevant - just use the ST_Distance_Sphere function as above.

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.