R数据点周边缓冲区

R Data points perimeter buffer

我需要在 data points 的集合上用 x 和 y 坐标(图中的灰色点)创建一个缓冲区。 不幸的是,我没有点的周边边界,可以从中创建缓冲区。 我试图使用 chull 函数计算周长,但它无法正常工作(橙色区域)。 我可以使用 max/min 函数通过某些步骤(比如 10 m,红点)计算边界点,并尝试从这些点计算缓冲区。 有人知道计算点集缓冲区的更正确和干净的方法吗?

您可以围绕这些点进行曲面细分。边界处的点将具有更大的多边形。

library(deldir)
library(ggplot2)
triang <- deldir(data$x, data$y)
border <- triang$summary
border$Selected <- border$dir.area > 260
ggplot(border[order(border$Selected), ], aes(x = x, y = y, colour = Selected)) + geom_point()

非常感谢您的建议和意见。 的确,是我的错忽略了 alphahull 包。

ashape 确定边界后,我创建了一个缓冲区多边形并确定了缓冲区内外的数据。挑战是从 ashap 中正确提取多边形,但 RPubs 的解决方案对我来说是安全的。 您还可以看到图形示例 here.

最佳

## load
library(ggplot2); library(alphahull); 
library(igraph); library(rgeos)
## Load the data
data.df<-read.csv("Data/Cencus/Lyford_meta.csv",sep=",",header=TRUE)

#Remove the duplicates in the data to do the chull calculation
data <- data.df[!duplicated(paste(data.df$xsite, data.df$ysite, sep ="_")), c("xsite","ysite") ]

#calculate the chull with alpha 20
data.chull <- ashape(data, alpha = 20)


## Below is the code to extract polygon from the ashape chull function 
## credit to: http://rpubs.com/geospacedman/alphasimple
order.chull <- graph.edgelist(cbind(as.character(data.chull$edges[, "ind1"]), as.character(data.chull$edges[,"ind2"])), directed = FALSE)
cutg <- order.chull - E(order.chull)[1]
ends <- names(which(degree(cutg) == 1))
path <- get.shortest.paths(cutg, ends[1], ends[2])[[1]]
pathX <- as.numeric(V(order.chull)[unlist(path[[1]])]$name)
pathX = c(pathX, pathX[1])
data.chull <- as.data.frame(data.chull$x[pathX, ])


## Create a spatial object from the polygon and apply a buffer to
## Then extract the data to the dataframe.
data.chull.poly <- SpatialPolygons(list(Polygons(list(Polygon(as.matrix(data.chull))),"s1")))
data.chull.poly.buff <- gBuffer(data.chull.poly, width = -10)
data.buffer <- fortify(data.chull.poly.buff)[c("long","lat")]

## Identidfy the data that are inside the buffer polygon
data$posit <- "Outside"
data$posit[point.in.polygon(data$x,data$y,data.buffer$long,data.buffer$lat) %in% c(1,2,3)] <- "Inside"


## Plot the results
ggplot()+
  theme_bw()+xlab("X coordinates (m)")+ylab("Y coordinates (m)") +
  geom_point(data = data, aes(xsite, ysite, color = posit))+
  geom_polygon(data = data.chull, aes(V1, V2), color = "black", alpha = 0)+
  geom_polygon(data = data.buffer, aes(long, lat), color = "blue", alpha = 0)