减少线上点数
我正在寻找算法来减少折线、节点线(循环或非循环)的 LOD。 简而言之,我想要获取高分辨率的海岸线数据,并能够将其 LOD 减少数百或数千倍,以小规模渲染。
我发现了多边形缩减算法(但它们需要三角形)和拉普拉斯平滑,但这似乎并不完全是我所需要的。
I'm searching for algorithms to reduce the LOD of polylines, lines (looped or not) of nodes.
In simple words, I want to take hi-resolution coastline data and be able to reduce its LOD hundred- or thousandfold to render it in small-scale.
I found polygon reduction algorithms (but they require triangles) and Laplacian smoothing, but that doesn't seem exactly what I need.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我修改了culebrón的答案中的代码,删除了需要 Vec2D/Line 类,而不是将点作为元组列表处理。
代码稍微不太整洁,但更短,更快一点(对于 900 分,原始代码花了 2966 毫秒,这个版本花了 500 毫秒 - 仍然比我想要的慢一点,但有所改进)
I've modified the code in culebrón's answer, removing the need for the Vec2D/Line classes, instead handling the points as a list of tuples.
The code is slightly less tidy, but shorter, and a bit quicker (for 900 points, the original code took 2966ms, and this version takes 500ms - still a bit slower than I'd like, but an improvement)
我发现并且很可能会使用的解决方案是 Ramer-Douglas-Peucker 算法。它用于 PostGIS
我已经发布了 我自己的 Python 实现(网站目前已关闭,以下内容为 从 archive.org 提取)
The solution that I've found and quite probably will use, is Ramer-Douglas-Peucker algorithm. It's used in PostGIS
I've published my own implementation in Python (site currently down, the following was pulled from archive.org)
当我考虑将贝塞尔曲线转换为直线段时,我最终所做的是定义曲线与曲线两点之间的直线之间的最大距离。从一个点作为一个端点开始,沿着曲线滑动另一端,直到进一步滑动超过最大距离。然后使用第二个(依此类推)点再次执行此操作,直到覆盖整个曲线。
您应该能够通过简单地增加线段和折线之间允许的距离来生成多个 LOD。
When I was looking at turning a Bezier curve into straight line segments, what I ended up doing was defining a maximum distance between the curve and a straight line between two points of the curve. Start with one point being one end-point, slide the other end along the curve, until sliding it any further would exceed the maximum distance. Then do it again, using the second (and so on) point, until you've covered the whole curve.
You should be able to generate multiple LODs by simply increasing the distance allowed between the line segments and your poly-line.
我开发了一个非常简单的算法,使用给定点到以下点的距离来决定将它们包含在渲染中是否有意义。根据当前比例,您可以关联转换模型所需的点之间的最小距离。
I developed a very simple algorithm, using the distance of a given point to the following points to decide whether it makes sense to include them in the rendering. Depending on current scale you could associate a minimum distance between points required for a transformed model.
我喜欢根据线段在点两侧形成的角度对点进行排序,然后迭代删除角度最浅的点,直到达到某个阈值。我认为 O(n log(n)) 与 RDP 方法的 O(n^2) 相比,并且启动的常数较小。 :)
如果您想为较长的线段赋予更多的权重(合意性),角度甚至可以通过线段长度来缩放(事实上,这样计算起来更容易)。
给定 p0、p1、p2、p1 的权重将为 ((p0 - p1) dot (p2 - p1)),如果您不想按长度加权,请将差异归一化。 (与距离线相比,它便宜得多,而且结果可能相同。)
I'm a fan of sorting the points based on the angle that the segments make on either side of the point, then removing the points with the shallowest angle iteratively until you hit some threshold. O(n log(n)) I think, versus the RDP method's O(n^2), and with smaller constants to boot. :)
The angle can even be scaled by the segment lengths (indeed it's easier to compute it this way) if you want to give more weight (desirability) to longer segments.
Given p0, p1, p2, p1's weight would be ((p0 - p1) dot (p2 - p1)), normalize the differences if you don't want to weight by length. (Contrast this to distance-to-line, it is much cheaper, and the results may be identical.)
虽然来晚了,但这里有 Douglas Peucker 算法的 Java 实现。
https:/ /github.com/MKergall/osmbonuspack/blob/0310258c53244a485fda0ff0dd7829e5557b531b/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/utils/DouglasPeuckerReducer.java
Late to the party, but here's a Java implementation of the douglas peucker algorithm.
https://github.com/MKergall/osmbonuspack/blob/0310258c53244a485fda0ff0dd7829e5557b531b/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/utils/DouglasPeuckerReducer.java
添加到大量答案。我在此 github 存储库中找到了一个 javascript 实现: https://github.com/mourner/simplify-js< /a>
还有一个不同语言的 Ramer-Douglas-Peucker 算法的不同实现的列表。
Adding to the slew of answers. I found a javascript implementation at this github repo: https://github.com/mourner/simplify-js
There's also a list of different implementations of the Ramer-Douglas-Peucker algorithm in different languages.
关于 culebron 的答案,递归调用正确吗?据我了解,RDP 将一行分成两条不同的行:从开始到最大,以及从最大到结束。
但是看看这个调用,其中 pos 是列表中最大距离的索引...
而是从开始到 max+1,从 max+1 到结束。难道不应该是...
In regards to culebron's answer, is the recursive call correct? From what I understand, RDP breaks up a a line into two different lines: start to max, and max to end.
But looking at the call, where pos is the index of the max dist in the list...
is instead doing start to max+1, max+1 to end. Shouldn't it be...