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?

2 Answers 2

23

with ST_Distance_Sphere you can achieve that:

ST_Distance_Sphere(a.geom,b.geom)
0
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.