【问题标题】:How to pick up the information for the nearest associated polygon to points using R?如何使用 R 获取与点最近的关联多边形的信息?
【发布时间】:2012-02-08 03:46:10
【问题描述】:

我正在研究如何在 shapefile 中的点和多边形之间进行交集(空间连接)。我的想法是获取最近的点以及在多边形内完全匹配的点。在 ARGIS 中有一个名为 CLOSEST 的匹配选项功能,它们定义为:“连接特征中最接近目标特征的特征被匹配。两个或多个连接特征可能与目标的距离相同特征。出现这种情况时,会随机选择其中一个连接特征作为匹配特征。”

我有一个将点相交成多边形的功能,它是由 Lyndon Estes 在 r-sig-geo 列表中提供的,当所有多边形都填充了所有区域时,代码运行良好。第二种情况称为空间连接距离,在 ArcGIS 中当 match_option 为 CLOSEST 时称为 INTERSECT,正如 ArcGIS 所做的那样。因此,当区域没有被所有多边形填充时,您可以修改点与多边形之间的最小距离。

这是第一个INTERSECT的数据和功能:

library(rgeos)
library(sp) 
library(maptools)
library(rgdal)
library(sp)
xy.map <- readShapeSpatial("http://www.udec.cl/~jbustosm/points.shp")
manzana.map <- readShapeSpatial("http://www.udec.cl/~jbustosm/manzanas_from.shp" )

IntersectPtWithPoly <- function(x, y) { 
# Extracts values from a SpatialPolygonDataFrame with SpatialPointsDataFrame, and appends table (similar to 
# ArcGIS intersect)
# Args: 
#   x: SpatialPoints*Frame
#   y: SpatialPolygonsDataFrame
# Returns:
# SpatialPointsDataFrame with appended table of polygon attributes

  # Set up overlay with new column of join IDs in x
  z <- overlay(y, x)

  # Bind captured data to points dataframe
  x2 <- cbind(x, z)

  # Make it back into a SpatialPointsDataFrame 
  # Account for different coordinate variable names 
  if(("coords.x1" %in% colnames(x2)) & ("coords.x2" %in% colnames(x2))) {
    coordinates(x2) <- ~coords.x1 + coords.x2  
  } else if(("x" %in% colnames(x2)) & ("x" %in% colnames(x2))) {
    coordinates(x2) <- ~x + y 
  }

  # Reassign its projection if it has one
  if(is.na(CRSargs(x@proj4string)) == "FALSE") {
    x2@proj4string <- x@proj4string  
  }
  return(x2)
}


test<-IntersectPtWithPoly (xy.map,manzana.map)

与林登分享一些想法,他告诉我:


我认为最简单的做法是在每个点周围放置一个缓冲区(如果它在投影坐标中,您可以指定 50 m),将它们转换为多边形,然后您的任务将成为两个不同点的交集多边形对象。

我没有在 R 中做过这种类型的操作,但我怀疑你可以通过以下函数找到答案:

library(sp)
?over

library(rgeos)
?gBuffer
?gIntersects

我建议放置一个数据子集来说明问题,然后也许其他对多边形到多边形相交/叠加有更好想法的人可以提出该方法。

应该在shapefile中的点半径中进行,以使它们进入最近的多边形。

我知道这个功能可以帮助实现它。

library(sp)
?over

library(rgeos)
?gBuffer
?gIntersects

我正在努力,所以任何评论或帮助,将不胜感激!

【问题讨论】:

  • gis.stackexchange.com/questions/18726/… 交叉发布。这似乎是一个有效的选择,但它意味着,Pantaleon,我们希望您努力在您在 每个 站点上开始的线程中总结来自 两个 站点的回复。
  • 好的,谢谢。我在这方面很新!!!

标签: r join arcgis esri shapefile


【解决方案1】:

我知道可以使用sprgeos 进行多边形到多边形的叠加。加载 sp 后,您需要加载 rgeos。

library(rgeos)
over(polygon1, polygon2)

【讨论】:

  • 也许您可以在 gis.stackexchange 上添加问题的链接?我假设你得到了这些答案......
猜你喜欢
  • 2013-10-03
  • 2022-06-10
  • 1970-01-01
  • 2014-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-06
  • 2013-05-03
相关资源
最近更新 更多