ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Core.Geometry Namespace / PolygonBuilderEx Class / CreatePolygon Method / CreatePolygon(IEnumerable<Coordinate3D>,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<Coordinate3D>,SpatialReference) Method
    In This Topic
    Convenience method to create a new instance of the Polygon class.
    Syntax
    Public Overloads Shared Function CreatePolygon( _
       ByVal coordinate3Ds As IEnumerable(Of Coordinate3D), _
       Optional ByVal spatialReference As SpatialReference _
    ) As Polygon

    Parameters

    coordinate3Ds
    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
    coordinate3Ds is null.
    Remarks
    The HasZ property is set to true.
    Example
    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;
    }
    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
    }
    Replace NaN Zs in a polygon
    {
      List<Coordinate3D> coordsZ =
      [
        new Coordinate3D(1, 2, double.NaN),
      new Coordinate3D(4, 5, 3),
      new Coordinate3D(7, 8, double.NaN)
      ];
    
      polygon = PolygonBuilderEx.CreatePolygon(coordsZ);
      // polygon.HasZ = true
    
      Polygon polygonZReplaced = GeometryEngine.Instance.ReplaceNaNZs(polygon, -1) as Polygon;
    
      // polygonZReplaced.Points[0].Z = -1
      // polygonZReplaced.Points[1].Z = 3
      // polygonZReplaced.Points[2].Z = -1
    }
    Union many Polygons
    {
      // union many polygons
    
      List<Coordinate3D> coordsZ =
      [
        new Coordinate3D(1, 2, 0), new Coordinate3D(3, 4, 1), new Coordinate3D(4, 2, 2),
      new Coordinate3D(5, 6, 3), new Coordinate3D(7, 8, 4), new Coordinate3D(8, 4, 5),
      new Coordinate3D(9, 10, 6), new Coordinate3D(11, 12, 7), new Coordinate3D(12, 8, 8),
      new Coordinate3D(10, 8, 9), new Coordinate3D(12, 12, 10), new Coordinate3D(14, 10, 11)
      ];
    
      // create polygons
      List<Polygon> manyPolygonsZ =
      [
        PolygonBuilderEx.CreatePolygon([coordsZ[0], coordsZ[1], coordsZ[2]], SpatialReferences.WGS84),
        PolygonBuilderEx.CreatePolygon([coordsZ[3], coordsZ[4], coordsZ[5]]),
        PolygonBuilderEx.CreatePolygon([coordsZ[6], coordsZ[7], coordsZ[8]])
      ];
    
      polygon = GeometryEngine.Instance.Union(manyPolygonsZ) as Polygon;
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also