数据点周边缓冲区

3
我需要在数据点上创建一个缓冲区,该点具有x和y坐标(图表上的灰色点)。不幸的是,我没有点的周长边界,无法创建缓冲区。我试图使用chull函数计算周长,但它不能正常工作(橙色区域)。我可以使用max/min函数为数据计算边界点(例如每10米一个点,红点),并尝试从这些点计算缓冲区。是否有更正确和清晰的方法来计算点集的缓冲区?

enter image description here


你是在寻找红线代表的结果吗? - Thierry
我想检索所有落在由红线标识的多边形内的点。 - Volodymyr
1
chull 正常工作。你只是不想让你的 hull 成为“凸形”。 - IRTFM
2个回答

1
你可以围绕这些点进行镶嵌。边界上的点会拥有更大的多边形。
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()

1
非常感谢您的建议和评论。 事实上,我的疏忽导致遗漏了alphahull包。
在使用ashape识别边界后,我创建了一个缓冲多边形,并确定了位于缓冲区内外的数据。挑战是正确地从ashap中提取多边形,但RPubs的解决方案帮助了我。 您可以在这里看到图形示例。
最好的祝愿
## 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)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接