2014-02-21 60 views
1

我正在使用PostgreSQL v9.1.11和PostGIS 2.1.0。我正在使用st_distance_sphere來計算各個點之間的距離,並得到不尋常的結果。根據文件,該功能應返回所提供的2個點之間的距離,單位爲米。下面是我所遇到的兩個例子:來自PostGIS的st_distance_sphere返回意外值?

select st_distance_sphere(
    st_setsrid(st_makepoint(33.44, -82.60), 4326), -- location near Warrenton, GA 
    st_setsrid(st_makepoint(33.533, -82.517), 4326) -- locaton near Thomson, GA 
) 

返回9325.862米,5.8英里,似乎是正確的

select st_distance_sphere(
    st_setsrid(st_makepoint(33.44, -82.60), 4326), -- location near Warrenton, GA 
    st_setsrid(st_makepoint(32.819, -97.361), 4326) -- location near Forth Worth, TX 
) 

返回9873.560米,或6.1英里,甚至還沒有接近。

我已閱讀並重新閱讀PostGIS文檔,找不到任何我做錯的地方。這個功能只是行爲不端?

+1

詢問這裏http://gis.stackexchange.com/ – huckfinn

回答

1

驗證您的疑問,我得到以下錯誤:

enter image description here

回首的文檔中,我們可以看到這一點:

ST_Distance_Sphere — Returns linear distance in meters between two lon/la points 

這意味着第一個座標的點必須是經度,第二個是緯度

因此,您將有以下得當,座標爲您的位置:

(-82.60, 33.44) -- location near Warrenton, GA 
(-82.517, 33.533 -- locaton near Thomson, GA 
(-97.361, 32.819) -- location near Forth Worth, TX 

現在,讓我們再次運行查詢:

select st_distance_sphere(
    st_setsrid(st_makepoint(-82.60, 33.44), 4326), -- location near Warrenton, GA 
    st_setsrid(st_makepoint(-82.517, 33.533), 4326) -- locaton near Thomson, GA 
) 

結果:12891.3730143974 meters = 8.01 miles

select st_distance_sphere(
    st_setsrid(st_makepoint(-82.60, 33.44), 4326), -- location near Warrenton, GA 
    st_setsrid(st_makepoint(-97.361, 32.819), 4326) -- location near Forth Worth, TX 
) 

結果:1375107.45231354 meters = 854.45 miles

+0

由於索林,知道這是愚蠢的東西在我的部分 – Mike