ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.Geometry Namespace / GeometryEngine Class / InsertMAtDistance Method
The multipart in which to set the M-value.
The M-value to set.
The distance along the multipart at which to set the M-value. If no point exists at the given distance, a new point is created with interpolated X and Y values.
Indicates whether the distance is interpreted as length or as a ratio along the multipart.
Indicates whether to create a new part at the split point (the point whose M-value is set) or not. MUST be false for polygons. For polylines, if true, the part on which the new split point falls is split into two parts with the newly added vertex serving as the end of the first part and the beginning of the second.
Indicates if a split happened at the split point. No split happens if createNewPart is false and the split point is at an existing vertex, or if createNewPart is true and a split part would be empty.
The index of the part that was modified. If createNewPart is true, partIndex refers to the added part and segmentIndex will be 0.
The index of the segment that was modified. The segment index is relative to the modified part.
Example

In This Topic
    InsertMAtDistance Method (GeometryEngine)
    In This Topic
    Sets the M-value at the given distance along the multipart.
    Syntax
    Public Function InsertMAtDistance( _
       ByVal multipart As Multipart, _
       ByVal mValue As Double, _
       ByVal distance As Double, _
       ByVal asRatioOrLength As AsRatioOrLength, _
       ByVal createNewPart As Boolean, _
       ByRef splitHappened As Boolean, _
       ByRef partIndex As Integer, _
       ByRef segmentIndex As Integer _
    ) As Multipart

    Parameters

    multipart
    The multipart in which to set the M-value.
    mValue
    The M-value to set.
    distance
    The distance along the multipart at which to set the M-value. If no point exists at the given distance, a new point is created with interpolated X and Y values.
    asRatioOrLength
    Indicates whether the distance is interpreted as length or as a ratio along the multipart.
    createNewPart
    Indicates whether to create a new part at the split point (the point whose M-value is set) or not. MUST be false for polygons. For polylines, if true, the part on which the new split point falls is split into two parts with the newly added vertex serving as the end of the first part and the beginning of the second.
    splitHappened
    Indicates if a split happened at the split point. No split happens if createNewPart is false and the split point is at an existing vertex, or if createNewPart is true and a split part would be empty.
    partIndex
    The index of the part that was modified. If createNewPart is true, partIndex refers to the added part and segmentIndex will be 0.
    segmentIndex
    The index of the segment that was modified. The segment index is relative to the modified part.

    Return Value

    A multipart with the M-value set.
    Exceptions
    ExceptionDescription
    The input multipart is null.
    createNewPart must be false for polygons.
    The input multipart is not M-Aware.
    Example
    Insert M value at the given distance - InsertMAtDistance
    string json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,-3],[-2000,-2000,-2],[-1000,-2000,null]]]}";
    Polyline polyline = PolylineBuilderEx.FromJson(json);
    bool splitHappened;
    int partIndex, segmentIndex;
    
    // A point already exists at the given distance
    double m = -1;
    double distance = 2000;
    bool createNewPart = false;
    Polyline outputPolyline = GeometryEngine.Instance.InsertMAtDistance(polyline, m, distance, AsRatioOrLength.AsLength, createNewPart, out splitHappened, out partIndex, out segmentIndex) as Polyline;
    
    // splitHappened = false, partIndex = 0, segmentIndex = 2
    // outputPolyline.Points[2].M = -1
    
    json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,-3],[-2000,-2000,-2],[-1000,-2000,-1]],[[0,0,0],[0,1000,0],[0,2000,2]]],\"spatialReference\":{\"wkid\":3857}}";
    polyline = PolylineBuilderEx.FromJson(json);
    
    // A point already exists at the given distance, but createNewPart = true
    m = 1;
    distance = 3000;
    createNewPart = true;
    outputPolyline = GeometryEngine.Instance.InsertMAtDistance(polyline, m, distance, AsRatioOrLength.AsLength, createNewPart, out splitHappened, out partIndex, out segmentIndex) as Polyline;
    string outputJson = outputPolyline.ToJson();
    
    // splitHappened = true, partIndex = 2, segmentIndex = 0
    // outputJson = {"hasM":true,"paths":[[[-3000,-2000,-3],[-2000,-2000,-2],[-1000,-2000,-1]],[[0,0,0],[0,1000,1]],[[0,1000,1],[0,2000,2]]]}}
    // A new part has been created and the M values for outputPolyline.Points[4] and outputPolyline.Points[5] have been modified
    
    // A point does not exist at the given distance
    m = 1;
    distance = 3500;
    createNewPart = false;
    outputPolyline = GeometryEngine.Instance.InsertMAtDistance(polyline, m, distance, AsRatioOrLength.AsLength, createNewPart, out splitHappened, out partIndex, out segmentIndex) as Polyline;
    outputJson = outputPolyline.ToJson();
    
    // splitHappened = true even though createNewPart = false because a new point was created
    // partIndex = 1, segmentIndex = 2
    // outputJson = {"hasM":true,"paths":[[[-3000,-2000,-3],[-2000,-2000,-2],[-1000,-2000,-1]],[[0,0,0],[0,1000,0],[0,1500,1],[0,2000,2]]]}
    // A new point has been inserted (0, 1500, 1) by interpolating the X and Y coordinates and M value set to the input M value.
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also