# Separate boundaries of multiply connected region

I have a multiply connection two-dimensional region such as the following:

br = BoundaryDiscretizeGraphics@Graphics[Disk[#, 8/9] & /@ CirclePoints[9]]


I am looking for a way to discard all inner "holes", i.e. get this:

In order to get this I was hoping to be able to separate the two boundaries of the region, then manually pick the outer one. What is a simple way to do this?

Here's an attempt to automate the selection of the outer boundaries with some undocumented properties. Here's a BoundaryMeshRegion with multiple holes and multiple outer boundaries:

g1 = Graphics[Table[Annulus[{x, 0}, {0.5 + x/20, 1}], {x, 0, 9, 3}]];
g2 = Graphics[Rectangle[{1.5, -0.3}, {7.5, 0.3}]];
br = RegionUnion[BoundaryDiscretizeGraphics /@ {g1, g2}]


The "BoundaryGroups" property groups the boundaries of connected regions, and it appears that the first element of each group is the outer boundary. (Pure conjecture of course, but that was the case for the limited number of tests I did).

bgps = br["BoundaryGroups"]
(* {{6, 2, 3, 4, 5}, {8, 7}, {1, 9}} *)

outer = bgps[[All, 1]]
(* {6, 8, 1} *)


I use another undocumented property, "IndexedBoundaryPolygons" to extract the polygons with those indices and construct a new region:

polys = br["IndexedBoundaryPolygons"][[outer]];

MeshRegion[MeshCoordinates[br], polys]


One possible solution is to take the boundary, then find the connected components:

ConnectedMeshComponents@RegionBoundary[br]


Key functions: ConnectedMeshComponents, RegionBoundary.

We can then manually pick the boundary we want:

outer = First[%];


And convert it back to a polygon (a 2D region rather than a boundary):

BoundaryDiscretizeRegion@Polygon@MeshCoordinates[outer]


In more complicated examples order of the points returned by MeshCoordinates may not follow the boundary in a continuous manner. In this case we can reorder them before converting them to a polygon:

pts = Part[
MeshCoordinates[outer],
DeleteDuplicates@Level[MeshCells[outer, 1], {-1}]
];

• I arrived to this solution after I have written up the question. Given that it took me some time to figure this out, I though posting the solution would be more valuable than deleting the question. – Szabolcs Dec 21 '15 at 9:25
• I was just about to post just another way of selecting the relevant mesh coordinates by selecting outside a disk...this is helpful and I am voting for it:) – ubpdqn Dec 21 '15 at 9:43
• @ubpdqn If you have another solution, I would like to see it! – Szabolcs Dec 21 '15 at 9:49
• @ubpdqn That would have worked too. I disk would not work for my real example, but I could have drawn an outline manually to separate the outer boundary from the inner ones, then test whether the points are within this outline. – Szabolcs Dec 21 '15 at 9:50
• it probably just worked for this case where the internal boundary is conveniently separable by a disk and the outer coordinates conveniently ordered... – ubpdqn Dec 21 '15 at 9:51