我正在弄清楚如何在 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
我正在努力,所以任何评论或帮助,都会非常感激!