Jos*_*tos 6 join r esri arcgis shapefile
我正在弄清楚如何在shape和多边形之间进行交点(空间连接).我的想法是获得最接近的点和那些在多边形内完全匹配的点.在ARGIS中,有一个名为CLOSEST的匹配选项函数,它们定义为:"最接近目标要素的连接要素中的要素是匹配的.两个或更多连接要素可能与目标的距离相同当出现这种情况时,随机选择一个连接特征作为匹配特征."
我有一个函数将点交叉成多边形,它是由Lyndon Estes在r-sig-geo列表中提供的,当所有多边形填满所有区域时代码工作得非常好.第二种情况称为空间连接距离,当match_option为CLOSEST时,在ArcGIS中称为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)
Run Code Online (Sandbox Code Playgroud)
与Lyndon分享一些想法,他告诉我这个:
我认为最简单的方法是在每个点周围放一个缓冲区(如果它在投影坐标中,你可以指定50米),将它们转换为多边形,然后你的任务就成了两个不同多边形对象的交集.
我没有在R中做过这种类型的操作,但我怀疑你可以通过以下功能找到你的答案:
library(sp)
?over
library(rgeos)
?gBuffer
?gIntersects
Run Code Online (Sandbox Code Playgroud)
我建议用你的数据的一个子集来说明这个问题,然后也许其他人对多边形到多边形的交叉/叠加有更好的想法可能会建议这个方法.
应该在shapefile中的点半径中进行,以使它们进入最近的多边形.
我知道这个功能可以帮助实现它.
library(sp)
?over
library(rgeos)
?gBuffer
?gIntersects
Run Code Online (Sandbox Code Playgroud)
我正在努力,所以任何评论或帮助,都会非常折旧!
我知道可以使用sp和进行多边形到多边形的叠加rgeos。加载 sp 后,您需要加载 rgeos。
library(rgeos)
over(polygon1, polygon2)
Run Code Online (Sandbox Code Playgroud)