# GeometryBuilder Class

Base class for classes used to create immutable geometries. More...

Header: | #include <GeometryBuilder> |

Since: | Esri::ArcGISRuntime 100.0 |

Inherits: | Esri::ArcGISRuntime::Object |

Inherited By: | Esri::ArcGISRuntime::EnvelopeBuilder, Esri::ArcGISRuntime::MultipartBuilder, Esri::ArcGISRuntime::MultipointBuilder, and Esri::ArcGISRuntime::PointBuilder |

This class was introduced in Esri::ArcGISRuntime 100.0.

## Public Functions

virtual | ~GeometryBuilder() override |

Esri::ArcGISRuntime::Envelope | extent() const |

virtual Esri::ArcGISRuntime::GeometryBuilderType | geometryBuilderType() const |

bool | hasM() const |

bool | hasZ() const |

bool | isEmpty() const |

bool | isSketchValid() const |

void | replaceGeometry(const Esri::ArcGISRuntime::Geometry &geometry) |

Esri::ArcGISRuntime::SpatialReference | spatialReference() const |

virtual Esri::ArcGISRuntime::Geometry | toGeometry() const |

## Static Public Members

Esri::ArcGISRuntime::GeometryBuilder * | create(const Esri::ArcGISRuntime::Geometry &geometry, QObject *parent = nullptr) |

Esri::ArcGISRuntime::GeometryBuilder * | create(Esri::ArcGISRuntime::GeometryType geometryType, const Esri::ArcGISRuntime::SpatialReference &spatialReference, QObject *parent = nullptr) |

## Detailed Description

Each type of Geometry has a corresponding builder class. For example, PolygonBuilder creates Polygons. Create a new empty builder in order to build up the shape of a geometry step by step. Alternatively for editing workflows, initialize the builder by passing the existing Geometry to be edited into the builder constructor, and then make the required changes. In both cases, call toGeometry to return a new immutable Geometry based on the current state of the geometry in the builder. The state of a builder can be completely overwritten by calling replaceGeometry.

Set the spatial reference of a builder either explicitly by specifying a SpatialReference object in the constructor, or is set implicitly from other constructor arguments. Once set, the spatial reference cannot be changed. When building geometries, the spatial reference of any objects or coordinates added to the builder must be compatible with the spatial reference of the builder; added items are not reprojected. The spatial reference of added objects may be null, in which case the added object is assumed to have the same spatial reference as the builder it is added to.

A number of other methods provide information about the geometry currently being constructed. A new builder will be empty (isEmpty is true). The hasZ and hasM methods indicate if the builder allows adding z and m-values for each coordinate in the geometry.

## Member Function Documentation

`[override virtual] `

GeometryBuilder::~GeometryBuilder()

Destructor.

`[static] `

Esri::ArcGISRuntime::GeometryBuilder *GeometryBuilder::create(const Esri::ArcGISRuntime::Geometry &*geometry*, QObject **parent* = nullptr)

Creates and returns a geometry builder from a geometry.

*geometry*- The geometry to be used as the starting point for further modifications.*parent*- An optional parent.

This function was introduced in Esri::ArcGISRuntime 100.1.

`[static] `

Esri::ArcGISRuntime::GeometryBuilder *GeometryBuilder::create(Esri::ArcGISRuntime::GeometryType *geometryType*, const Esri::ArcGISRuntime::SpatialReference &*spatialReference*, QObject **parent* = nullptr)

Creates and returns a geometry builder from a geometry type and spatial reference.

*geometryType*- The geometry type of the builder.*spatialReference*- The spatial reference of the builder.*parent*- An optional parent.

This function was introduced in Esri::ArcGISRuntime 100.1.

### Esri::ArcGISRuntime::Envelope GeometryBuilder::extent() const

Returns the extent of the builder's geometry.

`[virtual] `

Esri::ArcGISRuntime::GeometryBuilderType GeometryBuilder::geometryBuilderType() const

Returns the type of this geometry builder.

### bool GeometryBuilder::hasM() const

Returns whether the builder's geometry contains m-values.

### bool GeometryBuilder::hasZ() const

Returns whether the builder's geometry contains z-coordinate values.

### bool GeometryBuilder::isEmpty() const

Returns whether the builder's geometry is empty.

### bool GeometryBuilder::isSketchValid() const

Returns whether the builder's geometry contains sufficient points to show a valid graphical sketch.

This can be used as an initial lightweight check to see if the current state of a builder will produce a non-empty geometry; for example, it may be used to enable or disable functionality in an editing user interface. The exact requirements vary depending on the type of geometry produced by the builder:

- A PointBuilder must contain non-NaN x,y coordinates.
- A MultipointBuilder must contain at least one valid Point.
- A PolylineBuilder must contain at least two valid Points in each Part, and at least one part.
- A PolygonBuilder must contain at least three valid Points in each Part, and at least one part.
- An EnvelopeBuilder must contain non-NaN minimum and maximum x and y values.

Note that this is not equivalent to topological simplicity, which is enforced by GeometryEngine::simplify and checked using GeometryEngine::isSimple. Geometries must be topologically simple to be successfully saved in a geodatabase, or used in some service operations.

Prior to release version 100.8, only one part of a multipart polygon or polyline was required to have the minimum number (2 for a polyline, 3 for a polygon) of points.

### void GeometryBuilder::replaceGeometry(const Esri::ArcGISRuntime::Geometry &*geometry*)

Replaces the content of an existing *geometry* with the geometry in this builder.

An empty Geometry may be passed to reset the builder's geometry. Note that this won't change the SpatialReference.

### Esri::ArcGISRuntime::SpatialReference GeometryBuilder::spatialReference() const

The spatial reference associated with the builder's geometry.

`[virtual] `

Esri::ArcGISRuntime::Geometry GeometryBuilder::toGeometry() const

Returns the geometry this builder is constructing or modifying.