简体   繁体   中英

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!

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)

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM