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
    PolygonBuilder* 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
    PartCollection* 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();

    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.