Geometries represent real-world objects by defining a shape at a specific geographic location. They are used throughout the API to represent the shapes of features and graphics, layer extents, viewpoints, and GPS locations. They are also used as inputs and outputs of spatial analysis and geoprocessing operations, and to measure distances and areas, among other uses.

The `ArcGISGeometry`

class provides functionality common to all types of geometry. `ArcGISPoint`

, `ArcGISMultipoint`

, `ArcGISPolyline`

, `ArcGISPolygon`

, and `ArcGISEnvelope`

all inherit from the `ArcGISGeometry`

base class, and represent different types of shapes.

The following are common geometry characteristics:

- Geometries have a spatial reference indicating the coordinate system used by its coordinates.
- Geometries can be empty, indicating that they have no specific location or shape.
- Geometries can have Z values and/or M values.
- Geometries can be converted from JSON to be persisted or to be exchanged directly with REST services.

Most geometries are created and not changed for their lifetime. 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. Immutable geometries (geometries that cannot be changed) offer some important benefits to your app. They are inherently thread-safe, they help prevent inadvertent changes, and they allow for certain performance optimizations.

While immutable geometries appear to present problems for editing existing geometries, those problems are solved by using geometry builders. Geometry builders are designed to represent the state of a geometry under construction while allowing modifications, thus enabling editing workflows.

## Point

`ArcGISPoint`

geometries represent a single point, place, or location such as a geocoded house address in a neighborhood or the location of a water meter in a water utility network. Larger geographic entities such as cities can be represented as points on small-scale maps. Points can be used as the geometry of features and graphics and are often used to help construct other geometries.

Points store a single set of X,Y coordinates that represent the coordinates of a location (longitude and latitude for example), and a spatial reference. Optionally, a z value (representing things such as elevation for example) can also be included. Instances of `ArcGISPoint`

can be created using constructors, which define the full geometry in a single call.

## Envelope

`ArcGISEnvelope`

geometries represent rectangular shapes with sides that are parallel with the X or Y axis of the coordinate system. Most commonly, they represent the spatial extent of layers or other geometries, or define areas of interest for tasks. They can be used as the geometry of graphics and in many geometry operations, although they cannot be used as the geometry of features.

New instances of `ArcGISEnvelope`

are defined by specifying a minimum and maximum X coordinate and minimum and maximum Y coordinate, and an `ArcGISSpatial`

. Optionally, a minimum and maximum Z value can be specified to define the depth of the envelope.

## Multipoint

`ArcGISMultipoint`

geometries represent an ordered collection of points. They can be used as the geometry of features and graphics, or as input or output of geometry operations. For features that consist of a very large number of points that share the same set of attribute values, multipoints may be more efficient to store and analyze in a geodatabase compared to using multiple point features.

Multipoints are composed of a single read-only collection of points. To build a multipoint, create an `ArcGISMultipoint`

, add points, and the geometry will return an `ArcGISMultipoint`

.

You can also use geometry builders to modify an existing geometry.

```
MultipointBuilder* multiPointBuilder = new ArcGISMultipointBuilder(ArcGISSpatialReference(4326), this);
PointCollection* pc = new ArcGISMutablePointCollection(ArcGISSpatialReference(4326), this);
pc->addPoint(-169, 34, 2);
pc->addPoint(-171, 32);
pc->addPoint(Point(-175, 50, ArcGISSpatialReference(4326)));
multiPointBuilder->setPoints(pc);
ArcGISMultipoint mPoint(multiPointBuilder->toGeometry());
```

## Polyline

`ArcGISPolyline`

geometries represent the shape and location of linear features, for example, a street in a road network or a pipeline in an oil refinery. They can be used as the geometry of features and graphics, or as input or output of tasks or geoprocessing operations, such as the output of a network trace.

Polylines are composed of a series of connected segments, where each segment defines a continuous line between a start and an end point. You can also work with polylines by using point-based helper methods.

Create an `ArcGISPolyline`

