# Geometry Class

Base class for classes that represent geometric shapes. More...

Header: | #include <Geometry> |

Since: | Esri::ArcGISRuntime 100.0 |

Inherits: | Esri::ArcGISRuntime::JsonSerializable |

Inherited By: | Esri::ArcGISRuntime::Envelope, Esri::ArcGISRuntime::Multipart, Esri::ArcGISRuntime::Multipoint, and Esri::ArcGISRuntime::Point |

This class was introduced in Esri::ArcGISRuntime 100.0.

## Public Functions

Geometry(Esri::ArcGISRuntime::Geometry &&other) | |

Geometry(const Esri::ArcGISRuntime::Geometry &other) | |

Geometry() | |

Esri::ArcGISRuntime::Geometry & | operator=(Esri::ArcGISRuntime::Geometry &&other) |

Esri::ArcGISRuntime::Geometry & | operator=(const Esri::ArcGISRuntime::Geometry &other) |

virtual | ~Geometry() override |

int | dimension() const |

bool | equalsWithTolerance(const Esri::ArcGISRuntime::Geometry &other, double tolerance) const |

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

Esri::ArcGISRuntime::GeometryType | geometryType() const |

bool | hasCurves() const |

bool | hasM() const |

bool | hasZ() const |

bool | isEmpty() const |

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

bool | operator==(const Esri::ArcGISRuntime::Geometry &other) const |

## Reimplemented Public Functions

virtual QString | toJson() const override |

virtual QJsonObject | unknownJson() const override |

virtual QJsonObject | unsupportedJson() const override |

## Static Public Members

Esri::ArcGISRuntime::Geometry | fromJson(const QString &json) |

## Detailed Description

Geometry is the base class for two-dimensional (x,y) or three-dimensional (x,y,z) geometries, such as Point and Polyline objects. Objects that inherit from the Geometry class may also include an m (measure) value for each vertex. The Geometry class provides functionality common to all types of geometry. Point, Multipoint, Polyline, Polygon, and Envelope all inherit from Geometry and represent different types of shapes.

Geometries are used throughout the API, for example to define the shape of a feature or graphic, the extent of a layer, or as inputs and outputs of different types of tasks. Geometry examples include features created to be stored in a geodatabase or read from a non-editable layer, and features returned from tasks such as a spatial query, geocode operation, network trace, or geoprocessing task.

### Immutability

Geometries are immutable, which offers important benefits. For example, they are inherently thread-safe, help prevent inadvertent changes, and allow for certain performance optimizations. Instead of changing the properties of existing geometries, you can create and update geometries using the various subclasses of GeometryBuilder (for example, PolygonBuilder), which can represent the state of a geometry under construction while allowing modifications, thus enabling editing workflows.

Additionally, GeometryEngine offers a range of topological and relational operations and spatial transformations that read the content of existing geometries and create new geometries, for example, project, move, scale, rotate, buffer, union, and so on.

### Spatial reference

The coordinates that define a geometry only have meaning in the context of the Geometry's SpatialReference. The vertices and the spatial reference together allow your app to translate a real-world object from its location on Earth to its location on your map or scene.

In some cases, a geometry's spatial reference may not be set. For example, a Graphic that does not have a spatial reference is drawn using the same spatial reference as the MapView to which it was added. If the coordinates are in a different SpatialReference, the graphics may not display in the correct location, or at all.

When using a GeometryBuilder to create a Polyline or Polygon from a collection of Point, you don't need to set the spatial reference of every point before you add it to the builder, because as it will be assigned the spatial reference of the builder itself. In most other cases, such as when using a geometry in geometry operations or when editing a feature table, Geometry::spatialReference must be set.

### Spatial reference and projection

Changing the coordinates of a geometry to have the same shape and location represented using a different SpatialReference is known as "projection" or sometimes as "reprojection". Because geometries are immutable, they do not have any member methods that project, transform, or otherwise modify their content.

GeometryEngine, however, provides a wide range of methods that read the content of geometries and modify that content to create new geometries. There are methods to GeometryEngine::project, GeometryEngine::moveGeodetic, GeometryEngine::cut, GeometryEngine::densify, and GeometryEngine::generalize geometries.

