【问题标题】:Calculating distance to nearest shore from multiple GPS coordinates从多个 GPS 坐标计算到最近海岸的距离
【发布时间】:2015-10-15 15:32:51
【问题描述】:

我已尝试使用对this question 的响应来解决此问题,但我无法在我的情况下应用它,因为我有许多分布在全球范围内的坐标。

有没有人可以使用循环计算从一系列点到最近海岸的最小距离(公里)?这是我正在使用的点的子集(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

【问题讨论】:

    标签: r loops dictionary polygon distance


    【解决方案1】:

    看看rgeos

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

    spPoints 将是一个保存坐标的SpatialPoints 对象。 spPolygon 将是具有陆地的 SpatialPolygons 对象。请参阅sp 包。确保两个对象具有相同的投影并且具有合理的投影。

    【讨论】:

    • 是的,我试过这个,但它选择的投影是问题所在。点和多边形的默认值都是 WGS84,但我得到的距离很奇怪。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-13
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 1970-01-01
    • 2010-09-26
    相关资源
    最近更新 更多