[英]Calculating distance to nearest shore from multiple GPS coordinates
我嘗試使用對此問題的回答來解決此問題,但是由於我有許多在全球范圍內分布的坐標,因此無法在我的情況下應用它。
有沒有人可以使用循環來計算一系列點到最近海岸的最小距離(以公里為單位)? 這是我使用的觀點的一個子集(數據此處)
#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
看看rgeos
包
library(rgeos)
gDistance(spPoints, spPolygon, byid = TRUE)
spPoints
將是一個保存坐標的SpatialPoints
對象。 spPolygon
將是具有大陸塊的SpatialPolygons
對象。 請參見sp
程序包。 確保兩個對象都具有相同的投影並具有合理的投影。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.