public void AddParts( IEnumerable<IEnumerable<Segment>> parts )
Public Sub AddParts( _ ByVal parts As IEnumerable(Of IEnumerable(Of Segment)) _ )
Parameters
- parts
- An enumeration of parts built from an enumeration of segments.
public void AddParts( IEnumerable<IEnumerable<Segment>> parts )
Public Sub AddParts( _ ByVal parts As IEnumerable(Of IEnumerable(Of Segment)) _ )
| Exception | Description |
|---|---|
| System.ArgumentNullException | parts is null. |
{
List<Polygon> internalRings = new List<Polygon>();
// explode the parts of the polygon into a list of individual geometries
// see the "Get the individual parts of a multipart feature"
// snippet for MultipartToSinglePart
var parts = MultipartToSinglePart(polygon); //any polygon
// get an enumeration of clockwise geometries (area > 0) ordered by the area
var clockwiseParts = parts.Where(geom => ((Polygon)geom).Area > 0)
.OrderByDescending(geom => ((Polygon)geom).Area);
// for each of the exterior rings
foreach (var part in clockwiseParts)
{
// add the first (the largest) ring into the internal collection
if (internalRings.Count == 0)
{
internalRings.Add(part as Polygon);
}
// use flag to indicate if current part is within the already selection polygons
bool isWithin = false;
foreach (var item in internalRings)
{
if (GeometryEngine.Instance.Within(part, item))
{
isWithin = true;
}
}
// if the current polygon is not within any polygon of the internal collection
// then it is disjoint and needs to be added to
if (isWithin == false)
{
internalRings.Add(part as Polygon);
}
}
PolygonBuilderEx outerRings = new PolygonBuilderEx();
// now assemble a new polygon geometry based on the internal polygon collection
foreach (var ring in internalRings)
{
outerRings.AddParts(ring.Parts);
}
// the final geometry of the outer rings
var outerRingsResult = outerRings.ToGeometry();
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)