使用SQL空间数据(C#)来查找"视觉"不规则多边形的中心 [英] Using Sql Spatial Data (C#) to find the "visual" center of irregular polygons

查看:398
本文介绍了使用SQL空间数据(C#)来查找"视觉"不规则多边形的中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我画的区域(使用 SqlGeometry / SqlGeography ,并将其转换为WPF 在必应地图WPF控件LocationCollection 当量),并贴上标签需要。我上了区绘制的标签,并将其连接到由 STCentroid发现点()。当然,如你想象这是用U或C形状的区域,其中的重心区域,这使得标签不正确外结束的一个问题。



有没有使用 SqlGeometry / SqlGeography 办法找到视觉中心或者找到能够适应最大圆的形状,并使用该中心?我试过各种方法使用 STPointOnSurface()但似乎 STPointOnSurface()总是挑选对像这样DCREHA边缘的点(为底深绿色区域中的标签总是在边缘结束




解决方案

这是几乎相同的问题已经被问这里。在你的情况下,最相关的答案可能是的之一。这个问题的答案的最艰难的部分是确定在哪里画的拆分多边形进线。两个相等的区域。因此,我提出以下稍作修改的版本的SQL Server:




  1. 使用 STCentroid 找到质量中心

  2. 如果这是多边形内( STWithin ),则无需进一步处理;否则:

  3. 确定多边形的边界框的质心(如使用 STEnvelope 来得到多边形的信封,并传递作为参数 STCentroid

  4. 如果这个心是多边形内( STWithin ),它可能是不够好(需要测试);否则:

  5. 扩展该这样它延伸到刚好超出在每个方向上的多边形的信封(可在C#代码是更容易,或见<一个连接多边形的质心和包络的质心的线HREF =http://gis.stackexchange.com/a/104451/66066>这里为PostGIS的解决方案)

  6. 确定延长线之间的交叉点,多边形( STIntersection

  7. 找到最近的交叉点,从第1步多边形的质心点(见的这里)。这一点对于第一个切点中的联答案详细的近似值。

  8. 找到最近的交叉点在步骤7上面的交点这一点对于第二个切点的的链接的答案

  9. 线的中点连接两个交点将是多边形内部,应该是一个合理的近似视觉中心多边形的。



  10. 有关实例,给出了上面的DCREHA例如多边形,以下的GIF动画上面列出的程序(




    I'm drawing regions (using SqlGeometry/SqlGeography and translating them to the WPF LocationCollection equivalent) on the Bing Maps WPF Control and needed to label them. I got the labels drawn on the regions and attached them to the point found by STCentroid(). Of course as you imagine this is a problem with the 'U' or 'C' shaped regions where the centroid ends up outside the region, which makes the label incorrect.

    Is there a way using SqlGeometry/SqlGeography to find the "visual" center or perhaps find the largest circle that can fit in the shape and use that center? I've tried various methods using STPointOnSurface() but it seems that STPointOnSurface() always picks a point on the edge like so DCREHA (the label for the bottom dark green region always ends up on the edges:

    解决方案

    An almost identical question has already been asked here. In your case, the most relevant answer is probably this one. The hard part of that answer is determining where to draw the line that splits the polygon into two equal areas. Therefore, I propose a slightly modified version below for SQL Server:

    1. Use STCentroid to find the centre of mass
    2. If this is inside the polygon (STWithin), then no need to process further; otherwise:
    3. Determine the centroid of the polygon's bounding box (e.g. use STEnvelope to get the polygon's envelope and pass that as the argument to STCentroid)
    4. If this centroid is within polygon (STWithin), it may be good enough (would need testing); otherwise:
    5. Extend the line that connects the polygon's centroid and the envelope's centroid so that it extends to just beyond the polygon's envelope in each direction (may be easier in C# code, or see here for a PostGIS solution)
    6. Determine the intersection points between the extended line and the polygon (STIntersection)
    7. Find the nearest intersection point to the polygon's centroid point from step 1 (see here). This point is an approximation for the "1st cut point" detailed in the linked answer.
    8. Find the nearest intersection point to the intersection point found above in step 7. This point is an approximation for the "2nd cut point" detailed in the linked answer.
    9. The mid-point of the line that connects the two intersection points will be inside the polygon, and should be a reasonable approximation for the "visual centre" of the polygon.

    For instance, given the polygon for the DCREHA example above, the following GIF animates the procedure listed above (judged by eye - actual result will differ):

    这篇关于使用SQL空间数据(C#)来查找&QUOT;视觉&QUOT;不规则多边形的中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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