# How do I get the distance meter value between two geometries in PostGIS?

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

## 2 Answers

with ST_Distance_Sphere you can achieve that:

``````ST_Distance_Sphere(a.geom,b.geom)
``````
• 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
• 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
• The maximum distance would be earth_radius - minimum_distance, which would be traveling the opposite way. (heading + 180º) – Francisco Valdez Jul 8 '15 at 2:50
• @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

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.