确定哪些点位于R中不规则形状的数据覆盖区之外? [英] Determine which points lay outside an irregularly-shaped data footprint in R?

查看:150
本文介绍了确定哪些点位于R中不规则形状的数据覆盖区之外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在足迹"形状高度不规则的区域中有一系列点:

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!).

但是,当我尝试创建凸包时,显然是由于我的绿色空间形状不规则而造成的问题. [有人知道创建 CONVAVE 船体的方法吗?]

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!

推荐答案

或者,有没有一种方法可以使用'click 图的类型方法?

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

并确定其中哪些点在内部/外部(请参见?point.in.polygon):

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)

这篇关于确定哪些点位于R中不规则形状的数据覆盖区之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