Skip To Content ArcGIS for Developers Sign In Dashboard

PolygonBuilder Class


Helper class for building immutable polygon geometries. More...

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

Public Functions

PolygonBuilder(const SpatialReference &spatialReference, QObject *parent = nullptr)
PolygonBuilder(const Polygon &polygon, QObject *parent = nullptr)
Polygon toPolygon() const
Polyline toPolyline() const

Reimplemented Public Functions

virtual GeometryBuilderType geometryBuilderType() const
virtual Geometry toGeometry() const

Additional Inherited Members

Detailed Description

Helper class for building immutable polygon geometries.

The initial shape stored in the builder can be initialized in the constructors by passing in existing geometries or collections. Change the contents of the shape by using the mutable PartCollection accessible from the parts() getter. Call the toGeometry method to create a new immutable Polygon from the current state of this 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);

// 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);


Polygon multipartPolygon = polygonBuilder->toPolygon();

Member Function Documentation

PolygonBuilder::PolygonBuilder(const SpatialReference &spatialReference, QObject *parent = nullptr)

Constructor that takes a spatialReference and an optional parent.

PolygonBuilder::PolygonBuilder(const Polygon &polygon, QObject *parent = nullptr)

Constructor that takes a polygon and an optional parent.



[virtual] GeometryBuilderType PolygonBuilder::geometryBuilderType() const

Reimplemented from GeometryBuilder::geometryBuilderType().

Returns the GeometryBuilderType of this builder.

[virtual] Geometry PolygonBuilder::toGeometry() const

Reimplemented from GeometryBuilder::toGeometry().

Returns the Polygon geometry this builder is constructing or modifying.

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.

Polyline PolygonBuilder::toPolyline() const

Returns a polyline with the values in the polygon builder.

Feedback on this topic?