2015-10-14 88 views
1

我已經嘗試使用this question的響應來解決這個問題,但由於我在全球範圍內分佈有許多座標,所以我無法將其應用於我的案例。從多個GPS座標計算到最近岸的距離

有沒有人有辦法計算使用循環從一系列點到最近岸的最小距離(km)?這是點的子集,我使用(DATA HERE)

#setwd and load directories---- 
setwd("your_wd") 
    require (ggplot2) 
    require (ggmap) 

#build a map to plot distribution of sample sites ---- 
sites<-read.csv("sites.csv", header=T) 

#Using GGPLOT, plot the Base World Map 
mp <- NULL 
mapWorld <- borders("world", colour="gray50", fill="gray50") # create a layer of borders 
mp <- ggplot() + mapWorld 
#Now Layer the sites on top 
Lon<-sites$x 
Lat<-sites$y 
mp <- mp+ geom_point(aes(x=Lon, y=Lat),color="blue", size=3) 
mp 

Distribution of sites

回答

2

看一看在rgeos

library(rgeos) 
gDistance(spPoints, spPolygon, byid = TRUE) 

spPoints將是一個SpatialPoints對象持有的座標。 spPolygon將是一個SpatialPolygons有大陸的物體。請參閱sp包。確保兩個物體具有相同的投影並具有合理的投影。

+0

是的,我試過這個,但它選擇了一個問題的投影。對於點和多邊形,默認值爲WGS84,但Im得到的距離非常奇怪。 –