This document is archived and information here might be outdated.  Recommended version.


IMSegmentation.GetMsAtDistance Method (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference (Geometry)  

IMSegmentation.GetMsAtDistance Method

Returns M values at the distance along the geometry. An array of one or two Ms is returned. Two Ms can be returned if the given distance is exactly at the beginning or ending of a part.

[Visual Basic .NET]
Public Function GetMsAtDistance ( _
    ByVal distance As Double, _
    ByVal asRatio As Boolean _
) As Object
[C#]
public object GetMsAtDistance (
    double distance,
    bool asRatio
);
[C++]
HRESULT GetMsAtDistance(
  double distance,
  VARIANT_BOOL asRatio
);
[C++]

Parameters distance
distance is a parameter of type double asRatio
asRatio is a parameter of type bool

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.
[C#]

    public void GetMsAtPoint(IPolyline polyline, IPoint point)
    {
        /*
        This function does NOT assume that the point is on top of the PolyLine.
        If the point is equally distant from more that one location along the
        PolyLine, this function returns the all the M values.

        Note: You may notice some wierd behavior if the point falls on the
              end of a part as we will use distance in this function
        */
        IMAware mAware=polyline as IMAware;
        if (mAware.MAware)
        {
            IPoint outPoint=new PointClass();
            double distanceAlongCurve=0;
            double distanceFromCurve=0;
            bool isOnRightSide=false;
            ICurve curve=polyline as ICurve; curve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, outPoint, ref distanceAlongCurve, ref distanceFromCurve, ref isOnRightSide); IMSegmentation mSegmentation=curve as IMSegmentation; object mArrayObject=mSegmentation.GetMsAtDistance(distanceAlongCurve, false);
            double[] mArray=mArrayObject as double[];
            //print Ms
            for (int i=0; i < mArray.Length; i++)
            {
                System.Windows.Forms.MessageBox.Show(mArray[i].ToString());
            }
        }
    }

[Visual Basic .NET]

    Public Sub GetMsAtPoint(ByVal pPl As IPolyline, ByVal pPt As IPoint)
        '+++ This function does not assume that the point is on top of the PolyLine.

        '+++ If the point is equally distant from more that one location along the
        '+++ PolyLine, this function returns the all the M values.

        '+++ Here is how to find the M values returned by this function:
        '      Dim Ms
        '      Dim i As Long
        '      Ms=GetMsAtPoint(pPL, pPt)
        '      For i=LBound(Ms) To UBound(Ms)
        '        Debug.Print Ms(i)
        '      Next i

        '+++ Note: You may notice some wierd behavior if the point falls on the
        '+++       end of a part as we will use distance in this function

        Dim pMA As IMAware
        Dim pCurve As ICurve
        Dim pTmpPt As IPoint, dAlong As Double, dFrom As Double, bRight As Boolean
        Dim pMSeg As IMSegmentation
        Dim Ms As Double

        pMA=pPl
        If pMA.MAware Then
            pCurve=pPl
            pCurve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pPt, False, pTmpPt, dAlong, dFrom, bRight)
            pMSeg=pCurve
            Ms=pMSeg.GetMsAtDistance(dAlong, False)
        Else
            Err.Raise(vbObjectError + 11282000, "GetMsAtPoint", "Not M Aware")
        End If
    End Sub

See Also

IMSegmentation Interface