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

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

    Parameters

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

    Return Value

    Exceptions
    ExceptionDescription
    coordinate2Ds is null.
    Example
    Create an N-sided regular polygon
    {
      // <summary>
      // Create an N-sided regular polygon.  A regular sided polygon is a polygon that is equiangular (all angles are equal in measure)
      // and equilateral (all sides are equal in length).  See https://en.wikipedia.org/wiki/Regular_polygon
      // </summary>
      // <param name="numSides">The number of sides in the polygon.</param>
      // <param name="center">The center of the polygon.</param>
      // <param name="radius">The distance from the center of the polygon to a vertex.</param>
      // <param name="rotation">The rotation angle in radians of the start point of the polygon. The start point will be
      // rotated counterclockwise from the positive x-axis.</param>
      // <returns>N-sided regular polygon.</returns>
      // <exception cref="ArgumentException">Number of sides is less than 3.</exception>
      static Polygon CreateRegularPolygon(int numSides, Coordinate2D center, double radius, double rotation)
      {
        if (numSides < 3)
        {
          throw new ArgumentException();
        }
    
        Coordinate2D[] coords = new Coordinate2D[numSides + 1];
    
        double centerX = center.X;
        double centerY = center.Y;
        double x = radius * Math.Cos(rotation) + centerX;
        double y = radius * Math.Sin(rotation) + centerY;
        Coordinate2D start = new Coordinate2D(x, y);
        coords[0] = start;
    
        double da = 2 * Math.PI / numSides;
        for (int i = 1; i < numSides; i++)
        {
          x = radius * Math.Cos(i * da + rotation) + centerX;
          y = radius * Math.Sin(i * da + rotation) + centerY;
    
          coords[i] = new Coordinate2D(x, y);
        }
    
        coords[numSides] = start;
    
        return PolygonBuilderEx.CreatePolygon(coords);
      }
    }
    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 Polygon, Freehand Element
    {
      await QueuedTask.Run(() =>
      {
    
      List<Coordinate2D> plyCoords = new List<Coordinate2D>();
      plyCoords.Add(new Coordinate2D(1, 1));
      plyCoords.Add(new Coordinate2D(1.25, 2));
      plyCoords.Add(new Coordinate2D(1.5, 1.1));
      plyCoords.Add(new Coordinate2D(1.75, 2));
      plyCoords.Add(new Coordinate2D(2, 1.1));
      plyCoords.Add(new Coordinate2D(2.25, 2));
      plyCoords.Add(new Coordinate2D(2.5, 1.1));
      plyCoords.Add(new Coordinate2D(2.75, 2));
      plyCoords.Add(new Coordinate2D(3, 1));
      Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
      //Set symbology, create and add element to layout
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
                  ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid);
      CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(
               ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
    
      ElementFactory.Instance.CreateGraphicElement(
        layout, poly, polySym, "New Lasso");
      });
    }
    Create Polygon Element
    {
      await QueuedTask.Run(() =>
      {
    
      //Build geometry
      List<Coordinate2D> plyCoords = new List<Coordinate2D>();
      plyCoords.Add(new Coordinate2D(1, 7));
      plyCoords.Add(new Coordinate2D(2, 7));
      plyCoords.Add(new Coordinate2D(2, 6.7));
      plyCoords.Add(new Coordinate2D(3, 6.7));
      plyCoords.Add(new Coordinate2D(3, 6.1));
      plyCoords.Add(new Coordinate2D(1, 6.1));
      Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
      //Set symbology, create and add element to layout
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
        ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.DashDotDot);
      CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(
        ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
    
      ElementFactory.Instance.CreateGraphicElement(
        layout, poly, polySym, "New Polygon", false);
      });
    }
    Create Rectangle Paragraph Text Element 1
    {
      await QueuedTask.Run(() =>
      {
      //Create rectangle text with background and border symbology.
      //Build 2D polygon geometry
      List<Coordinate2D> plyCoords = new List<Coordinate2D>();
      plyCoords.Add(new Coordinate2D(3.5, 7));
      plyCoords.Add(new Coordinate2D(4.5, 7));
      plyCoords.Add(new Coordinate2D(4.5, 6.7));
      plyCoords.Add(new Coordinate2D(5.5, 6.7));
      plyCoords.Add(new Coordinate2D(5.5, 6.1));
      plyCoords.Add(new Coordinate2D(3.5, 6.1));
      Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
      //Set symbology, create and add element to layout
      //Also notice how formatting tags are using within the text string.
      CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
                        ColorFactory.Instance.GreyRGB, 10, "Arial", "Regular");
      string text = "Some Text String that is really long and is " +
                    "<BOL>forced to wrap to other lines</BOL> so that " +
                    "we can see the effects." as String;
    
      GraphicElement polyTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
        layout, TextType.RectangleParagraph, poly, sym, text, "Polygon Paragraph");
    
      //(Optionally) Modify paragraph border
      CIMGraphic polyTxtGra = polyTxtElm.GetGraphic();
      CIMParagraphTextGraphic cimPolyTxtGra = polyTxtGra as CIMParagraphTextGraphic;
      cimPolyTxtGra.Frame.BorderSymbol = new CIMSymbolReference();
      cimPolyTxtGra.Frame.BorderSymbol.Symbol =
                   SymbolFactory.Instance.ConstructLineSymbol(
                              ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
      polyTxtElm.SetGraphic(polyTxtGra);
      });
    }
    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);
    }
    Find the centroid of geometries
    {
      // simple polygon
      List<Coordinate2D> list2D =
      [
        new Coordinate2D(0, 0),
        new Coordinate2D(0, 2),
        new Coordinate2D(2, 2),
        new Coordinate2D(2, 0),
      ];
    
      polygon = PolygonBuilderEx.CreatePolygon(list2D, SpatialReferences.WGS84);
    
      // verify it is simple
      bool isSimple = GeometryEngine.Instance.IsSimpleAsFeature(polygon);
      // find the centroid
      MapPoint centroid = GeometryEngine.Instance.Centroid(polygon);
      // centroid.X = 1
      // centroid.Y = 1
    
      // map Point
      MapPoint pt1 = MapPointBuilderEx.CreateMapPoint(1, 2, 3, 4, SpatialReferences.WGS84);
      MapPoint pt2 = MapPointBuilderEx.CreateMapPoint(5, 2, double.NaN, 7);
    
      // pt1.HasZ = true
      // pt1.HasM = true
      centroid = GeometryEngine.Instance.Centroid(pt1);
      // centroid.HasZ = true
      // centroid.HasM = true
      // pt1.IsEqual(centroid) = true
    
      // multipoint
      List<MapPoint> list = [pt1, pt2];
      Multipoint multipoint = MultipointBuilderEx.CreateMultipoint(list);
      // multipoint.HasZ = true
      // multipoint.HasM = true
    
      centroid = GeometryEngine.Instance.Centroid(multipoint);
      // centroid.X = 3
      // centroid.Y = 2
      // centroid.HasZ = false
      // centroid.HasM = false
    }
    Clip a Polyline by a Polygon
    {
      // clip a polyline by a polygon
    
      List<Coordinate2D> list =
      [
        new Coordinate2D(1.0, 1.0),
        new Coordinate2D(1.0, 4.0),
        new Coordinate2D(4.0, 4.0),
        new Coordinate2D(4.0, 1.0),
      ];
    
      polygon = PolygonBuilderEx.CreatePolygon(list, SpatialReferences.WGS84);
    
      LineSegment crossingLine = LineBuilderEx.CreateLineSegment(MapPointBuilderEx.CreateMapPoint(0, 3), MapPointBuilderEx.CreateMapPoint(5.0, 3.0));
      Polyline p = PolylineBuilderEx.CreatePolyline(crossingLine);
      Geometry geometry = GeometryEngine.Instance.Clip(p, polygon.Extent);
    }
    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;
      }
    GeodeticDensifyByLength - polygon
    {
      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 polygon
      polygon = PolygonBuilderEx.CreatePolygon(coords, sr);
    
      // get the geodesic lengths of the polygon segments
      ReadOnlySegmentCollection segments = polygon.Parts[0];
      List<double> geoLengths = new(segments.Count);
      foreach (Segment s in segments)
      {
        Polyline line = PolylineBuilderEx.CreatePolyline(s, sr);
        double geoLen = GeometryEngine.Instance.GeodesicLength(line);
        geoLengths.Add(geoLen);
      }
    
      // find the max length
      geoLengths.Sort();
      double maxLen = geoLengths[^1];
    
      // densify the polygon (in meters)
      Polygon densifiedPoly = GeometryEngine.Instance.GeodeticDensifyByLength(polygon, maxLen, LinearUnit.Meters, GeodeticCurveType.Geodesic) as Polygon;
    
      // densify the polygon (in km)
      double maxSegmentLength = maxLen / 10000;
      densifiedPoly = GeometryEngine.Instance.GeodeticDensifyByLength(polygon, maxSegmentLength, LinearUnit.Kilometers, GeodeticCurveType.Geodesic) as Polygon;
    }
    Determine label point for a Polygon
    {
      // create a polygon
      List<Coordinate2D> list2D =
      [
        new Coordinate2D(1.0, 1.0),
        new Coordinate2D(1.0, 2.0),
        new Coordinate2D(2.0, 2.0),
        new Coordinate2D(2.0, 1.0),
      ];
    
      polygon = PolygonBuilderEx.CreatePolygon(list2D);
      bool isSimple = GeometryEngine.Instance.IsSimpleAsFeature(polygon);
      MapPoint pt = GeometryEngine.Instance.LabelPoint(polygon);
    }
    Separate components of a geometry into single component geometries
    {
      List<Coordinate2D> coords2D =
      [
        new Coordinate2D(0, 0),
      new Coordinate2D(1, 4),
      new Coordinate2D(2, 7),
      new Coordinate2D(-10, 3)
      ];
    
      Multipoint multipoint = MultipointBuilderEx.CreateMultipoint(coords2D, SpatialReferences.WGS84);
    
      IReadOnlyList<Geometry> result = GeometryEngine.Instance.MultipartToSinglePart(multipoint);
      // result.Count = 4,
    
      // 'explode' a multipart polygon
      result = GeometryEngine.Instance.MultipartToSinglePart(multipartPolygon);
    
      // create a bag of geometries
      polygon = PolygonBuilderEx.CreatePolygon(coords2D, SpatialReferences.WGS84);
      var bag = GeometryBagBuilderEx.CreateGeometryBag([multipoint, polygon]);
      // bag.PartCount = =2
    
      result = GeometryEngine.Instance.MultipartToSinglePart(bag);
      // result.Count == 2
      // result[0] is MultiPoint
      // result[1] is Polygon
    }
    Nearest Point versus Nearest Vertex
    {
      SpatialReference sr = SpatialReferences.WGS84;
      MapPoint pt = MapPointBuilderEx.CreateMapPoint(5, 5, sr);
    
      List<Coordinate2D> coords =
      [
        new Coordinate2D(10, 1),
      new Coordinate2D(10, -4),
      new Coordinate2D(0, -4),
      new Coordinate2D(0, 1),
      new Coordinate2D(10, 1)
      ];
    
      polygon = PolygonBuilderEx.CreatePolygon(coords);
    
      // find the nearest point in the polygon geometry to the pt
      ProximityResult result = GeometryEngine.Instance.NearestPoint(polygon, pt);
      // result.Point = 5, 1
      // result.SegmentIndex = 3
      // result.PartIndex = 0
      // result.PointIndex = null
      //result.Distance = 4
      //result.RightSide = false
    
      // find the nearest vertex in the polgyon geometry to the pt
      result = GeometryEngine.Instance.NearestVertex(polygon, pt);
      // result.Point = 10, 1
      // result.PointIndex = 0
      // result.SegmentIndex = null
      // result.PartIndex = 0
      // result.Distance = Math.Sqrt(41)
      // result.RightSide = false
    }
    Reflect a polygon about a line
    {
      SpatialReference sr = SpatialReferences.WGS84;
    
      Coordinate2D start = new(0, 0);
      Coordinate2D end = new(4, 4);
      LineSegment line = LineBuilderEx.CreateLineSegment(start, end, sr);
    
      Coordinate2D[] coords =
      [
        new Coordinate2D(-1, 2),
      new Coordinate2D(-1, 4),
      new Coordinate2D(1, 4),
      new Coordinate2D(-1, 2)
      ];
    
      polygon = PolygonBuilderEx.CreatePolygon(coords, sr);
    
      // reflect a polygon about the line
      Polygon reflectedPolygon = GeometryEngine.Instance.ReflectAboutLine(polygon, line) as Polygon;
    
      // reflectedPolygon points are
      //    (2, -1), (4, -1), (4, 1), (2, -1)
    }
    Determine relationship between two geometries
    {
      // set up some geometries
    
      // points
      MapPoint point0 = MapPointBuilderEx.CreateMapPoint(0, 0, SpatialReferences.WGS84);
      MapPoint point1 = MapPointBuilderEx.CreateMapPoint(1, 1, SpatialReferences.WGS84);
      MapPoint point2 = MapPointBuilderEx.CreateMapPoint(-5, 5, SpatialReferences.WGS84);
    
      // multipoint
      List<MapPoint> points = [point0, point1, point2];
      Multipoint multipoint = MultipointBuilderEx.CreateMultipoint(points, SpatialReferences.WGS84);
    
      // polygon
      List<Coordinate2D> polygonCoords =
      [
          new Coordinate2D(-10, 0),
      new Coordinate2D(0, 10),
      new Coordinate2D(10, 0),
      new Coordinate2D(-10, 0)
      ];
      polygon = PolygonBuilderEx.CreatePolygon(polygonCoords, SpatialReferences.WGS84);
    
      // polylines
      Polyline polyline1 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(-9.1, 0.1), new Coordinate2D(0, 9)), SpatialReferences.WGS84);
      Polyline polyline2 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(-5, 5), new Coordinate2D(0, 5)), SpatialReferences.WGS84);
      Polyline polyline3 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(2.09, -2.04), new Coordinate2D(5, 10)), SpatialReferences.WGS84);
      Polyline polyline4 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(10, -5), new Coordinate2D(10, 5)), SpatialReferences.WGS84);
    
      List<Segment> segments =
      [
          LineBuilderEx.CreateLineSegment(new Coordinate2D(5.05, -2.87), new Coordinate2D(6.35, 1.57)),
      LineBuilderEx.CreateLineSegment(new Coordinate2D(6.35, 1.57), new Coordinate2D(4.13, 2.59)),
      LineBuilderEx.CreateLineSegment(new Coordinate2D(4.13, 2.59), new Coordinate2D(5, 5))
      ];
      Polyline polyline5 = PolylineBuilderEx.CreatePolyline(segments, SpatialReferences.WGS84);
    
      segments.Add(LineBuilderEx.CreateLineSegment(new Coordinate2D(5, 5), new Coordinate2D(10, 10)));
    
      Polyline polyline6 = PolylineBuilderEx.CreatePolyline(segments, SpatialReferences.WGS84);
      Polyline polyline7 = PolylineBuilderEx.CreatePolyline(polyline5);
      Polyline polyline8 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(5, 5), new Coordinate2D(10, 10)), SpatialReferences.WGS84);
    
      segments.Clear();
      segments.Add(LineBuilderEx.CreateLineSegment(new Coordinate2D(0.6, 3.5), new Coordinate2D(0.7, 7)));
      segments.Add(LineBuilderEx.CreateLineSegment(new Coordinate2D(0.7, 7), new Coordinate2D(3, 9)));
    
      Polyline polyline9 = PolylineBuilderEx.CreatePolyline(segments, SpatialReferences.WGS84);
    
      // now do the Related tests
    
      // Interior/Interior Intersects
      string scl = "T********";
      bool related = GeometryEngine.Instance.Relate(polygon, polyline1, scl);     // related = true
      related = GeometryEngine.Instance.Relate(point0, point1, scl);              // related = false
      related = GeometryEngine.Instance.Relate(point0, multipoint, scl);          // related = true
      related = GeometryEngine.Instance.Relate(multipoint, polygon, scl);         // related = true
      related = GeometryEngine.Instance.Relate(multipoint, polyline1, scl);       // related = false
      related = GeometryEngine.Instance.Relate(polyline2, point2, scl);           // related = false
      related = GeometryEngine.Instance.Relate(point1, polygon, scl);             // related = true
    
      // Interior/Boundary Intersects
      scl = "*T*******";
      related = GeometryEngine.Instance.Relate(polygon, polyline2, scl);          // related = true
      related = GeometryEngine.Instance.Relate(polygon, polyline3, scl);          // related = false
      related = GeometryEngine.Instance.Relate(point1, polygon, scl);             // related = false
    
      // Boundary/Boundary Interior intersects
      scl = "***T*****";
      related = GeometryEngine.Instance.Relate(polygon, polyline4, scl);          // related = true
    
      // Overlaps Dim1
      scl = "1*T***T**";
      related = GeometryEngine.Instance.Relate(polygon, polyline5, scl);          // related = true
    
      // Crosses Area/Line (LineB crosses PolygonA)
      scl = "1020F1102";
      related = GeometryEngine.Instance.Relate(polygon, polyline6, scl);          // related = false
      related = GeometryEngine.Instance.Relate(polygon, polyline9, scl);          // related = true
    
      // Boundary/Boundary Touches
      scl = "F***T****";
      related = GeometryEngine.Instance.Relate(polygon, polyline7, scl);          // related = false
      related = GeometryEngine.Instance.Relate(polygon, polyline8, scl);          // related = 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
    }
    Reverse the order of points in a Polygon
    {
      List<Coordinate2D> list2D =
      [
        new Coordinate2D(1.0, 1.0),
      new Coordinate2D(1.0, 2.0),
      new Coordinate2D(2.0, 2.0),
      new Coordinate2D(2.0, 1.0),
    ];
    
      polygon = PolygonBuilderEx.CreatePolygon(list2D);
    
      Geometry g = GeometryEngine.Instance.ReverseOrientation(polygon);
      Polygon gPolygon = g as Polygon;
    
      // gPolygon.Points[0] = 1.0, 1.0
      // gPolygon.Points[1] = 2.0, 1.0
      // gPolygon.Points[2] = 2.0, 2.0
      // gPolygon.Points[3] = 1.0, 2.0
      // gPolygon.Points[4] = 1.0, 1.0
      // gPolygon.Area = -1 * polygon.Area
    }
    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
      }
    Slice a Polygon into equal parts
    {
      var slices = GeometryEngine.Instance.SlicePolygonIntoEqualParts(polygon, 3, 0, SliceType.Blocks);
      // slices.Count = 3
    
      // simple polygon
      List<Coordinate2D> list2D =
      [
        new Coordinate2D(1.0, 1.0),
      new Coordinate2D(1.0, 2.0),
      new Coordinate2D(2.0, 2.0),
      new Coordinate2D(2.0, 1.0),
    ];
    
      Polygon p = PolygonBuilderEx.CreatePolygon(list2D);
      slices = GeometryEngine.Instance.SlicePolygonIntoEqualParts(p, 2, 0, SliceType.Strips);
    
      // slice[0] coordinates - (1.0, 1.0), (1.0, 1.5), (2.0, 1.5), (2.0, 1.0), (1.0, 1.0)
      // slice[1] coordinates - (1.0, 1.5), (1.0, 2.0), (2.0, 2.0), (2.0, 1.5), (1.0, 1.5)
    
      slices = GeometryEngine.Instance.SlicePolygonIntoEqualParts(p, 2, Math.PI / 4, SliceType.Strips);
    
      // slice[0] coordinates - (1.0, 1.0), (1.0, 2.0), (2.0, 1.0), (1.0, 1.0)
      // slice[1] coordinates - (1.0, 2.0), (2.0, 2.0), (2.0, 1.0), (1.0, 2.0)
    }
    Get the individual parts of a multipart feature
    IEnumerable<Geometry> MultipartToSinglePart(Geometry inputGeometry)
    {
      // list holding the part(s) of the input geometry
      List<Geometry> singleParts = new List<Geometry>();
    
      // check if the input is a null pointer or if the geometry is empty
      if (inputGeometry == null || inputGeometry.IsEmpty)
      {
        return singleParts;
      }
    
      // based on the type of geometry, take the parts/points and add them individually into a list
      switch (inputGeometry.GeometryType)
      {
        case GeometryType.Envelope:
          singleParts.Add(inputGeometry.Clone() as Envelope);
          break;
        case GeometryType.Multipatch:
          singleParts.Add(inputGeometry.Clone() as Multipatch);
          break;
        case GeometryType.Multipoint:
          var multiPoint = inputGeometry as Multipoint;
    
          foreach (var point in multiPoint.Points)
          {
            // add each point of collection as a standalone point into the list
            singleParts.Add(point);
          }
          break;
        case GeometryType.Point:
          singleParts.Add(inputGeometry.Clone() as MapPoint);
          break;
        case GeometryType.Polygon:
          var polygonNew = inputGeometry as Polygon;
    
          foreach (var polygonPart in polygonNew.Parts)
          {
            // use the PolygonBuilderEx turning the segments into a standalone
            // polygon instance
            singleParts.Add(PolygonBuilderEx.CreatePolygon(polygonPart));
          }
          break;
        case GeometryType.Polyline:
          var polylineNew = inputGeometry as Polyline;
    
          foreach (var polylinePart in polyline.Parts)
          {
            // use the PolylineBuilderEx turning the segments into a standalone
            // polyline instance
            singleParts.Add(PolylineBuilderEx.CreatePolyline(polylinePart));
          }
          break;
        case GeometryType.Unknown:
          break;
        default:
          break;
      }
      return singleParts;
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also