【问题标题】:Using R to spatial join a data frame of lat/long points to a polygon shapefil使用 R 将 lat/long 点的数据框空间连接到多边形 shapefil
【发布时间】:2016-04-25 21:02:08
【问题描述】:

我希望编写一个 R 程序,它读取纬度/经度点的数据帧和 13 个多边形的 shapefile,然后识别每个纬度/经度点位于哪个多边形内。是否有一个 R 包可以让我进行这种类型的空间连接?我一直在使用 rgdal 来读取多边形 shapefile,但我没有看到用于与我的数据框中的 lat/long 列进行空间连接的选项。谢谢!

【问题讨论】:

  • 就像将您的纬度/经度数据帧转换为SpatialPointsDataFrame 然后使用来自library(sp) 的函数over 一样简单
  • 这可能会有所帮助:stackoverflow.com/questions/13316185/…
  • 效果很好。谢谢。

标签: r geospatial shapefile rgdal maptools


【解决方案1】:

G. Cocca 的解决方案经过一些小的修改后效果很好。

最终,解决方案需要使用Rlibrary(sp)library(EcoSpatial) 的四个步骤:

  1. 使用 sp 将纬度/经度点数据帧转换为 SpatialPointsDataFrame
  2. 使用spproj4string 函数重新投影SpatialPointsDataFrame,使其使用与我的多边形shapefile 相同的投影。
  3. 使用EcoSpatialpoints.in.poly 函数在空间上连接两个数据集。这是关键步骤,因为它创建了一个新的SpatialPointsDataframe,将相关的 polgyon 数据附加到每个 xy 点。
  4. 使用as.data.frameSpatialPointsDataframe 强制转换为常规R data.frame

再次感谢您的帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-27
    • 1970-01-01
    • 2018-08-01
    相关资源
    最近更新 更多