using an `ArcGISPolyline`

. Add points, and this will create a series of straight line segments connecting the points you specified.

Polylines can have multiple parts. Each part is a series of connected segments, but the parts can be disjoint from each other, for example, in a polyline representing a discontinuous highway that has an unfinished section. Parts can also intersect at one or more vertices, for example, in a polyline representing a river and its tributaries. The `ArcGISPolyline`

class inherits from `ArcGISMultipart`

, which provides members for iterating through the segments and points of each part in a polyline. For more information on segments, see Segments on this page.

To modify an existing polyline, use `ArcGISPolyline`

.

```
PolylineBuilder* polylineBuilder = new ArcGISPolylineBuilder(ArcGISSpatialReference(4326), this);
polylineBuilder->addPoint(-160, 34); // x,y-coordinates
polylineBuilder->addPoint(-175, 40, 25); // x,y,z-coordinates
polylineBuilder->addPoint(Point(-182, 36, ArcGISSpatialReference(4326))); // A Point object
ArcGISPolyline pline(polylineBuilder->toGeometry());
```

## Polygon

`ArcGISPolygon`

geometries represent the shape and location of areas, for example, a country or a lake. They can be used as the geometry of features and graphics, or as input or output of tasks or geoprocessing operations, such as the output of a drive-time analysis or a buffer operation.

Polygons are similar to polylines in that they are also composed of a series of connected segments. However, polygons define closed areas, so the end point of the last segment is always in the same location as the start point of the first segment, forming a closed boundary. As with polylines, you can work with the vertices of the segments of a polygon by using point-based helper methods. For more information on segments, see Segments on this page.

To build an `ArcGISPolygon`

, create an `ArcGISPolygon`

and add points in the correct order around the polygon's perimeter. Next, use the `t`

method to provide the `ArcGISPolygon`

.

Similar to polylines, polygons can have multiple parts but have different rules than those for multipart polylines. Each part of a multipart polygon is a series of connected segments forming a closed ring. Each part must not cross any other part but may lie completely inside or outside another part. For example, a polygon representing the state of Hawaii would comprise eight disjoint parts, one representing each island. A polygon representing the country of South Africa, which completely surrounds the enclave of Lesotho, would comprise two parts, one contained inside the other. The `ArcGISPolygon`

class also inherits from `ArcGISMultipart`

.

```
PolygonBuilder* polygonBuilder = new ArcGISPolygonBuilder(ArcGISSpatialReference(4326), this);
polygonBuilder->addPoint(-181, 35);
polygonBuilder->addPoint(-179, 34, 2);
polygonBuilder->addPoint(Point(-179, 35, ArcGISSpatialReference(4326)));
ArcGISPolygon poly(polygonBuilder->toGeometry());
```

## Multipart (Polygon and Polyline)

`ArcGISPolygon`

and `ArcGISPolyline`

inherit from `ArcGISMultipart`

. Multipart provides access to a collection of the geometry's parts. Each part in the collection is a collection of segment objects (see Segments below). You can iterate through the segments or points in each part.

```
for (int i = 0; i < pline.parts().size(); i++)
{
for (int j = 0; j < pline.parts().part(i).points().size(); j++)
{
double x = pline.parts().part(i).point(j).x();
Q_UNUSED(x);
double y = pline.parts().part(i).point(j).y();
Q_UNUSED(y);
}
}
```

You can iterate through the points that represent the vertices in all the parts. In the same way as `ArcGISPolygon`

and `ArcGISPolyline`

are immutable, the collections returned from `ArcGISMultipart`

are also immutable.

### Segments

A segment describes a continuous line between a start location and an end location. Every part in a multipart geometry is a collection of `ArcGISSegment`

s where the end of one segment is at exactly the same location as the start of the following segment. Multipart geometries can be composed from and decomposed into segments if required.

Because a single location is shared by adjacent segments, a single `ArcGISPoint`

object is used to represent the shared location when you iterate through the points in a part. As a result, when iterating through the points in a part of a polyline, there will be one more `ArcGISPoint`

