2017-05-01 2 views
2

ただ、次の例チェックアウト:それはようで私になぜ地理的距離が間違っているのですか?

lat <- c(47.5, 47.5, 47.501) 
lng <- c(9.3, 9.301, 9.3) 
geosphere::distVincentyEllipsoid(lng[c(1,2)], lat[c(1,2)]) 
# [1] 5551424 Should be about 5000 m? 
geosphere::distVincentyEllipsoid(lng[c(1,3)], lat[c(1,3)]) 
#[1] 5551583 Should be about 5000 m? 

m <- leaflet() %>% 
    addTiles(group = "OSM") %>% 
    addProviderTiles("Stamen.TonerLite") %>% 
    addLayersControl(
    baseGroups = c("OSM", "Stamen.TonerLite")) %>% 
    addCircleMarkers(lat = lat, 
        lng = lng, 
        color = "blue", 
        stroke = FALSE, 
        radius = 3, 
        fillOpacity = 0.7) 
print(m) 

を、結果はかなりものの????distVincentyEllipsoidオフの状態である:楕円体と同じ単位で

距離値(デフォルトはメートル)

編集

:ちょうど hereからの単純なクロスチェックなど
R = 6371 # radius of the earth in km 
x = (lng[2] - lng[1]) * cos(0.5*(lat[2]+lat[1])) 
y = lat[2] - lat[1] 
d = R * sqrt(x*x + y*y) # in km 

答えて

3

間違った情報をdistVincentyEllipsoidに入力しています。次の形式を持つ必要があります:distVincentyEllipsoid(p1, p2)。ヘルプファイルから:

p1 longitude/latitude of point(s), in degrees 1; can be a vector of two numbers, a matrix of 2 columns (first one is longitude, second is latitude) or a SpatialPoints* object 
p2 as above 

両方のポイントがlng/lat組み合わせである必要があり、一方、あなたがやっていることは、p2p1に2つのlng値と2つのlat値を提供しています。

そうした場合:

distVincentyEllipsoid(c(lng[1], lat[1]), c(lng[2], lat[2])) 

あなたが取得します:

[1] 75.34357 
関連する問題