R 连接点到多边形

R 连接点到多边形,r,join,polygon,geospatial,point,R,Join,Polygon,Geospatial,Point,我正在尝试将空间点数据连接到空间多边形数据 不久前,发布了一条非常有用的帖子: 和交叉链接: 我正在尝试使用OP发布的代码: library(rgeos) library(sp) library(maptools) library(rgdal) library(sp) ky.map <- readShapeSpatial("~/KYcounties.shp") points.xy <- readShapeSpatial('~/points.shp') # Sample da

我正在尝试将空间点数据连接到空间多边形数据

不久前,发布了一条非常有用的帖子:

和交叉链接:

我正在尝试使用OP发布的代码:

library(rgeos)
library(sp) 
library(maptools)
library(rgdal)
library(sp)

ky.map <- readShapeSpatial("~/KYcounties.shp") 

points.xy <- readShapeSpatial('~/points.shp') # Sample data of the points file 
                                              # is below.
以及一组用于连接多边形字段的NAs

很公平:

z <- over(y, x) 
下面是我正在使用的点数据示例(放入QGIS并导出为形状文件):

我在Google Drive上共享了shapefile:


想法?

使用
spatialEco
库有一个简单的解决方案

library(spatialEco)

# intersect points in polygon
  pts <- point.in.poly(pts, ply)

# check plot
  plot(ply)
  plot(a, add=T)

# convert to data frame, keeping your data
  pts <- as.data.frame(pts)
库(spatialEco)
#多边形中的交点

pts请将示例数据添加到您的问题中,否则无法重现您的问题。可以使用
spatat
package
dist
crossdist
函数。@CarlWitthoft使用
sp
类和
rgeos
,这是完全可能的,但是我们需要OP提供更多的信息来了解发生了什么。@SimonO101很好。你还没有添加shapefile的下载链接。此外,要通知某人您已留下评论,您必须在评论中包含他们的句柄(例如@SimonO101)
Warning message: 'overlay' is deprecated. Use 'over' instead.
z <- over(y, x) 
Error in data.frame(..., check.names = FALSE) : arguments imply differing
number of rows: 96, 121
structure(list(ID = c(5L, 11L, 33L, 41L, 73L, 119L, 175L, 206L, 
216L, 229L), Latitude = c(38.239829, 38.9231075, 38.04169866, 
38.13953849, 38.14800534, 37.85059283, 38.17820492, 38.00833019, 
38.22189947, 36.87255699), Longitude = c(-85.746211, -84.4108925, 
-84.49738797, -85.6776972, -85.02502406, -84.57452618, -85.56667237, 
-84.42084641, -85.48653626, -84.22021486)), .Names = c("ID", 
"Latitude", "Longitude"), row.names = c(NA, 10L), class = "data.frame")
library(spatialEco)

# intersect points in polygon
  pts <- point.in.poly(pts, ply)

# check plot
  plot(ply)
  plot(a, add=T)

# convert to data frame, keeping your data
  pts <- as.data.frame(pts)