Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

with ST_Distance_Sphere you can achieve that:

ST_Distance_Sphere(a.geom,b.geom)
share|improve this answer
    
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. –  pacofvf Apr 19 '12 at 17:28
    
okey thank you paco ! –  YassineGeoma Apr 19 '12 at 17:43
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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