Working with holes of a polygon

1700
2
03-04-2017 07:02 PM
MaxMax2
Occasional Contributor II

I have a couple of questions regarding to working with parts of polygons.

How can I know if a part is a hole?

At now there is no easy way to determine if a polygon's part is a hole. Turning the part into polygon and checking the sign of its area is the only way. If value of the Area property is a positive number we deal with exterior ring, if negative – with a hole. But it's not obvious.

It would be great if there will be some method to check orientation of a part in the Pro SDK. Since a part of a polygon is just ReadOnlySegmentCollection (which is common for polylines and polygons) maybe the more appropriate place for such method is GeometryEngine.

How can I get all holes of the specific exterior ring?

At now the only way to get all holes of the exetrior part is

var partsAsPolygons = polygon.Parts.Select(p => PolygonBuilder.CreatePolygon(p));
foreach (var exteriorPart in partsAsPolygons.Where(p => p.Area > 0))
{
    var interiorParts = partsAsPolygons.Where(p => p.Area < 0 && GeometryEngine.Contains(exteriorPart, p));
}

So we need to use GeometryEngine.Contains method to find all parts with negative area inside some part with positive area. Awful workaround. Hope you will add easy way to get interior parts of an exterior one.

Tags (2)
0 Kudos
2 Replies
ThomasEmge
Esri Contributor

Please do take a look at the following code snippet ProSnippets Geometry · Esri/arcgis-pro-sdk Wiki · GitHub to determine if we are dealing with an interior (hole) or exterior (boundary) ring.

0 Kudos
MaxMax2
Occasional Contributor II

Hi Thomas,

Thanks for reply. Yes, checking the sign of a polygon's area is a way to determine orientation of a ring. In my first post I mentioned this way. The way you've suggested is more efficient in terms of performance than checking of Area property. But I really don't understand why you are not going to turn this snippet into some method like GeometryUtils.GetOrientationAlso suggested code is more verbose than checking of the Area property value so I am surprised even more that you force developers to use this snippet for such common task as checking of a ring's orienation.

0 Kudos