Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine which points lay outside an irregularly-shaped data footprint in R?

I have a series of points in an area whose 'footprint' shape is highly irregular:

LE82

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!

like image 249
theforestecologist Avatar asked Sep 19 '16 19:09

theforestecologist


1 Answers

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)
})

enter image description here

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)

enter image description here

like image 55
lukeA Avatar answered Sep 27 '22 21:09

lukeA