问题
I have a series of points in an area whose 'footprint' shape is highly irregular:
I'd like to determine all of the coordinates within the footprint's vertices. The end goal is to determine which data points lay outside this footprint.
Does anyone have an efficient way to go about doing this??
My best idea to approaching this is to draw a polygon based on the green area's vertices and then use said polygon's coordinates to determine 'outlier' points' (though, I'm not sure how to do that yet -- one step at a time!).
However, when I try creating a convex hull, it obviously creates problems because of the irregular shape of my green space. [Anyone know of a way to create CONCAVE hulls?]
Alternatively, is there a way to draw polygons manually using a 'click the graph' type method?
...Again, if you have a better solution to my problem than using polygons, please by all means suggest that solution!
回答1:
Alternatively, is there a way to draw polygons manually using a 'click the graph' type method?
Here's one idea. First, some random points:
library(manipulate)
library(sp)
set.seed(1)
par(pch = 19, cex=.5)
x <- runif(1000)
y <- runif(1000)
Now, draw and capture the polygon:
coords <- data.frame()
manipulate({
plot(y~x)
res <- manipulatorMouseClick()
coords <<- rbind(coords, data.frame(x=res$userX, y=res$userY))
if (length(coords)) lines(coords)
})
And determine which points are inside/outside of it (see ?point.in.polygon
):
res <- point.in.polygon(x, y, coords$x, coords$y)!=0
plot(y~x, col = res + 1L)
lines(coords)
来源:https://stackoverflow.com/questions/39580566/determine-which-points-lay-outside-an-irregularly-shaped-data-footprint-in-r