than the number of `ArcGISSegment`

s in that same part.

Similar to the geometries they comprise, `ArcGISSegment`

s are immutable.

## Working with geometry

### Spatial references

The meaning of the coordinates in a geometry is determined by the geometry's spatial reference. The vertices and spatial reference together allow your app to translate a real-world object from its location on the Earth to its location on your map or scene.

In some cases, a geometry's spatial reference may not be set. Graphics that do not have a spatial reference are drawn using the same spatial reference as the map view in which they are drawn. When using a geometry builder to create a polyline or polygon geometry from point geometries, you don't need to set the spatial reference of every point before you add it to the builder, as it will be assigned the spatial reference of the builder it's added to. In most other cases, such as when using a geometry in geometry operations or when editing a feature table, the geometry's spatial reference must be set.

Learn more about spatial references.

### Linear, angular, and area units

Different categories of units of measurement can be used. Projected coordinate systems define coordinates using linear measurements, for example using meters or miles, which are represented by `ArcGISLinear`

. Linear units are also used to return distance measurements, for example by some members of `ArcGISGeometry`

. Geographic coordinate systems define coordinates using angular measurements, for example using degrees or radians, which are represented by `ArcGISAngular`

. Methods that calculate the size of areas, for example in acres or square kilometers, use area units. These are represented by `ArcGISArea`

. Linear, angular, and area units can be defined by using enumerations of the most common units of measurement. They can also be defined by Well-Known ID (WKID) or Well-Known Text (WKT).

### Projection, topological, and other operations

Changing the coordinates of a geometry to represent the same shape and location using a different spatial reference 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.

The `ArcGISGeometry`

class provides a wide range of methods that read the content of geometries and modify that content to create new geometries. There are methods to project, buffer, union, and so on. Note that not all methods support true curves. When creating geometries using locations from the screen, and the map is a wraparound map, you may also need to consider normalizing a geometry before you save it to a geodatabase or use it in tasks or other operations.

Use the `ArcGISGeometry`

class to project geometries to a different spatial reference.

### Converting from JSON

Geometries can be de-serialized from JSON. The Common Data Types 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.

Converting to or from JSON can add points to multipart geometries if the geometry has insufficient points to construct a segment.

### Z values

Geometries can have Z values, indicating values along the Z axis, which is orthogonal to both the X axis and Y axis. Z values can indicate height above or depth below a surface, or an absolute elevation. For example, Z values are used to draw the locations of geometries in scene views. Note that geometries are not considered true 3D shapes and are draped onto surfaces in the view, or in some cases, drawn in a single plane by using Z values. Z values are stored on `ArcGISPoint`

and `ArcGISEnvelope`

. Because all other geometries are created from `ArcGISPoint`

, it is possible for all types of geometry to have Z values.

Whether or not a geometry has Z values is determined when the geometry is created; if you use a method that has a Z value parameter, the new geometry will have Z values (the geometry's `has`

will be true). If you create geometries using constructors that take Z value parameters, or if you pass into the constructor points or segments that have Z values, the new geometry will have Z values. A geometry with Z values is sometimes known as a z-aware geometry.

It may be that not all vertices in your geometry have a Z value defined. `N`

is a valid Z value used to indicate an unknown Z value. However, the default Z value is zero. It is important to note that when you get Z values from a geometry that does not have Z values, the default value of zero is returned. Verify the `has`

property to determine whether a Z value of zero means that there are no Z values in the geometry or that the Z value in the geometry's coordinates is actually zero.

### M values

M values are used in linear referencing scenarios. Like Z values, every geometry can optionally store M values. The default M value is `N`

. If an M value is specified as a parameter when a geometry is created, the new geometry will have M values (the geometry's `has`

will be true). Note that when you get M values back from a geometry, the default value of `N`

(different than the default for Z values) is returned for vertices that do not have M values. A geometry with M values is sometimes known as an m-aware geometry.