### Dimension

Every non-empty Geometry has an inherent dimension (sometimes called the topological dimensionality) that indicates the general class of the Geometry.

`0`

- points and multipoints`1`

- lines and polylines`2`

- polygons and envelopes`3`

- objects with volume

### Serializing to JSON

Geometry can be serialized and de-serialized to and from JSON. The ArcGIS REST API documentation describes the JSON representation of geometry objects. You can use this encoding and decoding mechanism to exchange geometries with REST Web services or to store them in text files.

Valid polygons have at least three vertices, and valid polylines, two vertices. When there are not enough of them, JSON serialization copies existing vertices to reach the minimum vertex count. This results in invalid (degenerate) geometries that can be parsed as the valid JSON for those geometry types.

**See also **GeometryBuilder and GeometryEngine.

## Member Function Documentation

### Geometry::Geometry(Esri::ArcGISRuntime::Geometry &&*other*)

Move constructor from *other* Geometry.

### Geometry::Geometry(const Esri::ArcGISRuntime::Geometry &*other*)

Copy constructor from *other* Geometry.

### Geometry::Geometry()

Default constructor. Creates an empty Geometry.

### Esri::ArcGISRuntime::Geometry &Geometry::operator=(Esri::ArcGISRuntime::Geometry &&*other*)

Move operator from *other* Geometry.

### Esri::ArcGISRuntime::Geometry &Geometry::operator=(const Esri::ArcGISRuntime::Geometry &*other*)

Assignment operator from *other* Geometry.

`[override virtual] `

Geometry::~Geometry()

Destructor.

### int Geometry::dimension() const

Returns the topological dimensionality.

Every non-empty Geometry has an inherent dimension (sometimes called the topological dimensionality) that indicates the general class of the Geometry.

`0`

- points and multipoints`1`

- lines and polylines`2`

- polygons and envelopes`3`

- objects with volume

### bool Geometry::equalsWithTolerance(const Esri::ArcGISRuntime::Geometry &*other*, double *tolerance*) const

Returns whether this object and *other* are equal within the *tolerance*.

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

Returns the smallest rectangular bounding-box that covers the geometry.

`[static] `

Esri::ArcGISRuntime::Geometry Geometry::fromJson(const QString &*json*)

Creates this geometry from an ArcGIS json geometry representation.

Returns a Geometry created using the data in the *json* parameter.

### Esri::ArcGISRuntime::GeometryType Geometry::geometryType() const

Gets the geometry type.

Returns the geometry type enumeration.

### bool Geometry::hasCurves() const

Returns `true`

if this geometry has curves.

### bool Geometry::hasM() const

Returns `true`

if this geometry contains m-values (measure values).

### bool Geometry::hasZ() const

Returns `true`

if this geometry contains z-coordinate values.

Only 3D geometries contain z-coordinate values.

### bool Geometry::isEmpty() const

Gets whether this Geometry is empty.

A Geometry is empty if it does not contain any valid geographic coordinates. If a SpatialReference was specified, but still no valid coordinates exist, then the Geometry is still empty.

Returns `true`

if empty.

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

Gets the SpatialReference of the Geometry.

Returns the spatial reference of the coordinates assigned to the Geometry.

`[override virtual] `

QString Geometry::toJson() const

Reimplements: JsonSerializable::toJson() const.

Converts a geometry into an ArcGIS json geometry representation.

Returns this Geometry represented as a JSON String.

`[override virtual] `

QJsonObject Geometry::unknownJson() const

Reimplements: JsonSerializable::unknownJson() const.

Gets the unknown JSON of this object.

**See also **JsonSerializable.

`[override virtual] `

QJsonObject Geometry::unsupportedJson() const

Reimplements: JsonSerializable::unsupportedJson() const.

Gets the unsupported JSON of this object.

**See also **JsonSerializable.

### bool Geometry::operator==(const Esri::ArcGISRuntime::Geometry &*other*) const

Equivalency operator.

Returns whether this object and *other* are equivalent.