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

查看:26
本文介绍了如何使用 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."

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

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)

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

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天全站免登陆