17

I am using 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?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
YassineGeoma
  • 435
  • 1
  • 3
  • 8

2 Answers2

23

with ST_Distance_Sphere you can achieve that:

ST_Distance_Sphere(a.geom,b.geom)
Paco Valdez
  • 1,378
  • 1
  • 10
  • 15
4

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.

Stev_k
  • 6,689
  • 2
  • 34
  • 46