I have multipolygon that looks like a star with an empty hole in a middle: image
How do I transform this multipolygon into a single polygon or multipolygon that also includes the hole in a middle, e.g. fill the hole (using SQL Server 2008 CLR)?
WKT of the empty star: MULTIPOLYGON (((-75.850724788384952 39.781027647924496, -75.847514688412119 39.777165541462658, -75.835440819564724 39.781232982437771, -75.850724788384952 39.781027647924496)), ((-75.861083592601616 39.772592386436379, -75.836642464570019 39.764081172000729, -75.847514688412119 39.777165541462658, -75.861083592601616 39.772592386436379, -75.861083592601616 39.772592386436379)), ((-75.866832035574916 39.780809081927849, -75.850724788384952 39.781027647924496, -75.857585145413083 39.78927966926625, -75.866832035574916 39.780809081927849)), ((-75.8843643235475 39.764740937261692, -75.861083592601616 39.772592386436379, -75.8717486771904 39.776304058191712, -75.8843643235475 39.764740937261692)), ((-75.884021002483152 39.780573380153484, -75.8717486771904 39.776304058191712, -75.866832035574916 39.780809081927849, -75.884021002483152 39.780573380153484)))
Thank you.
Maybe not the fastest way, but one way that you could do it:
Here is an example script:
DECLARE @g geometry;
DECLARE @hull geometry;
DECLARE @regions geometry;
DECLARE @boundary geometry;
SET @g = geometry::STGeomFromText(...);
SET @hull = @g.STConvexHull();
SET @regions = @hull.STDifference(@g);
SET @boundary = @hull.STBoundary();
WITH Geoms AS
(
SELECT 1 i
UNION ALL
SELECT i + 1
FROM Geoms
WHERE i < @regions.STNumGeometries()
)
SELECT @g = @g.STUnion(@regions.STGeometryN(i))
FROM Geoms
WHERE @regions.STGeometryN(i).STTouches(@boundary) = 0
SELECT @g
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With