0

我目前正在线性参考一组道路。使用 IMSegmatation2.SetMsAsDistance2 对于单部分多段线效果很好,但对于多部分多段线,我想将 M 值设置为沿多段线到点的长度,而不是点和多段线起点之间的最短距离。SetMsAsDistance2 函数将平行线上的度量设置为相等。我希望他们与众不同。

除了为每个折线顶点设置 M 值之外,有人知道将 M 设置为沿折线的长度的方法吗?

4

1 回答 1

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


    }
于 2017-11-09T01:16:29.370 回答