2017-04-13 50 views
0

我有一組多部分折線幾何圖形,其中包含一些度量。我正在嘗試重新排列幾何圖形以更好地跟蹤交通流量。 我正在使用GeometryBridge將重新排序的片段添加到ISegmentCollection。 問題是我的段的M值重置,因此它們必須是IMSegmentation4段。當我嘗試將這些添加到ISegmentCollection VS時,程序將無法編譯。 我使用VS2010時,ArcGIS 10.2和Windows 7更改多部分幾何圖形的順序

pExGeomColl = (IGeometryCollection)new Polyline(); 
pExGeomColl = (IGeometryCollection)pBaseFeat.ShapeCopy; 
for (int i = 0; i < hGeomToFrom.Count; i++) 
{ 
    iTo = i; 
    iFrom = (int)hGeomToFrom[i]; 
    pGeom = pExGeomColl.Geometry[iFrom]; 
    pGeom.SpatialReference = pSpRef; 
    pMAware = (IMAware)pGeom; 
    pMAware.MAware = true; 

    pPolyline = (IPolyline6)new PolylineClass(); 
    if (pGeom.GeometryType != esriGeometryType.esriGeometryPolyline) 
    { 
     pPolyline = geometryToPolyline(pGeom, false, true, ref sError); 
     if (sError.Length > 0) 
     { 
      sError = "cmdReset\r\n" + sError; 
      clsMain.write_log(sError, clsMain.m_eLogType.FATAL); 
      MessageBox.Show(sError); 
      return; 
     } 

    } 
    else 
    { 
     pPolyline = (IPolyline)pGeom; 
    } 
    dLen = pPolyline.Length; 
    dFrom = dMeasure; 
    dTo = dFrom + dLen; 
    pSeg = (IMSegmentation4)pPolyline; 
    pSeg.SetAndInterpolateMsBetween(dFrom, dTo); 
    dMeasure = dTo; 

    pSegArray[i] = pSeg; 

    ProgressBar1.Value = iCount; 
    iCount++; 
} 

// Add the segment array to a segment collection 
pNewSegColl = (ISegmentCollection)new PolylineClass(); 
pMAware = (IMAware)pNewSegColl; 
pMAware.MAware = true; 

pGeomBridge = new GeometryEnvironmentClass(); 
pGeomBridge.AddSegments(pNewSegColl, pSegArray); // This doesn't work 

pGeom = (IGeometry)pNewSegColl; 
pGeom.SpatialReference = pSpRef; 
pBaseFeat.Shape = pGeom; 

pBaseFeat.Store(); 

誰能告訴我如何積累了一套衡量段?

回答

0

我發現使用Segment Collection是錯誤的方法。段是折線頂點之間的線段。

訣竅是將多段線放入幾何集合中,然後將該幾何集合的各個部分添加到新的(重新排序的)集合中。

// Existing Geometry Collection 
pExGeomColl = (IGeometryCollection)new PolylineClass(); 
pExGeomColl = (IGeometryCollection)pBaseFeat.ShapeCopy; 
// New Geometry collection 
pNewGeomColl = (IGeometryCollection)new PolylineClass(); 
pMAware = (IMAware)pNewGeomColl; 
pMAware.MAware = true; 
pZAware = (IZAware)pNewGeomColl; 
pZAware.ZAware = bHasZ; 

for (int i = 0; i < hGeomToFrom.Count; i++) 
{ 
    iTo = i; 
    iFrom = (int)hGeomToFrom[i]; 
    pGeom = pExGeomColl.Geometry[iFrom]; 
    pGeom.SpatialReference = pSpRef; 
    pMAware = (IMAware)pGeom; 
    pMAware.MAware = true; 
    pZAware = (IZAware)pGeom; 
    pZAware.ZAware = bHasZ; 
    // Convert the geometry to a polyline 
    pPolyline = (IPolyline6)new PolylineClass(); 
    if (pGeom.GeometryType != esriGeometryType.esriGeometryPolyline) 
    { 
     pPolyline = geometryToPolyline(pGeom, bHasZ, true, ref sError); 
     if (sError.Length > 0) 
     { 
      sError = "cmdReset\r\n" + sError; 
      clsMain.write_log(sError, clsMain.m_eLogType.FATAL); 
      MessageBox.Show(sError); 
      return; 
     } 
    } 
    else 
    { 
     pPolyline = (IPolyline)pGeom; 
    } 
    pMAware = (IMAware)pPolyline; 
    pMAware.MAware = true; 
    pZAware = (IZAware)pPolyline; 
    pZAware.ZAware = bHasZ; 


    dLen = pPolyline.Length; 
    dFrom = dMeasure; 
    dTo = dFrom + dLen; 
    pSeg = (IMSegmentation4)pPolyline; 
    pSeg.SetAndInterpolateMsBetween(dFrom, dTo); 

    IGeometryCollection pXGeomColl = new PolylineClass(); 
    pMAware = (IMAware)pXGeomColl; 
    pMAware.MAware = true; 
    pZAware = (IZAware)pXGeomColl; 
    pZAware.ZAware = bHasZ; 
    pXGeomColl = (IGeometryCollection)pPolyline; 
    for (int j = 0; j < pXGeomColl.GeometryCount; j++) 
     pNewGeomColl.AddGeometry(pXGeomColl.Geometry[j]); 

    dMeasure = dTo; 

    ProgressBar1.Value = iCount; 
    iCount++; 
} 

pGeom = (IGeometry)pNewGeomColl; 
pGeom.SpatialReference = pSpRef; 
pMAware = (IMAware)pGeom; 
pMAware.MAware = true; 
pZAware = (IZAware)pGeom; 
pZAware.ZAware = bHasZ; 
pBaseFeat.Shape = pGeom; 

pBaseFeat.Store();