Cómo rellenar huecos en MULTIPOLYGON en CLR espacial de SQL Server 2008

I have multipolygon that looks like a star with an empty hole in a middle: imagen

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)))

Gracias por su atención.

preguntado el 01 de febrero de 12 a las 04:02

1 Respuestas

Maybe not the fastest way, but one way that you could do it:

  1. Compute a geometry that contains your input: Use STConvexHull, which returns a single polygon that contains your entire input geometry, including both empty regions inside the geometry and concavities outside the geometry (such as the regions in between the points of your star).
  2. Find the empty regions: Use STDifference, subtracting the input from the convex hull, which will return polygons for those empty regions previously mentioned.
  3. Determine which empty regions are outside your input: Use STBoundary to get the bounds of the convex hull. A region is inside your input geometry if and only if it does not touch the bounds of the convex hull. Use STTouches to check.
  4. Compute the union of your geometry and the inner empty regions: Use STUnion.

Aquí hay un script de ejemplo:

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();

    SELECT 1 i


    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


Respondido 01 Feb 12, 09:02

@user1181846 Absolutely - please consider accepting it as the answer if you are satisfied. - Michael Petito

This is absolute gold. Thank you! - KOGI

Great solution. Imaginative use of existing functionality and cunning CTE. - andyb

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.