ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Core.Geometry Namespace / PolygonBuilderEx Class / PolygonBuilderEx Constructor / PolygonBuilderEx Constructor(IEnumerable<MapPoint>,AttributeFlags,SpatialReference)
Points for the first ring. Line segments are created from the points.
AttributeFlags to set the HasZ, HasM and HasID attributes. If no attributes should be set, pass AttributeFlags.None. If all attributes should be set, pass AttributeFlags.AllAttributes. Use the bitwise OR operator to set two attributes. For example, to set HasZ = true and HasM = true, pass AttributeFlags.HasZ | AttributeFlags.HasM.
(Optional) The SpatialReference. The default value is null. The spatial reference of each point is ignored.
Example

In This Topic
    PolygonBuilderEx Constructor(IEnumerable<MapPoint>,AttributeFlags,SpatialReference)
    In This Topic
    Initializes a new instance of the PolygonBuilderEx class.
    Syntax

    Parameters

    points
    Points for the first ring. Line segments are created from the points.
    attributes
    AttributeFlags to set the HasZ, HasM and HasID attributes. If no attributes should be set, pass AttributeFlags.None. If all attributes should be set, pass AttributeFlags.AllAttributes. Use the bitwise OR operator to set two attributes. For example, to set HasZ = true and HasM = true, pass AttributeFlags.HasZ | AttributeFlags.HasM.
    spatialReference
    (Optional) The SpatialReference. The default value is null. The spatial reference of each point is ignored.
    Exceptions
    ExceptionDescription
    The input mapPoint enumeration is null.
    Example
    Builder Properties
    // list of points
    List<MapPoint> points = new List<MapPoint>
    {
      MapPointBuilderEx.CreateMapPoint(0, 0, 2, 3, 1),
      MapPointBuilderEx.CreateMapPoint(1, 1, 5, 6),
      MapPointBuilderEx.CreateMapPoint(2, 1, 6),
      MapPointBuilderEx.CreateMapPoint(0, 0)
    };
    
    // will have attributes because it is created with convenience method
    Polyline polylineWithAttrs = PolylineBuilderEx.CreatePolyline(points);
    bool hasZ = polylineWithAttrs.HasZ;          // hasZ = true
    bool hasM = polylineWithAttrs.HasM;          // hasM = true
    bool hasID = polylineWithAttrs.HasID;        // hasID = true
    
    // will not have attributes because it is specified as a parameter
    Polyline polylineWithoutAttrs = 
      PolylineBuilderEx.CreatePolyline(points, AttributeFlags.None);
    hasZ = polylineWithoutAttrs.HasZ;          // hasZ = false
    hasM = polylineWithoutAttrs.HasM;          // hasM = false
    hasID = polylineWithoutAttrs.HasID;        // hasID = false
    
    // will have attributes because it is created with convenience method
    Polygon polygonWithAttrs = PolygonBuilderEx.CreatePolygon(points);
    hasZ = polygonWithAttrs.HasZ;               // hasZ = true
    hasM = polygonWithAttrs.HasM;               // hasM = true
    hasID = polygonWithAttrs.HasID;             // hasID = true
    
    // will not have attributes because it is specified as a parameter
    Polygon polygonWithoutAttrs = 
          PolygonBuilderEx.CreatePolygon(points, AttributeFlags.None);
    hasZ = polygonWithoutAttrs.HasZ;               // hasZ = false
    hasM = polygonWithoutAttrs.HasM;               // hasM = false
    hasID = polygonWithoutAttrs.HasID;             // hasID = false
    
    // will not have attributes because it is specified as a parameter
    PolylineBuilderEx polylineB = 
               new PolylineBuilderEx(points, AttributeFlags.None);
    hasZ = polylineB.HasZ;                      // hasZ = false
    hasM = polylineB.HasM;                      // hasM = false
    hasID = polylineB.HasID;                    // hasID = false
    
    // will have attributes because it is passed an attributed polyline
    polylineB = new PolylineBuilderEx(polylineWithAttrs);
    hasZ = polylineB.HasZ;                      // hasZ = true
    hasM = polylineB.HasM;                      // hasM = true
    hasID = polylineB.HasID;                    // hasID = true
    
    // will not have attributes because it is passed a non-attributed polyline
    polylineB = new PolylineBuilderEx(polylineWithoutAttrs);
    hasZ = polylineB.HasZ;                      // hasZ = false
    hasM = polylineB.HasM;                      // hasM = false
    hasID = polylineB.HasID;                    // hasID = false
    
    // will not have attributes because it is specified as a parameter
    PolygonBuilderEx polygonB = new PolygonBuilderEx(points, AttributeFlags.None);
    hasZ = polygonB.HasZ;                       // hasZ = false
    hasM = polygonB.HasM;                       // hasM = false
    hasID = polygonB.HasID;                     // hasID = false
    
    // will have attributes because it is passed an attributed polygon
    polygonB = new PolygonBuilderEx(polygonWithAttrs);
    hasZ = polygonB.HasZ;                       // hasZ = true
    hasM = polygonB.HasM;                       // hasM = true
    hasID = polygonB.HasID;                     // hasID = true
    
    // will not have attributes because it is passed a non-attributed polygon
    polygonB = new PolygonBuilderEx(polygonWithoutAttrs);
    hasZ = polygonB.HasZ;                       // hasZ = true
    hasM = polygonB.HasM;                       // hasM = true
    hasID = polygonB.HasID;                     // hasID = true
    
    Construct a Polygon - from an enumeration of MapPoints
    // Use a builderEx convenience method or use a builderEx constructor.
    
    MapPoint pt1 = MapPointBuilderEx.CreateMapPoint(1.0, 1.0);
    MapPoint pt2 = MapPointBuilderEx.CreateMapPoint(1.0, 2.0);
    MapPoint pt3 = MapPointBuilderEx.CreateMapPoint(2.0, 2.0);
    MapPoint pt4 = MapPointBuilderEx.CreateMapPoint(2.0, 1.0);
    
    List<MapPoint> list = new List<MapPoint>() { pt1, pt2, pt3, pt4 };
    
    Polygon polygon = PolygonBuilderEx.CreatePolygon(list, SpatialReferences.WGS84);
    // polygon.HasZ will be false - it is determined by the HasZ flag of the points in the list
    
    // or specifically use AttributeFlags.NoAttributes
    polygon = PolygonBuilderEx.CreatePolygon(list, AttributeFlags.None);
    
    // use AttributeFlags.None as we have 2D points
    PolygonBuilderEx polygonBuilder = new PolygonBuilderEx(list, AttributeFlags.None);
    polygonBuilder.SpatialReference = SpatialReferences.WGS84;
    polygon = polygonBuilder.ToGeometry();
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also