ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Core.Geometry Namespace / PolylineBuilderEx Class / CreatePolyline Method / CreatePolyline(IEnumerable<Coordinate2D>,SpatialReference) Method
Coordinates to create the polyline. Line segments are created from the coordinates.
(Optional) The SpatialReference. The default value is null.
Example

In This Topic
    CreatePolyline(IEnumerable<Coordinate2D>,SpatialReference) Method
    In This Topic
    Convenience method to create a new instance of the Polyline class.
    Syntax
    Public Overloads Shared Function CreatePolyline( _
       ByVal coordinates As IEnumerable(Of Coordinate2D), _
       Optional ByVal spatialReference As SpatialReference _
    ) As Polyline

    Parameters

    coordinates
    Coordinates to create the polyline. Line segments are created from the coordinates.
    spatialReference
    (Optional) The SpatialReference. The default value is null.

    Return Value

    Exceptions
    ExceptionDescription
    coordinates is null.
    Example
    Construct a Polyline - from a Cubic Bezier
    {
      polyline = PolylineBuilderEx.CreatePolyline(bezierSegment);
    }
    Construct GeometryBag
    {
      MapPoint point = MapPointBuilderEx.CreateMapPoint(1, 2, SpatialReferences.WebMercator);
    
      List<Coordinate2D> coords2DToUse = new List<Coordinate2D>()
      {
        new Coordinate2D(0, 0),
        new Coordinate2D(0, 1),
        new Coordinate2D(1, 1),
        new Coordinate2D(1, 0)
      };
    
      Multipoint multipointNew = MultipointBuilderEx.CreateMultipoint(coords2DToUse, SpatialReferences.WGS84);
      Polyline polylineNew = PolylineBuilderEx.CreatePolyline(coords2DToUse, SpatialReferences.WebMercator);
    
      GeometryBagBuilderEx builder = new GeometryBagBuilderEx(SpatialReferences.WGS84);
    
      GeometryBag emptyBag = builder.ToGeometry();
      // emptyBag.IsEmpty = true
    
      builder.AddGeometry(point);
      // builder.GeometryCount = 1
    
      GeometryBag geometryBag = builder.ToGeometry();
      // geometryBag.PartCount = 1
      // geometryBag.PointCount = 1
      // geometryBag.IsEmpty = false
    
      IReadOnlyList<ArcGIS.Core.Geometry.Geometry> geometries = geometryBag.Geometries;
      // geometries.Count = 1
      // geometries[0] is MapPoint with a sr of WGS84
    
      bool isEqual = geometryBag.IsEqual(emptyBag);   // isEqual = false
    
      builder.InsertGeometry(0, multipoint);
      geometryBag = builder.ToGeometry();
      // geometryBag.PartCount = 2
    
      geometries = geometryBag.Geometries;
      // geometries.Count = 2
      // geometries[0] is Multipoint
      // geometries[1] is MapPoint
    
      builder.AddGeometry(polyline);
      builder.RemoveGeometry(1);
      geometryBag = builder.ToGeometry();
      // geometryBag.PartCount = 2
    
      geometries = geometryBag.Geometries;
      // geometries.Count = 2
      // geometries[0] is Multipoint
      // geometries[1] is Polyline
    }
    Construct GeometryBag - from an enumeration of geometries
    {
      // Use a builder convenience method or use a builder constructor.
    
      MapPoint point = MapPointBuilderEx.CreateMapPoint(10, 20);
      List<Coordinate2D> coords = new List<Coordinate2D>() { new Coordinate2D(50, 60), new Coordinate2D(-120, -70), new Coordinate2D(40, 60) };
      Multipoint multipointNew = MultipointBuilderEx.CreateMultipoint(coords, SpatialReferences.WebMercator);
      Polyline polylineNew = PolylineBuilderEx.CreatePolyline(coords);
    
      string json = "{\"rings\":[[[0,0],[0,1],[1,1],[1,0],[0,0]],[[3,0],[3,1],[4,1],[4,0],[3,0]]]}";
      Polygon polygonNew = PolygonBuilderEx.FromJson(json);
    
      var geometries = new List<Geometry>() { point, multipoint, polyline, polygon };
    
      // Builder convenience methods don't need to run on the MCT.
      var bag = GeometryBagBuilderEx.CreateGeometryBag(geometries, SpatialReferences.WGS84);
    
      var builder = new GeometryBagBuilderEx(geometries, SpatialReferences.WGS84);
      // do something with the builder
      bag = builder.ToGeometry();
    }
    Construct GeometryBag - adding or inserting an enumeration of geometries
    {
      MapPoint point = MapPointBuilderEx.CreateMapPoint(10, 20);
      List<Coordinate2D> coords = new List<Coordinate2D>() { new Coordinate2D(50, 60), new Coordinate2D(-120, -70), new Coordinate2D(40, 60) };
      Multipoint multipointNew = MultipointBuilderEx.CreateMultipoint(coords, SpatialReferences.WebMercator);
      Polyline polylineNew = PolylineBuilderEx.CreatePolyline(coords);
    
      string json = "{\"rings\":[[[0,0],[0,1],[1,1],[1,0],[0,0]],[[3,0],[3,1],[4,1],[4,0],[3,0]]]}";
      Polygon polygonNew = PolygonBuilderEx.FromJson(json);
    
      var geometries = new List<Geometry>() { point, multipoint, polyline, polygon };
    
      var builder = new GeometryBagBuilderEx(SpatialReferences.WGS84);
      builder.AddGeometries(geometries);
    
      GeometryBag geomBag = builder.ToGeometry();
      // geomBag.PartCount == 4    (point, multipoint, polyline, polygon)
    
      geometries = new List<Geometry>() { point, polyline };
      builder.InsertGeometries(1, geometries);
      // builder.GeometryCount == 6
      geomBag = builder.ToGeometry();
      // geomBag.PartCount == 6    (point, point, polyline, multipoint, polyline, polygon)
    }
    Import and Export Geometries to well-known Binary
    {
      // create a polyline
      List<Coordinate2D> coords = new List<Coordinate2D>
      {
        new Coordinate2D(0, 0),
        new Coordinate2D(0, 1),
        new Coordinate2D(1, 1),
        new Coordinate2D(1, 0)
      };
    
      polyline = PolylineBuilderEx.CreatePolyline(
                  coords, SpatialReferences.WGS84);
    
      WkbExportFlags wkbExportFlags = WkbExportFlags.WkbExportDefaults;
      WkbImportFlags wkbImportFlags = WkbImportFlags.WkbImportDefaults;
    
      // export and import
      byte[] buffer = GeometryEngine.Instance.ExportToWKB(wkbExportFlags, polyline);
      geometry = GeometryEngine.Instance.ImportFromWKB(
                     wkbImportFlags, buffer, SpatialReferences.WGS84);
      Polyline importPolyline = geometry as Polyline;
    
    
      // alternatively, determine the size for the buffer
      int bufferSize = GeometryEngine.Instance.GetWKBSize(wkbExportFlags, polyline);
      buffer = new byte[bufferSize];
      // export
      bufferSize = GeometryEngine.Instance.ExportToWKB(
                      wkbExportFlags, polyline, ref buffer);
      // import
      importPolyline = GeometryEngine.Instance.ImportFromWKB(
               wkbImportFlags, buffer, SpatialReferences.WGS84) as Polyline;
    }
    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
    }
    Create Lasso Line, Freehand Graphic Element
    {
      await QueuedTask.Run(() =>
      {
      //Build geometry
      List<Coordinate2D> plCoords = new List<Coordinate2D>();
      plCoords.Add(new Coordinate2D(1.5, 10.5));
      plCoords.Add(new Coordinate2D(1.25, 9.5));
      plCoords.Add(new Coordinate2D(1, 10.5));
      plCoords.Add(new Coordinate2D(0.75, 9.5));
      plCoords.Add(new Coordinate2D(0.5, 10.5));
      plCoords.Add(new Coordinate2D(0.5, 1));
      plCoords.Add(new Coordinate2D(0.75, 2));
      plCoords.Add(new Coordinate2D(1, 1));
      Polyline linePl = PolylineBuilderEx.CreatePolyline(plCoords);
    
      //Set symbology, create and add element to layout
      CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(
                ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid);
      //var graphic = GraphicFactory.Instance.CreateShapeGraphic(linePl, lineSym);
    
      var ge = ElementFactory.Instance.CreateGraphicElement(
                              layout, linePl, lineSym, "New Freehand");
      });
    }
    Create Line Element
    {
      var project = Project.Current;
      await QueuedTask.Run(() =>
      {
    
      //Build geometry
      List<Coordinate2D> plCoords = new List<Coordinate2D>();
      plCoords.Add(new Coordinate2D(1, 8.5));
      plCoords.Add(new Coordinate2D(1.66, 9));
      plCoords.Add(new Coordinate2D(2.33, 8.1));
      plCoords.Add(new Coordinate2D(3, 8.5));
      Polyline linePl = PolylineBuilderEx.CreatePolyline(plCoords);
    
      //Reference a line symbol in a style
      var ProjectStyles = project.GetItems<StyleProjectItem>();
      StyleProjectItem style = ProjectStyles.First(x => x.Name == "ArcGIS 2D");
      var symStyle = style.SearchSymbols(StyleItemType.LineSymbol, "Line with 2 Markers")[0];
      CIMLineSymbol lineSym = symStyle.Symbol as CIMLineSymbol;
      lineSym.SetSize(20);
    
      //Set symbology, create and add element to layout
      //CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 4.0, SimpleLineStyle.Solid);
      ElementFactory.Instance.CreateGraphicElement(
        layout, linePl, lineSym, "New Line");
      });
    }
    Buffer many different Geometry Types
    {
      List<Coordinate2D> coords =
      [
        new Coordinate2D(1, 2), new Coordinate2D(3, 4), new Coordinate2D(4, 2),
        new Coordinate2D(5, 6), new Coordinate2D(7, 8), new Coordinate2D(8, 4),
        new Coordinate2D(9, 10), new Coordinate2D(11, 12), new Coordinate2D(12, 8),
        new Coordinate2D(10, 8), new Coordinate2D(12, 12), new Coordinate2D(14, 10)
      ];
    
      List<Geometry> manyGeometries =
      [
        MapPointBuilderEx.CreateMapPoint(coords[9]),
        PolylineBuilderEx.CreatePolyline([coords[0], coords[1], coords[2]], SpatialReferences.WGS84),
        PolylineBuilderEx.CreatePolyline([coords[3], coords[4], coords[5]]),
        PolygonBuilderEx.CreatePolygon([coords[6], coords[7], coords[8]])
      ];
    
      Geometry manyGeomBuffer = GeometryEngine.Instance.Buffer(manyGeometries, 0.25);
    }
    Construct a Polygon from a set of Polylines
    {
        List<Coordinate2D> firstLinePts = [new Coordinate2D(1.0, 1.0), new Coordinate2D(1.0, 4.0)];
    
        List<Coordinate2D> secondLinePts = [new Coordinate2D(4.0, 4.0), new Coordinate2D(4.0, 1.0)];
    
        List<Coordinate2D> thirdLinePts = [new Coordinate2D(0.0, 2.0), new Coordinate2D(5.0, 2.0)];
    
        List<Coordinate2D> fourthLinePts = [new Coordinate2D(0.0, 3.0), new Coordinate2D(5.0, 3.0)];
    
        // build the polylines
        List<Polyline> polylines =
        [
          PolylineBuilderEx.CreatePolyline(firstLinePts),
      PolylineBuilderEx.CreatePolyline(secondLinePts),
      PolylineBuilderEx.CreatePolyline(thirdLinePts),
      PolylineBuilderEx.CreatePolyline(fourthLinePts),
    ];
    
        // construct polygons from the polylines
        var polygons = GeometryEngine.Instance.ConstructPolygonsFromPolylines(polylines);
    
        // polygons.Count = 1
        // polygon coordinates are (1.0, 2.0), (1.0, 3.0), (4.0, 3.0), (4.0, 2.0)
      }
    Create a buffer polygon at the specified geodesic distance
    {
        // buffer a point
        MapPoint pt = MapPointBuilderEx.CreateMapPoint(1.0, 1.0, SpatialReferences.WGS84);
        Polygon outPolygon = GeometryEngine.Instance.GeodesicBuffer(pt, 5) as Polygon;
    
        double delta = SpatialReferences.WGS84.XYTolerance * 2 * Math.Sqrt(2);
        ReadOnlyPointCollection points = outPolygon.Points;
        foreach (MapPoint p in points)
        {
          double d = GeometryEngine.Instance.GeodesicDistance(pt, p);
          // d = 5 (+- delta)
        }
    
        // specify a unit for the distance
        outPolygon = GeometryEngine.Instance.GeodesicBuffer(pt, 5000, LinearUnit.Millimeters) as Polygon;
    
        // buffer of 0 distance produces an empty geometry
        Geometry g = GeometryEngine.Instance.GeodesicBuffer(pt, 0);
        // g.IsEmpty = true
    
        // buffer many points
        List<MapPoint> list =
        [
          MapPointBuilderEx.CreateMapPoint(1.0, 1.0, SpatialReferences.WGS84),
      MapPointBuilderEx.CreateMapPoint(10.0, 20.0),
      MapPointBuilderEx.CreateMapPoint(40.0, 40.0),
      MapPointBuilderEx.CreateMapPoint(60.0, 60.0),
    ];
    
        outPolygon = GeometryEngine.Instance.GeodesicBuffer(list, 10000) as Polygon;
        // outPolygon.PartCount = 4
    
        // buffer different geometry types
        List<Coordinate2D> coords =
        [
          new Coordinate2D(1, 2), new Coordinate2D(10, 20), new Coordinate2D(20, 30),
      new Coordinate2D(50, 60), new Coordinate2D(70, 80), new Coordinate2D(80, 40),
      new Coordinate2D(90, 10), new Coordinate2D(110, 15), new Coordinate2D(120, 30),
      new Coordinate2D(10, 40), new Coordinate2D(-10, 40), new Coordinate2D(-10, 50)
        ];
    
        List<Geometry> manyGeometries =
        [
          MapPointBuilderEx.CreateMapPoint(1.0, 1.0, SpatialReferences.WGS84),
      PolylineBuilderEx.CreatePolyline([coords[0], coords[1], coords[2]], SpatialReferences.WGS84),
      PolylineBuilderEx.CreatePolyline([coords[3], coords[4], coords[5]]),
      PolygonBuilderEx.CreatePolygon([coords[9], coords[10], coords[11]])
        ];
    
        outPolygon = GeometryEngine.Instance.GeodesicBuffer(manyGeometries, 20000) as Polygon;
    
        // specify unit types
        outPolygon = GeometryEngine.Instance.GeodesicBuffer(manyGeometries, 20, LinearUnit.Miles) as Polygon;
      }
    GeodeticDensifyByDeviation - polyline
    {
      List<Coordinate2D> coords =
      [
        new Coordinate2D(-80, 0),
    new Coordinate2D(-20, 60),
    new Coordinate2D(40, 20),
    new Coordinate2D(0, -20),
    new Coordinate2D(-80, 0)
      ];
    
      SpatialReference sr = SpatialReferences.WGS84;
    
      // create a polyline
      polyline = PolylineBuilderEx.CreatePolyline(coords, sr);
    
      // densify in km
      Polyline geodesicPolyline = GeometryEngine.Instance.GeodeticDensifyByDeviation(polyline, 200, LinearUnit.Kilometers, GeodeticCurveType.Geodesic) as Polyline;
      // densify in m
      geodesicPolyline = GeometryEngine.Instance.GeodeticDensifyByDeviation(polyline, 200, LinearUnit.Meters, GeodeticCurveType.Geodesic) as Polyline;
    
      // Change curve type to Loxodrome
      Polyline loxodromePolyline = GeometryEngine.Instance.GeodeticDensifyByDeviation(polyline, 200, LinearUnit.Meters, GeodeticCurveType.Loxodrome) as Polyline;
    }
    Get Sub-curve of a polyline or polygon
    {
      SpatialReference sr = SpatialReferences.WGS84;
    
      List<Coordinate2D> coords =
      [
        new Coordinate2D(-111, 72),
      new Coordinate2D(-108, 68),
      new Coordinate2D(-114, 68)
      ];
    
      polyline = PolylineBuilderEx.CreatePolyline(coords, sr);
    
      Polyline subCurve = GeometryEngine.Instance.GetSubCurve(polyline, 0, 5, AsRatioOrLength.AsLength);
      // subCurve.PartCount = 1
      // subCurve.PointCount = 2
    
      ReadOnlyPointCollection points = subCurve.Points;
      // points[0] = -111, 72
      // points[1] = -108, 68
    
      subCurve = GeometryEngine.Instance.GetSubCurve(polyline, 0, 0.5, AsRatioOrLength.AsRatio);
      // subCurve.PointCount = 3
    
      points = subCurve.Points;
      // points[0] = -111, 72
      // points[1] = -108, 68
      // points[2] = -108.5, 68
    
      List<Coordinate3D> coords3D =
      [
        new Coordinate3D(0, 0, 0),
      new Coordinate3D(0, 1, 1),
      new Coordinate3D(1, 1, 2),
      new Coordinate3D(1, 0, 3)
      ];
    
      polygon = PolygonBuilderEx.CreatePolygon(coords3D, sr);
    
      subCurve = GeometryEngine.Instance.GetSubCurve3D(polygon, 0, 1, AsRatioOrLength.AsLength);
      // subCurve.HasZ = true
    
      points = subCurve.Points;
      // points.Count = 2
      // points[0] = 0, 0, 0
      // points[1] = 0, 0.70710678118654746, 0.70710678118654746
    }
    GraphicBuffer
    {
      // mitered join and butt caps
      SpatialReference sr = SpatialReferenceBuilder.CreateSpatialReference(102010);
      List<Coordinate2D> coords =
      [
          new Coordinate2D(1400,6200),
      new Coordinate2D(1600,6300),
      new Coordinate2D(1800,6200)
      ];
    
      polyline = PolylineBuilderEx.CreatePolyline(coords, sr);
    
      polygon = GeometryEngine.Instance.GraphicBuffer(polyline, 50, LineJoinType.Miter, LineCapType.Butt, 10, 0, -1) as Polygon;
    
      // bevelled join and round caps
      Envelope envelope = EnvelopeBuilderEx.CreateEnvelope(0, 0, 10000, 10000, SpatialReferences.WebMercator);
    
      Polygon outPolygon = GeometryEngine.Instance.GraphicBuffer(envelope, 1000, LineJoinType.Bevel, LineCapType.Round, 4, 0, 96) as Polygon;
    }
    Determine if all the M-values are numbers - IsMSimple
    {
      Coordinate2D[] coords = [new Coordinate2D(-2, 2), new Coordinate2D(3, 5), new Coordinate2D(7, 2)];
      polyline = PolylineBuilderEx.CreatePolyline(coords); // polyline.HasM = false
      bool isMSimple = GeometryEngine.Instance.IsMSimple(polyline); // isMSimple = false
    
      PolylineBuilderEx polylineBuilder = new(polyline)
      {
        HasM = true
      };
      polyline = polylineBuilder.ToGeometry();
      isMSimple = GeometryEngine.Instance.IsMSimple(polyline); // isMSimple = false
    
      MapPoint point1 = MapPointBuilderEx.CreateMapPoint(-2, 2, -1, 1);
      MapPoint point2 = MapPointBuilderEx.CreateMapPoint(3, 5, -2, 2);
      MapPoint[] points = [point1, point2];
      polyline = PolylineBuilderEx.CreatePolyline(points, AttributeFlags.HasM);
      isMSimple = GeometryEngine.Instance.IsMSimple(polyline); // isMSimple = true
    }
    Reshape a polygon
    {
      List<Coordinate2D> polygon1Coords =
      [
        new Coordinate2D(0, -11000),
      new Coordinate2D(1000, -11000),
      new Coordinate2D(1000, -12000),
      new Coordinate2D(0, -12000),
      new Coordinate2D(0, -11000)
      ];
    
      // reshaper coordinates intersect the polygon
      List<Coordinate2D> reshaperCoords =
      [
        new Coordinate2D(1500, -11800),
      new Coordinate2D(-2600, -11800)
      ];
    
      SpatialReference sr = SpatialReferenceBuilder.CreateSpatialReference(102010);
      Polygon polygon1 = PolygonBuilderEx.CreatePolygon(polygon1Coords, sr);
      Polyline reshaper = PolylineBuilderEx.CreatePolyline(reshaperCoords, sr);
    
      Polygon outPolygon = GeometryEngine.Instance.Reshape(polygon1, reshaper) as Polygon;
      // outPolygon.PartCount = 1
    
      ReadOnlySegmentCollection segments = outPolygon.Parts[0];
      // segments.Count = 4
      // outPolygon.PointCount = 5
    
      string json = GeometryEngine.Instance.ExportToJson(JsonExportFlags.JsonExportSkipCRS, outPolygon);
      // json = "{\"rings\":[[[0,-11800],[0,-11000],[1000,-11000],[1000,-11800],[0,-11800]]]}";
    
      // example where the Reshaper polyline doesn't intersect the input
    
      reshaperCoords.Clear();
      reshaperCoords.Add(new Coordinate2D(1000, 1000));
      reshaperCoords.Add(new Coordinate2D(2000, 1000));
    
      reshaper = PolylineBuilderEx.CreatePolyline(reshaperCoords, sr);
    
      outPolygon = GeometryEngine.Instance.Reshape(polygon1, reshaper) as Polygon;
      // outPolygon = null
    }
    SideBuffer
    {
      // right side, round caps
      SpatialReference sr = SpatialReferenceBuilder.CreateSpatialReference(102010);
      List<Coordinate2D> coords =
      [
        new Coordinate2D(1200, 5800),
    new Coordinate2D(1400, 5800),
    new Coordinate2D(1400, 6000),
    new Coordinate2D(1300, 6000),
    new Coordinate2D(1300, 5700)
      ];
    
      polyline = PolylineBuilderEx.CreatePolyline(coords, sr);
      Polygon output = GeometryEngine.Instance.SideBuffer(polyline, 20, LeftOrRightSide.RightSide, LineCapType.Round) as Polygon;
    }
    SideBuffer Many
    {
      SpatialReference spatialReference = SpatialReferenceBuilder.CreateSpatialReference(102010);
      List<Coordinate2D> coordinates =
      [
        new Coordinate2D(1200, 5800),
    new Coordinate2D(1400, 5800),
    new Coordinate2D(1400, 6000),
    new Coordinate2D(1300, 6000),
    new Coordinate2D(1300, 5700)
      ];
    
      Polyline polyline1 = PolylineBuilderEx.CreatePolyline(coordinates, spatialReference);
    
      coordinates.Clear();
      coordinates.Add(new Coordinate2D(1400, 6050));
      coordinates.Add(new Coordinate2D(1600, 6150));
      coordinates.Add(new Coordinate2D(1800, 6050));
    
      Polyline polyline2 = PolylineBuilderEx.CreatePolyline(coordinates, spatialReference);
      List<Polyline> polylines = [polyline1, polyline2];
      IReadOnlyList<Geometry> outGeometries = GeometryEngine.Instance.SideBuffer(polylines, 10, LeftOrRightSide.RightSide, LineCapType.Round);
    }
    Get Non Simple Reason
    {
        SpatialReference sr = SpatialReferences.WGS84;
        Coordinate2D[] coords = [new Coordinate2D(5, 10), new Coordinate2D(15, 20), new Coordinate2D(25, 10), new Coordinate2D(5, 20)];
        polyline = PolylineBuilderEx.CreatePolyline(coords, sr);
    
        bool isSimple = GeometryEngine.Instance.GetNonSimpleReason(polyline, out NonSimpleReason nonSimpleReason);
        // isSimple = true;
        // nonSimpleReason = NonSimpleReason.IsSimple
    
        double resolution = sr.XYResolution;
        coords = [new Coordinate2D(0, 0), new Coordinate2D(0, 1.8 * resolution), new Coordinate2D(10, 10), new Coordinate2D(0, 5)];
        polyline = PolylineBuilderEx.CreatePolyline(coords, sr);
    
        isSimple = GeometryEngine.Instance.GetNonSimpleReason(polyline, out nonSimpleReason);
        // isSimple = false
        // nonSimpleReason = NonSimpleReason.ShortSegments
    
        coords = [ new Coordinate2D(10, 10), new Coordinate2D(10, 20), new Coordinate2D(40, 20),
    new Coordinate2D(40, 10), new Coordinate2D(60, 10), new Coordinate2D(70, 10)];
    
        polygon = PolygonBuilderEx.CreatePolygon(coords, sr);
    
        isSimple = GeometryEngine.Instance.GetNonSimpleReason(polygon, out nonSimpleReason);
        //isSimple = false
        //nonSimpleReason = NonSimpleReason.SelfIntersections
      }
    Simplify a polyline with intersections, overlaps
    {
      List<Coordinate2D> coords =
      [
        new Coordinate2D(8, 0),
      new Coordinate2D(8, 4),
      new Coordinate2D(6, 4),
      new Coordinate2D(8, 4),
      new Coordinate2D(10, 4),
      new Coordinate2D(8, 4)
      ];
    
      SpatialReference sr = SpatialReferences.WGS84;
    
      // build a line that has segments that cross over each other
      polyline = PolylineBuilderEx.CreatePolyline(coords, sr);
      // polyline.PartCount = 1
      ReadOnlyPartCollection parts = polyline.Parts;
      ReadOnlySegmentCollection segments = parts[0];
      // segments.Count = 5
    
      //  note there is a difference between SimpleAsFeature (doesn't detect intersections and overlaps, determines if it's simple enough for gdb storage)
      //  and SimplifyPolyline  (does detect intersections etc)
      bool isSimple = GeometryEngine.Instance.IsSimpleAsFeature(polyline, false);
      // isSimple = true
    
      // simplify it (with force = false)
      // because it has already been deemed 'simple' (previous IsSimpleAsFeature call) no detection of intersections, overlaps occur
      Polyline simplePolyline = GeometryEngine.Instance.SimplifyPolyline(polyline, SimplifyType.Planar, false);
      // simplePolyline.PartCount = 1
      ReadOnlyPartCollection simpleParts = simplePolyline.Parts;
      ReadOnlySegmentCollection simpleSegments = simpleParts[0];
      // simpleSegments.Count = 5
    
      // simplify it (with force = true)
      // detection of intersections, overlaps occur
      simplePolyline = GeometryEngine.Instance.SimplifyPolyline(polyline, SimplifyType.Planar, true);
      // simplePolyline.PartCount = 3
      simpleParts = simplePolyline.Parts;
      simpleSegments = simpleParts[0];
      // simpleSegments.Count = 1
    }
    SimplifyOGC
    {
      SpatialReference sr = SpatialReferences.WGS84;
    
      Coordinate2D[] coords = [new Coordinate2D(5, 10), new Coordinate2D(15, 20), new Coordinate2D(25, 10), new Coordinate2D(5, 20)];
      polyline = PolylineBuilderEx.CreatePolyline(coords, sr);
      // polyline.IsKnownSimpleOgc = false
      // polyline.IsKnownSimple = false
    
      bool isSimple = GeometryEngine.Instance.IsSimpleOgc(polyline, out NonSimpleReason nonSimpleReason, true);
      // isSimple = false
      // nonSimpleReason = NonSimpleReason.SelfIntersections
    
      Polyline simplePolyline = GeometryEngine.Instance.SimplifyOgc(polyline) as Polyline;
      // simplePolyline.IsKnownSimpleOgc = true
      // simplePolyline.IsKnownSimple = true
    
      double resolution = sr.XYResolution;
      Coordinate3D[] coords3D = [ new Coordinate3D(0, 0, 0), new Coordinate3D(0, 1.8 * resolution, 0.8 * sr.ZTolerance), new Coordinate3D(10, 10, 1),
    new Coordinate3D(0, 5, 1) ];
      polyline = PolylineBuilderEx.CreatePolyline(coords3D, sr);
    
      isSimple = GeometryEngine.Instance.IsSimpleOgc(polyline, out nonSimpleReason);
      // isSimple = false
      // nonSimpleReason = NonSimpleReason.ShortSegments
    
      simplePolyline = GeometryEngine.Instance.SimplifyOgc(polyline, true) as Polyline;
      // simplePolyline.IsKnownSimpleOgc = true
      // simplePolyline.IsKnownSimple = true
    
      coords = [new Coordinate2D(0, 0), new Coordinate2D(0, 0)];
      Multipoint multipoint = MultipointBuilderEx.CreateMultipoint(coords, sr);
    
      isSimple = GeometryEngine.Instance.IsSimpleOgc(multipoint, out nonSimpleReason);
      // isSimple = false
      // nonSimpleReason = NonSimpleReason.DuplicateVertex
    }
    Union many Polylines
    {
      // union many polylines
    
      List<Coordinate2D> coords =
      [
        new Coordinate2D(1, 2), new Coordinate2D(3, 4), new Coordinate2D(4, 2),
      new Coordinate2D(5, 6), new Coordinate2D(7, 8), new Coordinate2D(8, 4),
      new Coordinate2D(9, 10), new Coordinate2D(11, 12), new Coordinate2D(12, 8),
      new Coordinate2D(10, 8), new Coordinate2D(12, 12), new Coordinate2D(14, 10)
      ];
    
      // create Disjoint lines
      List<Polyline> manyLines =
      [
        PolylineBuilderEx.CreatePolyline([coords[0], coords[1], coords[2]], SpatialReferences.WGS84),
        PolylineBuilderEx.CreatePolyline([coords[3], coords[4], coords[5]]),
        PolylineBuilderEx.CreatePolyline([coords[6], coords[7], coords[8]])
      ];
    
      polyline = GeometryEngine.Instance.Union(manyLines) as Polyline;
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also