0

I have a group of Multipart Polyline Geometries which have measures. I am trying to re-order the geometries to better follow the traffic flow. I am using a GeometryBridge to add the re-orderd segments to an ISegmentCollection. The problem is that my segments have their M values reset so they must be IMSegmentation4 segments. When I try to add these to an ISegmentCollection VS the program won't compile. I am using VS2010, ArcGis 10.2 and 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();

Can anyone tell me how to accumulate a set of measure segments?

PolyGeo
  • 1,340
  • 3
  • 26
  • 59
John M
  • 53
  • 7

1 Answers1

0

I found that using a Segment Collection is the wrong approach. A segment is the line segment between vertices of a polyline.

The trick is to put the polyline into a geometry collection and then add the parts of that geometry collection into the new (re-ordered) 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();
John M
  • 53
  • 7