更好的“中心点”比质心 [英] Better "centerpoint" than centroid

查看:107
本文介绍了更好的“中心点”比质心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用多边形的质心在地图应用程序中附加标记。

I'm using the centroid of polygons to attach a marker in a map application. This works definitely fine for convex polygons and quite good for many concave polygons.

但是,某些多边形(香蕉,甜甜圈)显然无法产生预期的结果:质心在这种情况下,是多边形区域之外。

However, some polygons (banana, donut) obviously don't produce the desired result: The centroid is in these cases outside the polygons area.

有人知道更好的方法来找到内部的合适点吗?是否有任何要标记的多边形区域(可能包含孔!)?

Does anybody know a better approach to find a suitable point within any polygons area (which may contain holes!) to attach a marker?

推荐答案

一种方法是生成并优化多边形,然后使用骨骼的中点放置标记(如果是文本,则可以正确定位文本)。

One approach would be to generate and refine a skeleton of the polygon, then use the midpoint of the skeleton to place your marker (and if it's text, to orient the text correctly). This works well for most shapes, including ones with holes, and banana-shaped or tadpole-shaped crescents.

CGAL库具有 2D直形骨架和多边形偏移模块,也可以使用PostGIS

The CGAL library has a 2D Straight Skeleton and Polygon Offsetting module, or you could use PostGIS, for example.

这篇关于更好的“中心点”比质心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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