Calculating distance between 2 points. Can I trust in GeoLocation.STDistance function of sql server? -
i want calculate distance between 2 points sql server. problem result not accurate.
create table #auxdist ( idempr int identity(1,1) ,emp_desc varchar(60) ,longitud float ,latitud float ,geolocation geography ) insert #auxdist values ('ting',-55.769,-34.768,null) insert #auxdist values ('ccomp',-55.74132,-34.19647,null) update #auxdist set [geolocation] = geography::stpointfromtext('point(' + cast( cast(cs.latitud decimal(30,20)) varchar(30)) + ' ' + cast( cast(cs.longitud decimal(30,20)) varchar(30))+ ')', 4326) #auxdist cs select com1.idempr,com2.idempr, com1.geolocation.stdistance(com2.geolocation) dist #auxdist com1 join #auxdist com2 on com1.idempr <> com2.idempr , com1.idempr=1 using query distance between 2 points 36016 mts. check result using http://www.onlineconversion.com/map_greatcircle_distance.htm , found different answer: 63673mts (haversine formula)

you've specified points backwards. run following query , you'll see mean.
select *, geolocation.lat lat, geolocation.long long #auxdist the fix easy enough: when you're creating wkt via string concatenation, switch order of latitud , longitud
Comments
Post a Comment