【问题标题】:How to fill the gap in a multipolygon in SQL Server如何在 SQL Server 中填补多面体中的空白
【发布时间】:2021-02-04 00:56:27
【问题描述】:

使用 SQL Server 2014。

我有以下自相交几何,我使用 .MakeValid() 使其有效,它给出了一个多面体。

declare @geomOrig geometry
select @geomOrig = geometry::STGeomFromText('POLYGON((705768.86 6193250.0725,705646.46 6193139.6725,705848.06 6193169.2725,705636.06 6193237.2725,705784.06 6193102.0725,705768.86 6193250.0725))', 25832).MakeValid()
select @geomOrig

问题是:如何填充中间的空隙来创建单个星形多边形?

【问题讨论】:

    标签: geometry sql-server-2014 spatial computational-geometry


    【解决方案1】:

    我知道的一种方法会引入一些错误(基于投影的 0.0000001 个单位)如下所示。它确实会产生您正在寻找的单个多边形星。我删除了您原始文件中的十进制值,以便查看引入了多少错误。

    DECLARE @geomOrig GEOMETRY, @geomText VARCHAR(MAX), @geomOuterPoly GEOMETRY
    SELECT @geomOrig = geometry::STGeomFromText('POLYGON((705768 6193250,705646 6193139,705848 6193169,705636 6193237,705784 6193102,705768 6193250))', 25832).MakeValid()
    
    -- buffer the existing polygons by a small amount to join them into one polygon and get the exterior ring (LINESTRING)
    SET @geomOuterPoly = @geomOrig.STBuffer(0.0000001).STExteriorRing()
    
    -- get the WKT of the buffered polygon
    SET @geomText = @geomOuterPoly.STAsText()
    
    -- replace the word 'LINESTRING' with 'POLYGON' and add an extra parenthese
    SET @geomText = REPLACE(@geomText, 'LINESTRING', 'POLYGON')
    SET @geomText = REPLACE(@geomText, '(', '((')
    SET @geomText = REPLACE(@geomText, ')', '))')
    
    -- build a new geometry from the text
    SET @geomOuterPoly = geometry::STGeomFromText(@geomText, 25832)
    
    -- unbuffer the polygon to get back down to the previous shape (small amount of error introduced here)
    SET @geomOuterPoly = @geomOuterPoly.STBuffer(-0.0000001)
    
    -- select the final polygon
    SELECT @geomOuterPoly
    

    【讨论】:

    • 完美运行。并且似乎也适用于类似的数字。
    猜你喜欢
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-19
    • 1970-01-01
    • 2010-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多