如何确定几何是否是多部分的?

Jac*_*sch 2 arcobjects

标题基本上都说明了一切.在我的情况下,我有一条折线,我必须找出它是多部分还是单部分.

一般而言,整个互联网(通过谷歌搜索),特别是ESRI的在线资料,已经证明在这个主题上相当中立.有一些希望在这里.以下复制的相关摘录:

您可以分别使用PathCount或RingCount属性确定折线中的路径数或多边形中的环.使用重载的GetPoint方法在特定路径或环中的特定位置获取Point的副本.以下代码示例使用PathCount,PointCount和GetPoint成员遍历P​​olyline,multiPathLine中的所有点:

// 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);
    }
}
Run Code Online (Sandbox Code Playgroud)

看起来很有希望,在这个漫长的页面上没有任何地方可以告诉潜在的开发者什么类型multiPathLine.所以我去寻找难以捉摸的PathCount财产,但它仍然没有.

Jac*_*sch 5

解决方案实际上非常简单:只需将折线转换为a IGeometryCollection并检查其GeometryCount属性即可.如果它大于1,则它是多部件几何.

这不仅适用于折线,也适用于多边形和点.

static bool IsMultiPart(this IGeometry geometry)
{
    var geometryCollection = geometry as IGeometryCollection;
    return geometryCollection != null && geometryCollection.GeometryCount > 1;
}
Run Code Online (Sandbox Code Playgroud)