mysql - Why I obtain different values calculating distance between two point in the space using this "Great-circle distance" formula and Google Earth tool? -
i not database , gis , have following doubt function used on mysql database calculate distance between 2 points.
i started tutorial there function used calculate distance between 2 point field:
create function earth_circle_distance(point1 point, point2 point) returns double deterministic begin declare lon1, lon2 double; declare lat1, lat2 double; declare td double; declare d_lat double; declare d_lon double; declare a, c, r double; set lon1 = x(geomfromtext(astext(point1))); set lon2 = x(geomfromtext(astext(point2))); set lat1 = y(geomfromtext(astext(point1))); set lat2 = y(geomfromtext(astext(point2))); set d_lat = radians(lat2 - lat1); set d_lon = radians(lon2 - lon1); set lat1 = radians(lat1); set lat2 = radians(lat2); set r = 6372.8; -- in kilometers set = sin(d_lat / 2.0) * sin(d_lat / 2.0) + sin(d_lon / 2.0) * sin(d_lon / 2.0) * cos(lat1) * cos(lat2); set c = 2 * asin(sqrt(a)); return r * c; end
i think should return value in km unit measurment.
then have used calculate distance between 2 point in space (taken google maps example rome , milan cities, here in italy).
i obtaining reasonable values. doubt that, have check distance using ruler tool in gooogle earth , obtaining different values.
foe example considering 2 points near (2 km of distance) obtain 300 m of difference between difference calculated google earth , previous function.
considering 2 points distant (for example rome , milan) obtain 100 km of difference between value calculated google earth , 1 calculated previous function.
the previous function give bigger value.
so have use calculate on small distance (maximum 30 km) error should little , ok pourpose.
but why obtain these difference between funcion , distance calculated using google earth?
sql server returns 534.728893656916km using code: declare @g geography = geography::point(9.191884,45.464090,4326) -- latitude, longitude, srid declare @h geography = geography::point(12.492359,41.890365,4326) select @g.stdistance(@h)/1000.00
Comments
Post a Comment