ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Core.Geometry Namespace / PolylineBuilderEx Class / FromJson Method
JSON string representation of a Polyline.
Example

In This Topic
    FromJson Method (PolylineBuilderEx)
    In This Topic
    Creates a new instance of a Polyline class from a JSON string representation.
    Syntax
    public static Polyline FromJson( 
       string jsonString
    )
    Public Shared Function FromJson( _
       ByVal jsonString As String _
    ) As Polyline

    Parameters

    jsonString
    JSON string representation of a Polyline.

    Return Value

    Exceptions
    ExceptionDescription
    The jsonString is empty or null.
    JSON string is invalid or does not represent a polyline string.
    Example
    Construct Multipatch via Extrusion of Polygon or Polyline
    {
      // build a polygon
      string json = "{\"hasZ\":true,\"rings\":[[[0,0,0],[0,1,0],[1,1,0],[1,0,0],[0,0,0]]],\"spatialReference\":{\"wkid\":4326}}";
      Polygon polygonNew = PolygonBuilderEx.FromJson(json);
    
      // extrude the polygon by an offset to create a multipatch
      multipatch = GeometryEngine.Instance.ConstructMultipatchExtrude(polygon, 2);
    
      // a different polygon
      json = "{\"hasZ\":true,\"rings\":[[[0,0,1],[0,1,2],[1,1,3],[1,0,4],[0,0,1]]],\"spatialReference\":{\"wkid\":4326}}";
      polygon = PolygonBuilderEx.FromJson(json);
    
      // extrude between z values to create a multipatch
      multipatch = GeometryEngine.Instance.ConstructMultipatchExtrudeFromToZ(polygon, -10, 20);
    
      // extrude along the axis defined by the coordinate to create a multipatch
      Coordinate3D coord = new Coordinate3D(10, 18, -10);
      multipatch = GeometryEngine.Instance.ConstructMultipatchExtrudeAlongVector3D(polygon, coord);
    
      // build a polyline
      json = "{\"hasZ\":true,\"paths\":[[[400,800,1000],[800,1400,1500],[1200,800,2000],[1800,1800,2500],[2200,800,3000]]],\"spatialReference\":{\"wkid\":3857}}";
      Polyline polylineNew = PolylineBuilderEx.FromJson(json);
    
      // extrude to a specific z value to create a multipatch
      multipatch = GeometryEngine.Instance.ConstructMultipatchExtrudeToZ(polyline, 500);
    
      Coordinate3D fromCoord = new Coordinate3D(50, 50, -500);
      Coordinate3D toCoord = new Coordinate3D(200, 50, 1000);
    
      // extrude between two coordinates to create a multipatch
      multipatch = GeometryEngine.Instance.ConstructMultipatchExtrudeAlongLine(polyline, fromCoord, toCoord);
    }
    Import and Export Geometries to JSON
    {
      // MapPoint
      string inputString =
        "{\"x\":1,\"y\":2,\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326}}";
      Geometry geometryFromJson = GeometryEngine.Instance.ImportFromJson(
        JsonImportFlags.JsonImportDefaults, inputString);
    
      MapPoint importPoint = geometryFromJson as MapPoint;
      // importPoint = 1, 2
      // importPoint.SpatialReference.WKid = 4326
    
      // use the MapPointBuilderEx convenience method
      MapPoint importPoint2 = MapPointBuilderEx.FromJson(inputString);
      // importPoint2 = 1, 2
      // impointPoint2.SpatialReference.Wkid = 4326
    
      string outputString = GeometryEngine.Instance.ExportToJson(
        JsonExportFlags.JsonExportDefaults, importPoint);
      // outputString =
      //   "{\"x\":1,\"y\":2,\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326}}"
    
      string outputString2 = importPoint.ToJson();
    
      inputString =
        "{\"spatialReference\":{\"wkid\":4326},\"z\":3,\"m\":4,\"x\":1,\"y\":2}";
      importPoint = GeometryEngine.Instance.ImportFromJson(
        JsonImportFlags.JsonImportDefaults, inputString) as MapPoint;
      // importPoint.HasM = true
      // importPoint.HasZ = true
      // importPoint.X = 1
      // importPoint.Y = 2
      // importPoint.M = 4
      // importPoint.Z = 3
    
      importPoint2 = MapPointBuilderEx.FromJson(inputString);
    
      // export to json - skip spatial reference
      outputString = GeometryEngine.Instance.ExportToJson(
                    JsonExportFlags.JsonExportSkipCRS, importPoint);
      // outputString = "{\"x\":1,\"y\":2,\"z\":3,\"m\":4}"
    
      // export from mappoint, skipping the sr - same as GeometryEngine.Instance.ExportToJson w JsonExportFlags.JsonExportSkipCRS
      outputString2 = importPoint.ToJson(true);
    
      //
      // Multipoint
      //
      List<Coordinate2D> coords = new List<Coordinate2D>()
    {
      new Coordinate2D(100, 200),
      new Coordinate2D(201, 300),
      new Coordinate2D(301, 400),
      new Coordinate2D(401, 500)
    };
    
      Multipoint multipointFromCoords = MultipointBuilderEx.CreateMultipoint(
        coords, SpatialReferences.WebMercator);
    
      inputString =
        "{\"points\":[[100,200],[201,300],[301,400],[401,500]],\"spatialReference\":{\"wkid\":3857}}";
      Multipoint importMultipoint =
        GeometryEngine.Instance.ImportFromJson(
               JsonImportFlags.JsonImportDefaults, inputString) as Multipoint;
      // importMultipoint.IsEqual(multipoint) = true
    
      ReadOnlyPointCollection pointsFromMultipoint = importMultipoint.Points;
      // points.Count = 4
      // points[0] = 100, 200
      // points[1] = 201, 300
      // points[2] = 301, 400
      // points[3] = 401, 500
    
      // use the MultipointbuilderEx convenience method
      Multipoint importMultipoint2 = MultipointBuilderEx.FromJson(inputString);
      // importMultipoint2.IsEqual(multipoint) = true
    
      // export to json
      outputString = GeometryEngine.Instance.ExportToJson(
                      JsonExportFlags.JsonExportDefaults, multipointFromCoords);
      // outputString = inputString
    
      // or use the multipoint itself
      outputString2 = multipointFromCoords.ToJson();
    
      //
      // Polyline
      //
      Polyline polylineFromCoords = PolylineBuilderEx.CreatePolyline(
                               coords, SpatialReferences.WebMercator);
    
      // export without the spatial reference
      outputString = GeometryEngine.Instance.ExportToJson(
                              JsonExportFlags.JsonExportSkipCRS, polylineFromCoords);
      // import
      geometry = GeometryEngine.Instance.ImportFromJson(
                   JsonImportFlags.JsonImportDefaults, outputString);
      Polyline importPolyline = geometryFromJson as Polyline;
      // importPolyline.SpatialReference = null
    
    
      pointsFromMultipoint = importPolyline.Points;
      // points.Count = 4
      // points[0] = 100, 200
      // points[1] = 201, 300
      // points[2] = 301, 400
      // points[3] = 401, 500
    
      // use the polylineBuilderEx convenience method
      Polyline importPolyline2 = PolylineBuilderEx.FromJson(outputString);
      // importPolyline2 = importPolyline
    
      outputString2 = importPolyline2.ToJson();
      // outputString2 = outputString
    
      //
      // Polygon
      //
      Polygon polygonFromCoords = PolygonBuilderEx.CreatePolygon(
                                    coords, SpatialReferences.WebMercator);
    
      // export without the spatial reference
      outputString = GeometryEngine.Instance.ExportToJson(
                                JsonExportFlags.JsonExportSkipCRS, polygonFromCoords);
      // import
      geometryFromJson = GeometryEngine.Instance.ImportFromJson(
                           JsonImportFlags.JsonImportDefaults, outputString);
    
      Polygon importPolygon = geometry as Polygon;
      // importPolygon.SpatialReference = null
      pointsFromMultipoint = importPolygon.Points;
      // points.Count = 5
    
      // polygonBuilderEx convenience method
      Polygon importPolyon2 = PolygonBuilderEx.FromJson(outputString);
      // importPolygon2 = importPolygon
    
      // export from the polygon
      outputString2 = importPolyon2.ToJson(true);
    
      // Empty polygon
      polygon = PolygonBuilderEx.CreatePolygon(SpatialReferences.WebMercator);
      outputString = GeometryEngine.Instance.ExportToJson(
                                     JsonExportFlags.JsonExportDefaults, polygon);
      importPolygon = GeometryEngine.Instance.ImportFromJson(
                          JsonImportFlags.JsonImportDefaults, outputString) as Polygon;
    
      // importPolygon.IsEmpty = true
      // importPolygon.SpatialReference.Wkid = 3857
    }
    Get the minimum and maximum M values - GetMinMaxM
    {
      string json = "{\"hasM\":true,\"rings\":[[[-3000,-2000,10],[-2000,-2000,15],[-1000,-2000,20],[0,-2000,0],[1000,-2000,-20],[2000,-2000,-30],[3000,-2000,10],[4000,-2000,5]]],\"spatialReference\":{\"wkid\":3857}}";
      polygon = PolygonBuilderEx.FromJson(json);
    
      GeometryEngine.Instance.GetMinMaxM(polygon, out double minM, out double maxM);
      // minM = -30
      // maxM = 20
    
      json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,10],[-2000,-2000,null],[-1000,-2000,null]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      GeometryEngine.Instance.GetMinMaxM(polyline, out minM, out maxM);
      // minM = 10
      // maxM = 10
    
      json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,null],[-2000,-2000,null],[-1000,-2000,null]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      GeometryEngine.Instance.GetMinMaxM(polyline, out minM, out maxM);
      // minM = double.Nan
      // maxM = double.Nan
    }
    Determine whether Ms are monotonic and whether ascending or descending - GetMMonotonic
    {
      string json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,10],[-2000,-2000,15],[-1000,-2000,20]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      MonotonicType monotonic = GeometryEngine.Instance.GetMMonotonic(polyline);
      // monotonic = Monotonic.Ascending
    
      json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,10],[-2000,-2000,5],[-1000,-2000,0]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      monotonic = GeometryEngine.Instance.GetMMonotonic(polyline);
      // monotonic = Monotonic.Descending
    
      json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,10],[-2000,-2000,15],[-1000,-2000,0]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      monotonic = GeometryEngine.Instance.GetMMonotonic(polyline);
      // monotonic = Monotonic.NotMonotonic
    }
    Get a multipoint corresponding to the locations where the specified M values occur along the geometry - GetPointsAtM
    {
      string json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,10],[-2000,-2000,15],[-1000,-2000,20],[0,-2000,0],[1000,-2000,20],[2000,-2000,30],[3000,-2000,10],[4000,-2000,5]]],\"spatialReference\":{\"wkid\":3857}}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      Multipoint multipoint = GeometryEngine.Instance.GetPointsAtM(polyline, 10, 500);
      // multiPoint.PointCount = 4
      // multipoint.Points[0]  X= -3000, Y= -2500  M= 10
      // multipoint.Points[1]  X= -500, Y= -2500  M= 10
      // multipoint.Points[2]  X= 500, Y= -2500  M= 10
      // multipoint.Points[3]  X= 3000, Y= -2500  M= 10
    }
    Get a polyline corresponding to the subcurves between specified M values - GetSubCurveBetweenMs
    {
      string json = "{\"hasM\":true,\"paths\":[[[-2000,0,1],[-1000,1000,2],[-1000,0,3],[1000,1000,4],[2000,1000,5],[2000,2000,6],[3000,2000,7],[4000,0,8]]],\"spatialReference\":{\"wkid\":3857}}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      Polyline subCurve = GeometryEngine.Instance.GetSubCurveBetweenMs(polyline, 2, 6);
      // subCurve.PointCount = 5
      // subCurve.Points[0]  X= --1000, Y= 1000 M= 2
      // subCurve.Points[1]  X= --1000, Y= 0  M= 3
      // subCurve.Points[2]  X= 1000, Y= 1000  M= 4
      // subCurve.Points[3]  X= 2000, Y= -1000  M= 5
      // subCurve.Points[4]  X= 2000, Y= -2000  M= 6
    
      subCurve = GeometryEngine.Instance.GetSubCurveBetweenMs(polyline, double.NaN, 5);
      // subCurve.PointCount = 0
      // subCurve.IsEmpty = true
    }
    Get the M values at the specified distance along the multipart
    {
      string json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,-3],[-2000,-2000,-2]],[[-2000,-2000,1],[-2000,1000,2]]],\"spatialReference\":{\"wkid\":3857}}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      // polyline has 2 parts
    
      GeometryEngine.Instance.GetMsAtDistance(polyline, 0, AsRatioOrLength.AsLength, out double m1, out double m2);
      // m1 = -3
      // m2 = NaN
    
      GeometryEngine.Instance.GetMsAtDistance(polyline, 500, AsRatioOrLength.AsLength, out m1, out m2);
      // m1 = -2.5
      // m2 = NaN
    
      GeometryEngine.Instance.GetMsAtDistance(polyline, 1000, AsRatioOrLength.AsLength, out m1, out m2);
      // m1 = -2
      // m2 = 1     // m2 has a value because distance 1000 is at the end of the first part, beginning of the second part
    }
    Insert M value at the given distance - InsertMAtDistance
    {
      string json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,-3],[-2000,-2000,-2],[-1000,-2000,null]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      // 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 bool splitHappened, out int partIndex, out int 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.
    }
    Calibrate M values using M values from input points - CalibrateByMs
    {
      string json = "{\"hasM\":true,\"paths\":[[[0,0,-1],[1,0,0],[1,1,1],[1,2,2],[3,1,3],[5,3,4],[9,5,5],[7,6,6]]],\"spatialReference\":{\"wkid\":4326}}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      // Interpolate using points (0, 0, 17), (1, 0, 42), (7, 6, 18)
      List<MapPoint> updatePoints = new(3);
      MapPointBuilderEx builder = new(0, 0)
      {
        M = 17
      };
      updatePoints.Add(builder.ToGeometry() as MapPoint);
    
      builder.X = 1;
      builder.M = 42;
      updatePoints.Add(builder.ToGeometry() as MapPoint);
    
      builder.X = 7;
      builder.Y = 6;
      builder.M = 18;
      updatePoints.Add(builder.ToGeometry() as MapPoint);
    
      // Calibrate all the points in the polyline
      double cutOffDistance = polyline.Length;
    
      Polyline updatedPolyline = GeometryEngine.Instance.CalibrateByMs(polyline, updatePoints, UpdateMMethod.Interpolate, cutOffDistance) as Polyline;
      // The points in the updated polyline are
      // (0, 0, 17 ), ( 1, 0, 42 ), ( 1, 1, 38 ), ( 1, 2, 34 ), ( 3, 1, 30 ), ( 5, 3, 26 ), ( 9, 5, 22 ), ( 7, 6, 18 )
    
      // ExtrapolateBefore using points (1, 2, 42), (9, 5, 18)
      builder.X = 1;
      builder.Y = 2;
      builder.M = 42;
      updatePoints[0] = builder.ToGeometry() as MapPoint;
    
      builder.X = 9;
      builder.Y = 5;
      builder.M = 18;
      updatePoints[1] = builder.ToGeometry() as MapPoint;
    
      updatePoints.RemoveAt(2);
    
      updatedPolyline = GeometryEngine.Instance.CalibrateByMs(polyline, updatePoints, UpdateMMethod.ExtrapolateBefore, cutOffDistance) as Polyline;
      // The points in the updated polyline are
      // ( 0, 0, 66 ), ( 1, 0, 58 ), ( 1, 1, 50 ), ( 1, 2, 42 ), ( 3, 1, 3 ), ( 5, 3, 4 ), ( 9, 5, 18 ), ( 7, 6, 6 )
    
      // ExtrapolateAfter using points (0, 0, 17), (1, 2, 42)
      builder.X = 0;
      builder.Y = 0;
      builder.M = 17;
      updatePoints.Insert(0, builder.ToGeometry() as MapPoint);
    
      updatePoints.RemoveAt(2);
    
      updatedPolyline = GeometryEngine.Instance.CalibrateByMs(polyline, updatePoints, UpdateMMethod.ExtrapolateAfter, cutOffDistance) as Polyline;
      // The points in the updated polyline are
      // ( 0, 0, 17 ), ( 1, 0, 0 ), ( 1, 1, 1 ), ( 1, 2, 42 ), ( 3, 1, 50.333333333333333 ), ( 5, 3, 58.666666666666671 ), ( 9, 5, 67 ), ( 7, 6, 75.333333333333343 )
    
      // ExtrapolateAfter and Interpolate using points (0, 0, 17), (1, 2, 42)
      updatedPolyline = GeometryEngine.Instance.CalibrateByMs(polyline, updatePoints, UpdateMMethod.ExtrapolateAfter | UpdateMMethod.Interpolate, cutOffDistance) as Polyline;
      // The points in the updated polyline are
      // (0,0,17),(1,0,25.333333333333336),(1,1,33.666666666666671),(1,2,42),(3,1,50.333333333333336),(5,3,58.666666666666671),(9,5,67),(7,6,75.333333333333343)
    }
    Set all the M-values to NaN - DropMs
    {
      string json = "{\"hasM\":true,\"paths\":[[[-4,2,1],[-4,5,2],[-2,5,3],[-2,7,4],[2,7,5]],[[4,1,-1],[2,1,-2],[2,-2,-3],[-3,-2,-4],[-3,0,-5]]]}}";
      polyline = PolylineBuilderEx.FromJson(json);
      Polyline outputPolyline = GeometryEngine.Instance.DropMs(polyline) as Polyline;
      // outputPolyline.HasM = true. Every M-value is NaN.
      // outputPolyline.ToJson() = {"hasM":true,"paths":[[[-4,2,null],[-4,5,null],[-2,5,null],[-2,7,null],[2,7,null]],[[4,1,-null],[2,1,null],[2,-2,null],[-3,-2,null],[-3,0,null]]]}
    }
    Extrapolate M-values based on a range defined by part and vertex indices - ExtrapolateMs
    {
      string json = "{\"hasM\":true,\"paths\":[[[2,0,50],[2,1,40],[3,1,30],[3,5,60],[7,5,12],[7,1,20],[9,1,28],[9,3,10]]],\"spatialReference\":{\"wkid\":4326}}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      // Extrapolate M-values from part 0, point 3 to part 0, point 5
      Polyline outPolyline = GeometryEngine.Instance.ExtrapolateMs(polyline, ExtrapolateMMethod.ExtrapolateBefore, 0, 3, 0, 5) as Polyline;
      // The points in outPolyline are (x, y, m):
      // ( 2, 0, 90 ), ( 2, 1, 85 ), ( 3, 1, 80 ), ( 3, 5, 60 ), ( 7, 5, 12 ), ( 7, 1, 20 ), ( 9, 1, 28 ), ( 9, 3, 10 )
    
      json = "{\"hasM\":true,\"paths\":[[[2,0,50],[2,1,40],[3,1,30],[3,5,60],[7,5,12],[7,1,20],[9,1,28],[9,3,10]],[[5,-4,-10],[5,-2,-40],[10,-2,-60],[10,-6,-50],[8,-6,-40],[8,-4,-80],[6,-4,-90]]],\"spatialReference\":{\"wkid\":4326}}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      // Extrapolate M-values from part 0, point 5 to part1, point 1
      outPolyline = GeometryEngine.Instance.ExtrapolateMs(polyline, ExtrapolateMMethod.ExtrapolateAfter, 0, 5, 1, 1) as Polyline;
      // The points in part 0 of outPolyline don't change. They are (x, y, m):
      // ( 2, 0, 50 ), ( 2, 1, 40 ), ( 3, 1, 30 ), ( 3, 5, 60 ), ( 7, 5, 12 ), ( 7, 1, 20 ), ( 9, 1, 28 ), ( 9, 3, 10 )
    
      // The points in part 1 of outPolyline are (x, y, m):
      // ( 5, -4, -10 ), ( 5, -2, -40 ), ( 10, -2, -90 ), ( 10, -6, -130 ), ( 8, -6, -150 ), ( 8, -4, -170 ), ( 6, -4, -190 )
    }
    Get a list of distances along the multipart at points with the specified M-value - GetDistancesAtM
    {
      string json = "{\"hasM\":true,\"paths\":[[[-4,1,1],[-4,3,2],[-2,3,3],[-2,5,1]],[[3,5,1],[3,2,2],[6,2,3],[6,-2,2]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      // Get the distances as length measured from the start of the multipart
      IReadOnlyList<double> distances = GeometryEngine.Instance.GetDistancesAtM(polyline, AsRatioOrLength.AsLength, 2);
      // distances.Count = 4
      // distances[0] = 2 measured to the point (-4, 3, 2)
      // distances[1] = 5 measured to the point (-2, 4, 2). Its M-value is interpolated from the segment (-2, 3, 3) -> (-2, 5, 1)
      // distances[2] = 9 measured to the point (3, 2, 2)
      // distances[3] = 16 measured to the point (6, -2, 2)
    
      // Get the distances as a ratio of the distance measured from the start of the multipart and the total length of the multipart
      distances = GeometryEngine.Instance.GetDistancesAtM(polyline, AsRatioOrLength.AsRatio, 2);
      // distances.Count = 4;
      // distances are { 0.125, 0.3125, 0.5625, 1 }
    }
    Get a polyline and other details corresponding to the subcurves between the specified M-values GetSubCurveBetweenMsEx
    {
      string json = "{\"hasM\":true,\"paths\":[[[-2000,0,1],[-1000,1000,-1],[-1000,0,3],[1000,1000,4],[2000,1000,5],[2000,2000,6],[3000,2000,7],[4000,0,8]]],\"spatialReference\":{\"wkid\":3857}}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      // Get the subcurve between M-values 2 and 6
      Polyline subCurve = GeometryEngine.Instance.GetSubCurveBetweenMsEx(polyline, 2, 6, out MSubCurveRelation fromDetail, out MSubCurveRelation toDetail);
      // The subcurve has one part and five points. The subcurve points are (x, y, m):
      // (-1000, 250, 2), (-1000, 0, 3), (1000, 1000, 4), (2000, 1000, 5), (2000, 2000, 6)
      // fromDetail = toDetail = MSubCurveRelation.MBetweenMinMax
    
      // Get the subcurve between M-values -2 and 3.5
      subCurve = GeometryEngine.Instance.GetSubCurveBetweenMsEx(polyline, -2, 3.5, out fromDetail, out toDetail);
      // The subcurve has two parts and five points.
      // The subcurve points in part 0 are (x, y, m): (-1000, 1000, -1), (-2000, 0, 1)
      // The subcurve points in part 1 are (x, y, m): (-1000, 1000, -1), (-1000, 0, 3), (0, 500, 3.5)
      // fromDetail = MSubCurveRelation.MBelowMin, toDetail = MSubCurveRelation.MBetweenMinMax
    }
    Get a combination of monotonicity values that describes all trends in the M-values over the length of the multipart - GetMMonotonicity
    {
      string json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,10],[-2000,-2000,5],[-1000,-2000,0]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
      Monotonicity monotonicity = GeometryEngine.Instance.GetMMonotonicity(polyline);
      // monotonicity = Monotonicity.ValueDecreases
    
      // Create a polygon from the polyline
      polygon = PolygonBuilderEx.CreatePolygon(polyline);
      monotonicity = GeometryEngine.Instance.GetMMonotonicity(polygon);
      // monotonicity = ValueIncreases | ValueDecreases
    
      json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,10],[-2000,-2000,10],[-1000,-2000,10]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
      monotonicity = GeometryEngine.Instance.GetMMonotonicity(polygon);
      // monotonicity = Monotonicity.ValueLevel
    
      json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,null],[-2000,-2000,5],[-1000,-2000,10]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
      monotonicity = GeometryEngine.Instance.GetMMonotonicity(polyline);
      // monotonicity = ValueIncreases | ValueEmpty
    
      // Create an empty polyline
      Polyline emptyPolyline = PolylineBuilderEx.FromJson("{\"hasM\":true,\"paths\":[]}");
      monotonicity = GeometryEngine.Instance.GetMMonotonicity(emptyPolyline);
      // monotonicity = Monotonicity.None
    }
    Generates M-values by linear interpolation over a range of points - InterpolateMsBetween
    {
      string json = "{\"hasM\":true,\"paths\":[[[0,0,-1],[1,0,0],[1,1,1],[1,2,2],[3,1,3],[5,3,4],[9,5,5],[7,6,6]]],\"spatialReference\":{\"wkid\":4326}}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      // Interpolate between points 2 and 6
      Polyline outPolyline = GeometryEngine.Instance.InterpolateMsBetween(polyline, 0, 2, 0, 6) as Polyline;
      // The points of the output polyline are
      // (0, 0, -1), (1, 0, 0), (1, 1, 1), (1, 2, 1.3796279833912741), (3, 1, 2.2285019604153242), (5, 3, 3.3022520459518998), (9, 5, 5), (7, 6, 6)
    }
    Reorient a polyline such that all M-values are non-decreasing, if possible - OrientByMs
    {
      string json = "{\"hasM\":true,\"paths\":[[[0,0,1],[0,1,0],[1,1,-1],[1,0,-2]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      Polyline outputPolyline = GeometryEngine.Instance.OrientByMs(polyline);
      // The points of outputPolyline are (x, y, m): (1, 0, -2), (1, 1, -1), (0, 1, 0), (0, 0, 1)
    
      // M-values of second part is not monotonic, so it won't change. The first part will change.
      json = "{\"hasM\":true,\"paths\":[[[0,0,1],[0,1,0],[1,1,-1],[1,0,-2]],[[5,4,6],[6,4,5],[8,6,7]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
      outputPolyline = GeometryEngine.Instance.OrientByMs(polyline);
      // The points of part 0 of outputPolyline are (x, y, m): (1, 0, -2), (1, 1, -1), (0, 1, 0), (0, 0, 1)
      // The points of part 1 of outputPolyline are (x, y, m): (5, 4, 6), (6, 4, 5), (8, 6, 7)
    }
    Get the first and last defined M-values in a polyline - QueryFirstLastM
    {
      string json = "{\"hasM\":true,\"paths\":[[[5,4,6],[6,4,5],[8,6,7]],[[0,0,1],[0,1,0],[1,1,-1],[1,0,-2]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      GeometryEngine.Instance.QueryFirstLastM(polyline, out double firstM, out double lastM);
      // firstM = 6, lastM = -2
    
      json = "{\"hasM\":true,\"paths\":[[[5,4,null],[6,4,5],[8,6,7]],[[0,0,1],[0,1,0],[1,1,-1],[1,0,null]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      GeometryEngine.Instance.QueryFirstLastM(polyline, out firstM, out lastM);
      // firstM = 5, lastM = -1
    
      json = "{\"hasM\":true,\"paths\":[[[5,4,null],[6,4,null],[8,6,null]],[[0,0,null],[0,1,null],[1,1,null],[1,0,null]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      GeometryEngine.Instance.QueryFirstLastM(polyline, out firstM, out lastM);
      // firstM and lastM are NaN
    
      json = "{\"hasM\":true,\"paths\":[]}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      GeometryEngine.Instance.QueryFirstLastM(polyline, out firstM, out lastM);
      // firstM and lastM are NaN
    }
    Reverse the order of the M-values along a multipart - ReverseMs
    {
      string json = "{\"hasM\":true,\"paths\":[[[5,4,6],[6,4,5],[8,6,7]]],\"spatialReference\":{\"wkid\":4326}}";
      polyline = PolylineBuilderEx.FromJson(json);
      Polyline outputPolyline = GeometryEngine.Instance.ReverseMs(polyline) as Polyline;
      // The xy-coordinates in outputPolyline are not changed.
      // The M-values in outputPolyline are: { 7, 5, 6 }
    }
    Set Ms at the beginning and end of the geometry and interpolate M-values between the two values - SetAndInterpolateMsBetween
    {
      string json = "{\"hasM\":true,\"paths\":[[[-3000,-2000],[-2000,-2000],[-1000,-2000],[0,-2000],[1000,-2000],[2000,-2000],[3000,-2000],[4000,-2000]]],\"spatialReference\":{\"wkid\":3857}}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      Polyline outPolyline = GeometryEngine.Instance.SetAndInterpolateMsBetween(polyline, 100, 800) as Polyline;
      ReadOnlyPointCollection outPoints = outPolyline.Points;
      // outPoints M values are { 100, 200, 300, 400, 500, 600, 700, 800 };
    }
    Set the M-values to the cumulative length of the start of the multipart - SetMsAtDistance
    {
      string json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,1],[-2000,-2000,2],[-1000,-2000,3],[0,-2000,null],[1000,-2000,4],[2000,-2000,5],[3000,-2000,10],[4000,-2000,11],[5000,-2000,12],[6000,-2000,13],[7000,-2000,14]]],\"spatialReference\":{\"wkid\":3857}}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      Polyline outPolyline = GeometryEngine.Instance.SetMsAsDistance(polyline, AsRatioOrLength.AsLength) as Polyline;
      // The xy-coordinates don't change.
      // The M-values of the vertices in outPolyline are (x, y, m):
      // { 0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000 }
    
      json = "{\"hasM\":true,\"rings\":[[[0,0],[0,3000],[4000,3000],[4000,0],[0,0]]],\"spatialReference\":{\"wkid\":3857}}";
      polygon = PolygonBuilderEx.FromJson(json);
    
      Polygon outPolygon = GeometryEngine.Instance.SetMsAsDistance(polygon, AsRatioOrLength.AsLength) as Polygon;
      // The M-values of the vertices in outPolygon are (x, y, m): { 0, 3000, 7000, 10000, 14000 };
    }
    Set the M-values of the vertices as scaled and offset distances measured along a polyline - SetMsAsDistance
    {
      string json = "{\"hasM\":true,\"paths\":[[[0,0,1],[3,0,2],[3,6,3],[7,6,4]]],\"spatialReference\":{\"wkid\":4326}}";
      polyline = PolylineBuilderEx.FromJson(json);
      Coordinate2D origin = new(0, 0);
    
      Polyline outputPolyline = GeometryEngine.Instance.SetMsAsDistance(polyline, origin, 0.5, 1, true) as Polyline;
      // The xy-coordinates of the polyline don't change.
      // The points of outputPolyline are (x, y, m):
      // (0, 0, 1), (3, 0, 2.5), (3, 6, 5.5), (7, 6, 7.5)
    
      // Measurements will start at the end of the polyline, point (7, 6)
      origin = new Coordinate2D(4, 6);
    
      outputPolyline = GeometryEngine.Instance.SetMsAsDistance(polyline, origin, 0.5, 1, true) as Polyline;
      // The points of outputPolyline are (x, y, m):
      // (0, 0, 7.5), (3, 0, 6), (3, 6, 3), (7, 6, 1)
    }
    Snap the M-values to the M-precision of the spatial reference - SnapMsToSpatialReference
    {
      SpatialReference sr = SpatialReferences.WebMercator;  // precision = 1 / MScale = 0.0001
    
      // MapPoint
      MapPointBuilderEx pointBuilder = new(3, 4, sr)
      {
        M = 5.00006
      };
      MapPoint point = pointBuilder.ToGeometry();
      MapPoint outputPoint = GeometryEngine.Instance.SnapMsToSpatialReference(point) as MapPoint;
      // outputPoint.M = 5.0001
    
      // Multipoint
      MapPointBuilderEx mapPointBuilderEx = new(-3, -4, sr)
      {
        M = -5.000007
      };
      pointBuilder = mapPointBuilderEx;
      MapPoint point2 = pointBuilder.ToGeometry();
      Multipoint multipoint = MultipointBuilderEx.CreateMultipoint([point, point2], AttributeFlags.HasM, sr);
      Multipoint outputMultipoint = GeometryEngine.Instance.SnapMsToSpatialReference(multipoint) as Multipoint;
      // outputMultipoint.Points[0].M = 5.0001, outputMultipoint.Points[1].M = -5
    
      // Polyline
      string json = "{\"hasM\":true,\"paths\":[[[3,2,10.00065],[3,4,15.000325],[5,4,20],[5,2,15.000325],[3,2,10.00065]]],\"spatialReference\":{\"wkid\":3857}}";
      polyline = PolylineBuilderEx.FromJson(json);
      Polyline outputPolyline = GeometryEngine.Instance.SnapMsToSpatialReference(polyline) as Polyline;
      // The M-values for the vertices in outputPolyline are { 10.0007, 15.0003, 20, 15.0003, 10.0007 }
    }
    Set the M-values of the vertices as scaled and offset M distances measured along a polyline - UpdateAllMsByMs
    {
      string json = "{\"hasM\":true,\"paths\":[[[-8,2,1],[-8,5,8],[-5,5,0],[-5,7,12]],[[3,2,20],[7,2,30],[7,4,10],[13,4,5]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
      Coordinate2D origin = new(-5, 6);
    
      Polyline outputPolyline = GeometryEngine.Instance.UpdateAllMsByMs(polyline, origin, 1, 0, true);
      // The xy-coordinates don't change.
      // The M-values of the vertices in part 0 of outputPolyline are { 27, 20, 12, 0 }
      // The M-values of the vertices in part 1 of outputPolyline are { 27, 37, 57, 62 }
    
      outputPolyline = GeometryEngine.Instance.UpdateAllMsByMs(polyline, origin, 2, 4, true);
      // The M-values of the vertices in part 0 of outputPolyline are { 58, 44, 28, 4 }
      // The M-values of the vertices in part 1 of outputPolyline are { 58, 78, 118, 128 }
    }
    Update M-values along the shortest path between the specified vertices - UpdateMsByDistance
    {
      string json = "{\"hasM\":true,\"paths\":[[[-8,2,1],[-8,5,8],[-5,5,0],[-5,7,12]]],\"spatialReference\":{\"wkid\":4326}}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      Polyline outputPolyline = GeometryEngine.Instance.UpdateMsByDistance(polyline, 0, 0, 0, 2, 10, 20, UpdateMMethod.Interpolate, true);
      // The xy-coordinates don't change.
      // The M-values of the vertices in outputPolyline are { 10, 15, 20, 12 }
    
      json = "{\"hasM\":true,\"paths\":[[[-8,2,1],[-8,5,8],[-5,5,0],[-5,7,12]],[[3,2,20],[7,2,30],[7,4,10],[13,4,5]]]}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      outputPolyline = GeometryEngine.Instance.UpdateMsByDistance(polyline, 0, 2, 1, 1, 10, 20, UpdateMMethod.ExtrapolateBefore, true);
      // The M-values of the vertices in part 0 of outputPolyline are { -5, 2.5, 10, 5 }
      // The M-values of the vertices in part 1 of outputPolyline are { 20, 20, 10, 5 }
    }
    Update M-values with the interpolation ratio determined by existing M-values and the input M-values - UpdateMsByMs
    {
      string json = "{\"hasM\":true,\"paths\":[[[-8,2,1],[-8,5,8],[-5,5,0],[-5,7,12]]],\"spatialReference\":{\"wkid\":4326}}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      Polyline outputPolyline = GeometryEngine.Instance.UpdateMsByMs(polyline, 0, 1, 0, 3, -2, 14, UpdateMMethod.Interpolate);
      // The xy-coordinates don't change.
      // The M-values of the vertices in outputPolyline are (x, y, m): { 1, -2, 30, 14 }
    }
    QueryNormal
    {
      string json = "{\"curvePaths\":[[[-13046586.8335,4036570.6796000004]," +
                    "{\"c\":[[-13046645.107099999,4037152.5873000026]," +
                    "[-13046132.776277589,4036932.1325614937]]}]],\"spatialReference\":{\"wkid\":3857}}";
      polyline = PolylineBuilderEx.FromJson(json);
    
      EllipticArcSegment arc = polyline.Parts[0][0] as EllipticArcSegment;
    
      // No extension, distanceAlongCurve = 0.5
    
      // use the polyline
      Polyline poly_normal = GeometryEngine.Instance.QueryNormal(polyline, SegmentExtensionType.NoExtension, 0.5, AsRatioOrLength.AsRatio, 1000);
      // or a segment
      LineSegment seg_normal = GeometryEngine.Instance.QueryNormal(arc, SegmentExtensionType.NoExtension, 0.5, AsRatioOrLength.AsRatio, 1000);
    
      // TangentAtFrom, distanceAlongCurve = -1.2
      poly_normal = GeometryEngine.Instance.QueryNormal(polyline, SegmentExtensionType.ExtendTangentAtFrom, -1.2, AsRatioOrLength.AsRatio, 1000);
      seg_normal = GeometryEngine.Instance.QueryNormal(arc, SegmentExtensionType.ExtendTangentAtFrom, -1.2, AsRatioOrLength.AsRatio, 1000);
    
      // TangentAtTo (ignored because distanceAlongCurve < 0), distanceAlongCurve = -1.2
      poly_normal = GeometryEngine.Instance.QueryNormal(polyline, SegmentExtensionType.ExtendTangentAtTo, -1.2, AsRatioOrLength.AsRatio, 1000);
      seg_normal = GeometryEngine.Instance.QueryNormal(arc, SegmentExtensionType.ExtendTangentAtTo, -1.2, AsRatioOrLength.AsRatio, 1000);
    
      // TangentAtTo, distanceAlongCurve = 1.2
      poly_normal = GeometryEngine.Instance.QueryNormal(polyline, SegmentExtensionType.ExtendTangentAtTo, 1.2, AsRatioOrLength.AsRatio, 1000);
      seg_normal = GeometryEngine.Instance.QueryNormal(arc, SegmentExtensionType.ExtendTangentAtTo, 1.2, AsRatioOrLength.AsRatio, 1000);
    
      // TangentAtFrom (ignored because distanceAlongCurve > 0), distanceAlongCurve = 1.2
      poly_normal = GeometryEngine.Instance.QueryNormal(polyline, SegmentExtensionType.ExtendTangentAtFrom, 1.2, AsRatioOrLength.AsRatio, 1000);
      seg_normal = GeometryEngine.Instance.QueryNormal(arc, SegmentExtensionType.ExtendTangentAtFrom, 1.2, AsRatioOrLength.AsRatio, 1000);
    
      // EmbeddedAtTo, distanceAlongCurve = 1.2
      poly_normal = GeometryEngine.Instance.QueryNormal(polyline, SegmentExtensionType.ExtendEmbeddedAtTo, 1.2, AsRatioOrLength.AsRatio, 1000);
      seg_normal = GeometryEngine.Instance.QueryNormal(arc, SegmentExtensionType.ExtendEmbeddedAtTo, 1.2, AsRatioOrLength.AsRatio, 1000);
    
      // EmbeddedAtFrom, distanceAlongCurve = -0.2
      poly_normal = GeometryEngine.Instance.QueryNormal(polyline, SegmentExtensionType.ExtendEmbeddedAtFrom, -0.2, AsRatioOrLength.AsRatio, 1000);
      seg_normal = GeometryEngine.Instance.QueryNormal(arc, SegmentExtensionType.ExtendEmbeddedAtFrom, -0.2, AsRatioOrLength.AsRatio, 1000);
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also