如何简化KML(减少点数)?
我遇到了与这篇文章类似的问题。 我需要在嵌入式 Google 地图上显示最多 1000 个多边形。 这些多边形位于 SQL 数据库中,我可以使用自定义 HttpHandler(在 ASP.NET 中)将每个多边形即时渲染为单个 KML 文件,如下所示 http://alpha.foresttransparency.org/concession.1.kml 。
即使在我的(非常快的)开发机器上,加载几十个形状也需要一段时间。 所以有两个问题:
一旦我超出一定的缩放级别,将这些渲染为标记而不是覆盖层的好策略是什么?
是否有公开可用的算法来简化多边形(减少点数),以便我在特定缩放级别上显示的点不会多于有意义?
I have a similar problem to this post. I need to display up to 1000 polygons on an embedded Google map. The polygons are in a SQL database, and I can render each one as a single KML file on the fly using a custom HttpHandler (in ASP.NET), like this http://alpha.foresttransparency.org/concession.1.kml .
Even on my (very fast) development machine, it takes a while to load up even a couple dozen shapes. So two questions, really:
What would be a good strategy for rendering these as markers instead of overlays once I'm beyond a certain zoom level?
Is there a publicly available algorithm for simplifying a polygon (reducing the number of points) so that I'm not showing more points than make sense at a certain zoom level?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对于第二个问题:您需要 Douglas-Peucker 泛化算法
For your second question: you need the Douglas-Peucker Generalization Algorithm
对于您的第一个问题,您是否可以计算特定多边形的面积,并将每个缩放级别与特定的最小区域相关联,以便当您放大或缩小时,多边形会消失,并且标记会根据缩放级别而出现。
对于第二个问题,我会使用马克·贝西的建议。
For your first question, could you calculate the area of a particular polygon, and relate each zoom level to a particular minimum area, so as you zoom in or out polygon's disappear and markers appear depending on the zoom level.
For the second question, I'd use Mark Bessey's suggestion.
我对 KML 不太了解,但我认为问题#2 的通常解决方案涉及迭代点,并删除特定大小以下的任何线段。 在某些情况下,这会导致一些“不幸”的影响,但它相对较快且容易做到。
I don't know much aobut KML, but I think the usual solution to question #2 involves iterating over the points, and deleting any line segments under a certain size. This will cause some "unfortunate" effects in some cases, but it's relatively fast and easy to do.
我会推荐两件事:
- 计算并组合接触的多边形。 这涉及大量的处理和硬数学,但我已经做到了,所以我知道这是可能的。
- 创建您自己的叠加层,而不是使用 PNG 格式的 KML,同时在之前的建议中将它们组合起来。 您必须创建大量 PNG,但它在客户端上的速度非常快。
祝你好运 :)
I would recommend 2 things:
- Calculate and combine polygons that are touching. This involves a LOT of processing and hard math, but I've done it so I know it's possible.
- Create your own overlay instead of using KML in PNG format, while you combine them in the previous suggestion. You'll have to create a LOT of PNGs but it is blazing fast on the client.
Good luck :)
不久前我需要一个解决你的#2问题的方法,在查看了一些可用的线路简化算法之后,我创建了自己的算法。
这个过程很简单,而且似乎运行良好,尽管如果您没有正确实现它可能会有点慢:
P[0..n]
是您的点数组令
T[n]
定义为由点P[n-1]、P[n]、P[n+1 形成的三角形]
Max
是您尝试将此线减少到的点数。T[1..n-1]
的面积。T[i]
P[i]
,使三角形基本变平T[n -1], T[n+1]
最大
I needed a solution to your #2 question a little bit ago and after looking at a few of the available line-simplification algorithms, I created my own.
The process is simple and it seems to work well, though it can be a bit slow if you don't implement it correctly:
P[0..n]
is your array of pointsLet
T[n]
be defined as the triangle formed by pointsP[n-1], P[n], P[n+1]
Max
is the number of points you are trying to reduce this line to.T[1..n-1]
in the set.T[i]
with the smallest areaP[i]
to essentially flatten the triangleT[n-1], T[n+1]
Max