2017-10-02 3 views
0

現在、道路の集合を線形参照しています。 IMSegmatation2.SetMsAsDistance2を使用すると、単一部品のポリラインでは問題なく動作しますが、マルチパートのポリラインでは、ポイントとポリラインの開始点の最短距離ではなく、ポリラインに沿った長さとしてM値を設定します。 SetMsAsDistance2関数は、平行線のメジャーを等しく設定します。私はそれらを違うものにしたい。Arcobjects:ポリラインの長さに基づいて数値を設定する

各ポリライン頂点のM値を設定する以外に、ポリラインに沿った長さをMとして設定する方法は誰も知っていますか?

答えて

0

解決策は、IMSegmentation3.SetAndInterpolateMsBetween関数を使用することです。 このソリューションでは、フィーチャーを構成するジオメトリが正しい順序であることを前提としています。ジオメトリごとのメジャーを割り当てます。

このためのコードは次のとおりです。

public static void measuresAdd_NonDuplicating(ref IFeature pFeat, bool bHasZ, bool bIgnoreGaps, out string sError) 
    { 
     // Add non-duplicating measures to the feature 
     sError = ""; 
     IMSegmentation3 pSeg; 
     IGeometryCollection pGeomColl; 
     //IGeometryCollection pNewGeomColl; // Use if geometries are to be re-ordered. 
     IGeometry pGeom; 
     IPolyline4 pPoly; 
     IQueryFilter pQ; 
     IMAware pMAware; 
     IZAware pZAware; 
     double dStartMeasure; 
     double dToMeasure; 
     double dMeasure; 
     double dLen; 

     try 
     { 


       if (pFeat.ShapeCopy.IsEmpty == false) 
       { 
        pGeomColl = (IGeometryCollection)new PolylineClass(); 
        pGeomColl = (IGeometryCollection)pFeat.ShapeCopy; 
        if (pGeomColl.GeometryCount == 1) 
        { 
         // Single line geometry. Duplication not an issue. 
         pMAware = (IMAware)pFeat.ShapeCopy; 
         pMAware.MAware = true; 
         pSeg = (IMSegmentation3)pMAware; 
         pPoly = geometryToPolyline((IGeometry)pFeat.ShapeCopy, out sError); 
         if (sError.Length > 0) 
         { 
          sError = "measuresAdd_NonDuplicating\r\n" + sError; 
          return; 
         } 
         pSeg.SetMsAsDistance2(pPoly.FromPoint, 1, 0, bIgnoreGaps); 
         pFeat.Shape = (IGeometry)pSeg; 
         pFeat.Store(); 
        } 
        else 
        { 
         // For re-ordering geometries. Not currently used. 
         //pNewGeomColl = (IGeometryCollection)new Polyline(); 
         //IZAware pZawareNew = (IZAware)pNewGeomColl; 
         //pZawareNew.ZAware = bHasZ; 
         //IMAware pMAwareNew = (IMAware)pNewGeomColl; 
         //pMAwareNew.MAware = true; 

         dStartMeasure = 0; 
         dMeasure = 0; 
         // MultiGeometry. Place them in order and set the measures on each part increasing. 
         // Currently assumes the existing order is correct. 
         for (int i = 0; i < pGeomColl.GeometryCount; i++) 
         { 
          pGeom = pGeomColl.Geometry[i]; 

          pPoly = geometryToPolyline(pGeom, out sError); 
          if (sError.Length > 0) 
          { 
           sError = "measuresAdd_NonDuplicating\r\n" + sError; 
           return; 
          } 
          // Measure Values 
          dStartMeasure = dMeasure; 
          if (i > 0) dStartMeasure += 0.01; 
          dLen = pPoly.Length; 
          dToMeasure = dMeasure + dLen; 
          // Set Measures 
          pMAware = (IMAware)pPoly; 
          pMAware.MAware = true; 
          pZAware = (IZAware)pPoly; 
          pZAware.ZAware = bHasZ; 
          pSeg = (IMSegmentation3)pPoly; 
          pSeg.SetAndInterpolateMsBetween(dStartMeasure, dToMeasure); 

          // If geometries are re-ordered into a connecting network 
          //IGeometryCollection pXGeomColl = new PolylineClass(); 
          //pMAware = (IMAware)pXGeomColl; 
          //pMAware.MAware = true; 
          //pZAware = (IZAware)pXGeomColl; 
          //pZAware.ZAware = bHasZ; 
          //pXGeomColl = (IGeometryCollection)pPoly; 
          //for (int j = 0; j < pXGeomColl.GeometryCount; j++) 
          // pNewGeomColl.AddGeometry(pXGeomColl.Geometry[j]); 

          dMeasure += dLen; 

         } 

         pFeat.Shape = (IGeometry)pGeomColl; 
        } 
      } 

     } 
     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: measuresAdd_NonDuplicating; Line: " + iLineNo + "\n" + ex.ToString(); 
     } 


    } 
関連する問題