【发布时间】:2017-10-03 08:16:06
【问题描述】:
这是我一直在努力的一个玩具示例
# Make points
point1 <- c(.5, .5)
point2 <- c(.6, .6)
point3 <- c(3, 3)
mpt <- st_multipoint(rbind(point1, point2, point3)) # create multipoint
# Make polygons
square1 <- rbind(c(0, 0), c(1, 0), c(1,1), c(0, 1), c(0, 0))
square2 <- rbind(c(0, 0), c(2, 0), c(2,2), c(0, 2), c(0, 0))
square3 <- rbind(c(0, 0), c(-1, 0), c(-1,-1), c(0, -1), c(0, 0))
mpol <- st_multipolygon(list(list(square1), list(square2), list(square2))) # create multipolygon
# Convert to class 'sf'
pts <- st_sf(st_sfc(mpt))
polys <- st_sf(st_sfc(mpol))
# Determine which points fall inside which polygons
st_join(pts, polys, join = st_contains)
最后一行产生
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :
cannot coerce class "c("sfc_MULTIPOINT", "sfc")" to a data.frame
如何进行空间连接以确定哪些点位于哪些多边形内?
【问题讨论】:
-
您能澄清一下“空间连接”的含义吗?预期的结果是什么?
-
给定一组多边形和一组点,创建映射 (PointId, PolygonId) 来说明哪些点包含在哪些多边形中。
-
我最近为sf package 写了this tutorial,以帮助自己和其他人理解基本概念。了解基本原理是解决像我在这里遇到的特定问题的关键。