PolygonBuilder Class

  • PolygonBuilder
  • class Esri::ArcGISRuntime::PolygonBuilder

    The polygon builder allows you to create and modify Polygon geometries incrementally. More...

    Header: #include <PolygonBuilder.h>
    Since: Esri::ArcGISRuntime 100.0
    Inherits: Esri::ArcGISRuntime::MultipartBuilder

    Public Functions

    PolygonBuilder(const Esri::ArcGISRuntime::SpatialReference &spatialReference, QObject *parent = nullptr)
    PolygonBuilder(const Esri::ArcGISRuntime::Polygon &polygon, QObject *parent = nullptr)
    virtual ~PolygonBuilder() override
    Esri::ArcGISRuntime::Polygon toPolygon() const
    Esri::ArcGISRuntime::Polyline toPolyline() const

    Reimplemented Public Functions

    virtual Esri::ArcGISRuntime::GeometryBuilderType geometryBuilderType() const override
    virtual Esri::ArcGISRuntime::Geometry toGeometry() const override

    Detailed Description

    Polygon geometries are immutable and cannot be changed directly once created. A polygon is a closed area shape defined by one or more parts. Each part in a polygon is a connected sequence of Segment instances that start and end at the same point (a closed ring). If a polygon has more than one ring, the rings may be separate from one another or they may nest inside one another, but they should not overlap. Note: interior rings, to make donut polygons, should be counter-clockwise in direction to be topology correct. If there is ever a doubt about the topological correctness of a polygon, call GeometryEngine::simplify(const Esri::ArcGISRuntime::Geometry&) to correct any issues.

    The polygon builder allows you to change the contents of the shape using the PartCollection that you can access from the MultipartBuilder::parts. Each Part, in this PartCollection, comprises a collection of segments that make edges of the Part. You can add or remove a Part from the PartCollection, or you can create a new or edit the segment vertices of an existing Part. Use GeometryBuilder::toGeometry to return the new Polygon from the builder.

    // create a polygon builder
    auto* polygonBuilder = new PolygonBuilder(SpatialReference(3857), this);
    
    // create a single-part polygon using x/y
    polygonBuilder->addPoint(-18.0, 34.0);
    polygonBuilder->addPoint(-18.0, 35.0);
    polygonBuilder->addPoint(-17.0, 34.0);
    Polygon singlePartPolygonXY(polygonBuilder->toGeometry());
    
    // create a multi-part polygon with same PolygonBuilder
    auto* partCollection = new PartCollection(polygonBuilder->spatialReference(), this);
    
    // create outer poly 1
    Part* part1 = new Part(polygonBuilder->spatialReference(), this);
    part1->addPoint(2.123456789, 3.123456789);
    part1->addPoint(1.123456789, 3.123456789);
    part1->addPoint(1.123456789, 1.123456789);
    partCollection->addPart(part1);
    
    // create outer poly 2
    Part* part2 = new Part(polygonBuilder->spatialReference(), this);
    part2->addPoint(3.123456789, 3.123456789);
    part2->addPoint(4.123456789, 3.123456789);
    part2->addPoint(4.123456789, 1.123456789);
    partCollection->addPart(part2);
    
    polygonBuilder->setParts(partCollection);
    
    Polygon multipartPolygon = polygonBuilder->toPolygon();

    Relevant samples:

    • Add graphics with renderer: A renderer allows you to change the style of all graphics in a graphics overlay by referencing a single symbol style.

    Member Function Documentation

    [explicit] PolygonBuilder::PolygonBuilder(const Esri::ArcGISRuntime::SpatialReference &spatialReference, QObject *parent = nullptr)

    Creates a new empty polygon builder with the specified SpatialReference.

    • spatialReference - The builder's spatial reference.
    • parent - The optional parent QObject.

    The SpatialReference cannot be changed after instantiation.

    See also GeometryBuilder::hasCurves.

    [explicit] PolygonBuilder::PolygonBuilder(const Esri::ArcGISRuntime::Polygon &polygon, QObject *parent = nullptr)

    Creates a new polygon builder by copying the parts from the specified Polygon.

    • polygon - A polygon used to initialize the new builder.
    • parent - The optional parent QObject.

    The SpatialReference of the new polygon builder will match that of the given Polygon. Use this constructor in workflows that create a modified version of an existing geometry. Polygons with curves are supported.

    See also GeometryBuilder::hasCurves.

    [override virtual] PolygonBuilder::~PolygonBuilder()

    Destructor.

    [override virtual] Esri::ArcGISRuntime::GeometryBuilderType PolygonBuilder::geometryBuilderType() const

    Reimplements: GeometryBuilder::geometryBuilderType() const.

    Returns the GeometryBuilderType of this builder.

    [override virtual] Esri::ArcGISRuntime::Geometry PolygonBuilder::toGeometry() const

    Reimplements: GeometryBuilder::toGeometry() const.

    Returns the Polygon geometry this builder is constructing or modifying.

    Esri::ArcGISRuntime::Polygon PolygonBuilder::toPolygon() const

    Returns the Polygon geometry this builder is constructing or modifying.

    This is a convenience method to avoid casting the return value.

    Esri::ArcGISRuntime::Polyline PolygonBuilder::toPolyline() const

    Returns a polyline with the values in the polygon builder.

    Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

    You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

    Your ArcGIS portal

    Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

    Your ArcGIS Location Platform dashboard

    Manage billing, monitor service usage, and access additional resources.

    Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

    Close