如何填补 SQL 服务器中多边形的空白

How to fill the gap in a multipolygon in SQL Server

使用 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

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

我知道的一种方法会引入一些错误(基于投影的 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