2017-03-09 2 views
0

Ich habe eine Datei mit Punkten, die in einen Polyliniensatz umgewandelt werden sollen. Einige der Zeilen sind mehrteilig und ich möchte sie in ein einzelnes Teil konvertieren. Die Punkte werden verarbeitet und die Polylinien zu einer Interim-Feature-Class hinzugefügt (für Sicherungszwecke). Wenn eine Zeile mehrteilig ist, wird sie dieser Interim-Feature-Class als Multipart hinzugefügt. Die Interim-Feature-Class wird dann gelesen und die Features in eine Basis-Feature-Class kopiert. Dies funktioniert gut für Einzelkomponenten-Features, aber ich erhalte weiterhin den Fehler 'Keine Unterstützung für diesen Geometrietyp', wenn die Multiparts in einzelne Teile konvertiert werden. Das Problem besteht darin, dass ich eine Segmentsammlung als Pfad verwenden muss, um das Multipart-Feature aus einer Menge von Punkten zu erstellen. Ich habe versucht, dies auf eine Polylinie einzustellen, aber das Hinzufügen von Liniensegmenten verursacht einen Fehler (falscher Geometrietyp).IGeometryCollection von Polylines gibt Pfade zurück

Wenn ich die Multipart-Features zur Interim-Feature-Class hinzufüge, sind die Geometrien Polylinien. Wenn ich sie später abrufe (indem ich die Form in eine neue GeometryCollection einfüge), ist die Geometriesammlung eine Polylinie, aber die einzelnen Geometrien sind Pfade (?).

Der Code ist:

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; 

Dieser Teil des Codes alles funktioniert gut. Beim Verarbeiten dieser Features aus der Interim-Feature-Class, um sie der Basis-Feature-Class hinzuzufügen, erhalte ich einen Fehler, weil der Geometrietyp aus der Geometriesammlung "Pfad" und nicht "Polylinie" lautet.

// 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. 
} 

Wie kann ich sicherstellen, dass die Geometriesammlung Geometrien mit Polylinien anstelle von Pfaden enthält?

Danke,

JM

Antwort

0

Ich habe gefunden, was ich condsider eine Abhilfe für dieses Problem sein, aber es ist nicht sehr hübsch. Die Lösung besteht darin, die Pfadgeometrie in eine Polylinie zu konvertieren und sie dann in eine Geometrie zurückzuversetzen, wenn sie dem Attribut .Shape zugewiesen wird.

 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; 
} 

} 
Verwandte Themen