[英]Why I obtain different values calculating distance between two point in the space using this “Great-circle distance” formula and Google Earth tool?
我對數據庫和GIS不太滿意,對於在MySql數據庫上用於計算2點之間的距離的此函數,我有以下疑問。
我從本教程開始,這里有用於計算2 點場之間距離的函數:
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 a = 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
我認為它應該以km為單位返回一個值。
然后,我用它來計算空間中2個點之間的距離(取自Google Maps ,例如意大利的羅馬和米蘭城市)。
我正在獲得合理的價值。 我的疑問是,然后我使用Gooogle Earth中的標尺工具檢查了距離,並且獲得了不同的值。
考慮到附近兩個點(距離為2 km)的敵人示例,我在Google Earth計算出的差值和我以前的函數之間得到了大約300 m的差值。
考慮到非常遙遠的2個點(例如羅馬和米蘭),我得到了由Google Earth計算的值與由上一個函數計算的值之間相差100公里的結果。
前一個功能始終會提供更大的價值。
因此,我必須使用它來計算較小的距離(最大30 km),因此誤差應該很小,並且出於我的考慮可以接受。
但是,為什么在我的函數和使用Google Earth計算的距離之間獲得這些差異?
SQL Server使用以下代碼返回534.728893656916km: 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.