如何使用R选取与点最近的关联多边形的信息? [英] How to pick up the information for the nearest associated polygon to points using R?

查看:134
本文介绍了如何使用R选取与点最近的关联多边形的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找如何在shapefile中的点和多边形之间进行交点(空间连接).我的想法是获取最接近的点以及在多边形内部完全匹配的那些点.在ARGIS中,有一个名为CLOSEST的用于匹配选项的函数,它们的定义如下:最接近目标要素的连接要素中的要素已匹配.两个或多个连接要素距目标的距离可能相等.发生这种情况时,会随机选择其中一个连接特征作为匹配特征."

I'm figuring out how to do a Intersection (Spatial Join) between point and polygons from shapefiles. My idea is to get the closest points and those points that match completely inside the polygons. In ARGIS there's a function for match option named CLOSEST and they have defined by: "The feature in the join features that is closest to a target feature is matched. It is possible that two or more join features are the same distance away from the target feature. When this situation occurs, one of the join features is randomly selected as the matching feature."

我有一个将点相交为多边形的功能,它是r-sig-geo列表中的Lyndon Estes贡献的,当所有多边形都填满整个区域时,代码可以很好地工作.第二种情况称为空间连接距离,而在ArcGIS中,当match_option为CLOSEST时,在ArcGIS中称为INTERSECT.因此,当区域没有被所有多边形填充时,您可以修改点与多边形之间的最小距离.

I have a function to intersect points into polygons, it was kindly contributed by Lyndon Estes at the r-sig-geo list and the code works very well when all the polygons have filled all the area. The second case is known as a Spatial join distance and in ArcGIS is know as INTERSECT when match_option is CLOSEST, as ArcGIS does. So, you can modify the minimal distance between the point and the polygon when the area is not filled by all polygons.

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

Here's the data and the function of the first 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)

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

Sharing some ideas with Lyndon, he told me this:

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

I think the easiest thing to do would be to put a buffer around each of the points (you could specify 50 m if it is in projected coordinates), converting them to polygons, and then your task becomes an intersection of two different polygon objects.

我还没有在R中完成这种类型的操作,但是我怀疑您可以通过以下功能找到答案:

I haven't done this type of operation in R, but I suspect you could find your answer with the following functions:

library(sp)
?over

library(rgeos)
?gBuffer
?gIntersects

我建议放置一部分数据来说明问题,然后也许其他人对多边形到多边形的相交/叠加有更好的了解可以建议该方法.

I suggest putting up a subset of your data illustrating the problem, and then maybe someone else who has a better idea on polygon to polygon intersects/overlays could suggest the method.

应在shapefile中的点半径内进行制作,以使它们进入最近的多边形.

should be made in the points radius which are in the shapefile in order to make them get into the nearest polygon.

我知道此功能可以帮助实现它.

I know that this functions could help to achive it.

library(sp)
?over

library(rgeos)
?gBuffer
?gIntersects


我正在研究它,因此任何评论或帮助都会非常感激!


I'm working on it, so any comment or help, would be very apreciated!

推荐答案

我知道可以使用sprgeos对多边形叠加层进行多边形处理.加载sp之后,您需要加载rgeos.

I have got that it's possible doing polygon to polygon overlays using sp andrgeos. You'd need to load rgeos after you load sp.

library(rgeos)
over(polygon1, polygon2)

这篇关于如何使用R选取与点最近的关联多边形的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