2017-03-09 62 views
0

我有将要被转换成一组折线点的文件。一些线是多部分,我想将它们转换为单部分。 处理点并将多段线添加到临时要素类(用于备份目的)。如果一行是多部分,则它将作为多部分添加到此临时要素类中。 然后读取临时要素类,并将其复制到基本要素类中。这适用于单部件特征,但在将多部件转换为单部件时,我始终得到'不支持此几何类型'的错误。问题是,要从一组点创建多部分功能,我必须将一个段集合用作Path。我试着把它设置成多段线,但是向它添加线段会导致错误(错误的几何类型)。IGeometryCollection折线的返回路径

当我到多的功能添加到临时要素类的几何形状折线。当我稍后检索它们(通过将形状放入新的GeometryCollection中)时,几何集合是Polyline,但各个几何体是Paths(?)。

的代码是:

1. Add points to interim featureclass by putting them in a pointcollection. 

    pPtColl = (IPointCollection4)new Polyline(); 
    pGeomColl = (IGeometryCollection)new Polyline(); 

    // Fill point collection 
    ....... 

    // Create a path made up of segments from the point collection 
    ISegment pSegment; 
    ISegmentCollection pSegColl = (ISegmentCollection)new ESRI.ArcGIS.Geometry.Path(); // Fails if changed to new Polyline() 

    // M and Z aware 
    if (bHasZ == true) 
    { 
     pZAware = (IZAware)pSegColl; 
     pZAware.ZAware = true; 
    } 
    if (bHasM == true) 
    { 
    pMAware = (IMAware)pSegColl; 
    pMAware.MAware = true; 
    } 

    for (int n = 1; n < pPtColl.PointCount; n++) 
    { 
    pSegment = (ISegment)new Line(); 
    pSegment.SpatialReference = pSpRef; 
    pSegment.FromPoint = pPtColl.Point[n - 1]; 
    pSegment.ToPoint = pPtColl.Point[n]; 
    pSegColl.AddSegment(pSegment, oMissing, oMissing); 
    } 

    pGeomColl.AddGeometry(pSegColl as IGeometry, oMissing, oMissing); 

    pGeom = (IGeometry)pGeomColl; // pGeom has geometry type = Polyline 
    pGeom.SpatialReference = pSpRef; 

    pFeat.Shape = pGeom; 

代码一切工作正常的这一部分。 处理临时要素类中的这些要素以将它们添加到基础要素类时,我收到一个错误,因为几何集合中的几何类型是'路径'而不是'折线'。

// Read the geometry from the interim feature into a geometry collection 
pGeomColl = (IGeometryCollection)new Polyline(); 
pGeomColl = (IGeometryCollection)pFromFeature.ShapeCopy; 

for (int j = 0; j < pGeomColl.GeometryCount; j++) 
{ 
    // Create a new (Polyline) feature pToFeat and populate its attributes 
    pToFeat = pToFC.CreateFeature(); 
    .... 

    // pGeomColl has geometry type = Polyline 
    pGeom = pGeomColl.Geometry[j]; // pGeom has geometry type = Path 
    pToFeat.Shape = pGeom; // Fails. pToFeat is a Polyline. 
} 

如何确保几何集合包含带多段线而不是路径的几何?

感谢,

JM

回答

0

我已经找到了我condsider成为这个问题的方法,但它是不是很漂亮。 解决方案是将Path几何体转换为多段线,然后在将其分配给.Shape属性时将其重新转换为几何体。

 if (pToFeat .ShapeCopy.GeometryType == esriGeometryType.esriGeometryPolyline && pGeom.GeometryType == esriGeometryType.esriGeometryPath) 
    { 
     IPolyline pPoly = (IPolyline)new Polyline(); 
     pPoly = geometryToPolyline(pGeom, bHasZ, bHasM, ref sError); 
     if (sError.Length > 0) 
     { 
      sError = "processAdds; ID = " + sID + " OID = " + iOID.ToString() + sNL + sError; 
      clsMain.write_log(sError, clsMain.m_eLogType.FATAL); 
      iErrorCount++; 
     } 
     else 
     { 
      pToFeat.Shape = (IGeometry)pPoly; 
     } 
    } 


private static IPolyline geometryToPolyline(IGeometry pInputGeom, bool bHasZ, bool bHasM, ref string sError) 
{ 
IPolyline pPoly = null; 
IGeometryCollection pPolyColl = null; 
IZAware pZAware; 
IMAware pMAware; 
double dZ; 
ISpatialReference pSpRef; 
bool bIsMulti; 
esriGeometryType pType; 

try 
{ 
    sError = ""; 

    pSpRef = pInputGeom.SpatialReference; 

    // Create a new polyline 
    pPoly = (IPolyline)new Polyline(); 

    if (bHasZ == true) 
    { 
     pZAware = (IZAware)pPoly; 
     pZAware.ZAware = true; 
    } 
    if (bHasM == true) 
    { 
     pMAware = (IMAware)pPoly; 
     pMAware.MAware = true; 
    } 

    // Create the geometry collection 
    pPolyColl = (IGeometryCollection)new Polyline(); 
    if (bHasZ == true) 
    { 
     pZAware = (IZAware)pPolyColl; 
     pZAware.ZAware = true; 
    } 
    if (bHasM == true) 
    { 
     pMAware = (IMAware)pPolyColl; 
     pMAware.MAware = true; 
    } 

    // Set the polyline as the geometry collection 
    pPoly = (IPolyline)pPolyColl; 
    pPoly.SpatialReference = pSpRef; 
    pPolyColl.AddGeometry(pInputGeom); 

    return pPoly; 
} 
catch (Exception ex) 
{ 
    System.Diagnostics.StackTrace pStack = new System.Diagnostics.StackTrace(ex, true); 
    System.Diagnostics.StackFrame pFrame = pStack.GetFrame(pStack.FrameCount - 1); 
    int iLineNo = pFrame.GetFileLineNumber(); 

    sError = "ERROR: geometryToPolyline; Line: " + iLineNo + "\n" + ex.ToString(); 
    return pPoly; 
} 

}