简体   繁体   English

删除重叠的多边形,点太多

[英]Removing overlapping polygons, too many points

I have many points of data. 我有很多数据点。 In fact, too many points. 其实太多了。 None of the points are overlapping but some are quite near to each other. 没有一点是重叠的,但有些彼此很接近。 I'd like to have less points but without moving any of the locations. 我想减少点数,但不移动任何位置。

I'd to end up with as many points as possible but only points which are at least ~5.7km apart from any other point. 我最终将获得尽可能多的点,但只能与其他任何点至少相距约5.7公里。 (if there is a little bit of overlap it's okay -- an error of 0.5km is acceptable) (如果有一点重叠,就可以了-0.5km的误差是可以接受的)

I tried to write an algorithm in R to accomplish this but there are quite a few unexpected results. 我试图用R编写一个算法来完成此操作,但是有很多出乎意料的结果。 I have some data that is about 300,000 points covering the earth. 我有一些覆盖地球的大约300,000点数据。 I have some other data that is a few million. 我还有其他几百万个数据。 When I execute the algorithm I can segment the data by country which could reduce those numbers into the 20,000 to 100,000 range. 执行算法时,我可以按国家/地区细分数据,从而将这些数字减少到20,000到100,000之间。 If the location of the points didn't matter then I would probably just make an interpolated raster and call it good but for this problem I need to keep the specific location intact. 如果这些点的位置无关紧要,那么我可能只是制作一个插值栅格并将其命名为好,但是对于这个问题,我需要保持特定位置不变。

Another thing that I tried is to make a regular grid of 0.028 degrees and run NNJoin to find the nearest data point. 我尝试做的另一件事是制作一个0.028度的规则网格,然后运行NNJoin查找最近的数据点。 This worked a bit better than my R code but the results are a bit funny as you can probably imagine. 这比我的R代码要好一些,但是结果可能有点像您想象的那样有趣。

Another idea I had was to Buffer the points the count how many of the points intersect with the Buffered layer. 我的另一个想法是对点进行缓冲,计算与缓冲层相交的点数。 I'm still working on this one 我还在做这个

Is there an already established method for arriving at this result? 有没有已经建立的方法来达到这个结果? I am comfortable to work with PostGIS, QGIS, Python, R if there is a package or library that can do this. 如果有可以执行此操作的程序包或库,我很愿意与PostGIS,QGIS,Python,R一起使用。

tl;dr how do I reduce dense clusters of points but maintain coverage with a reduced set of points? tl; dr如何减少密集的点簇,但保持减少的点集覆盖率?

Here is an approach. 这是一种方法。

Example data 示例数据

x <- runif(10000, -180, 180)
y <- runif(10000, -90, 90)
pts <- cbind(x, y)

Solution

library(raster)
# you will want a lower resolution than this
r <- raster(nrow=18, ncol=36, vals=1) 
# get cell numbers
cells <- cellFromXY(r, pts)
# pick one point per cell
sel <- aggregate(pts, list(cells), function(i)i[1])  # or sample

Let's see 让我们来看看

plot(r)
points(pts, cex=.1)
points(sel[,2:3], pch=20, col="red")

Note that this use lon/lat so the distances are not the same across latitudes. 请注意,此操作使用lon / lat,因此跨纬度的距离不同。 Not sure if that matters; 不确定是否重要; but if so you could transform. 但如果是这样,您可以转型。

Later: 后来:

There are several ways to create shifted variations by changing the extent, or when creating the RasterLayer. 有多种方法可以通过更改范围或创建RasterLayer来创建偏移的变体。 See ?raster and ?extent for more. 有关更多信息,请参见栅格和范围。 You can also use shift 您也可以使用shift

#add a row and a column
r1 <- raster(nrow=19, ncol=37, xmx=190, ymn=-100)
r2 <- shift(r1, -.5*xres(r1), -.5*yres(r1))

plot(as(r1, "SpatialPolygons"))
lines(as(r2, "SpatialPolygons"), col="red")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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