简体   繁体   中英

Calculating distance to nearest shore from multiple GPS coordinates

I have tried using the response to this question to solve this problem but I cannot apply it in my case since I have many coordinates distributed at a global scale.

Does anyone have a way to calculate the minimum distance in km from a series of points to the nearest shore using a loop? This is a subset of the points I am using (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

网站分布

Have a look at the rgeos package

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

spPoints will be a SpatialPoints object holding the coordinates. spPolygon will be a SpatialPolygons objects with landmasses. See the sp package. Make sure that both object have the same projection and have a sensible projection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM