Question

The title basically says it all. In my case, I have a polyline and I have to find out if it is multi-part or single-part.

In general, the entire Internet (searched via Google), and ESRI's online material in particular, has proven rather neutral on this topic. There was some hope here. The relevant extract copied below:

You can determine the number of paths in a Polyline or rings in a Polygon by using the PathCount or RingCount properties respectively. Use the overloaded GetPoint methods to get a copy of the Point at a specific position in a specific path or ring. The following code example iterates through all of the points in a Polyline, multiPathLine, using the PathCount, PointCount and GetPoint members:

// Iterate through all points in all paths.
for (int i = 0; i < multiPathLine.PathCount; i++)
{
    for (int j = 0; j < multiPathLine.PointCount(i); j++)
    {
        multiPathLine.GetPoint(i, j);
    }
}

Promising as that looked, nowhere on that long, long page do they inform the would-be developer of what type multiPathLine is. So I went searching for the elusive PathCount property but it remained unfound.

Was it helpful?

Solution

The solution is actually so easy: Just cast your polyline to a IGeometryCollection and check its GeometryCount property. If it is greater than 1, then it is a multi-part geometry.

This works not only with polylines, but with polygons and points, too.

static bool IsMultiPart(this IGeometry geometry)
{
    var geometryCollection = geometry as IGeometryCollection;
    return geometryCollection != null && geometryCollection.GeometryCount > 1;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top