# SpatialReference Class

A spatial reference that defines how coordinates correspond to locations in the real world. More...

Header: | #include <SpatialReference> |

Since: | Esri::ArcGISRuntime 100.0 |

Inherits: | Esri::ArcGISRuntime::JsonSerializable |

This class was introduced in Esri::ArcGISRuntime 100.0.

## Public Functions

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

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

SpatialReference(int wkid, int verticalWkid) | |

SpatialReference(int wkid) | |

SpatialReference(const QString &wktext) | |

SpatialReference() | |

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

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

virtual | ~SpatialReference() override |

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

double | convergenceAngle(const Esri::ArcGISRuntime::Point &point) const |

bool | hasVertical() const |

bool | isEmpty() const |

bool | isGeographic() const |

bool | isPannable() const |

bool | isProjected() const |

Esri::ArcGISRuntime::Unit | unit() const |

int | verticalWkid() const |

QString | wkText() const |

int | wkid() const |

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

bool | operator==(const Esri::ArcGISRuntime::SpatialReference &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::SpatialReference | fromJson(const QString &json) |

Esri::ArcGISRuntime::SpatialReference | webMercator() |

Esri::ArcGISRuntime::SpatialReference | wgs84() |

## Detailed Description

Instances of this class represent a specific coordinate system, identified by a well-known ID (WKID) number or well-known text (WKT) string. SpatialReferences are immutable.

SpatialReferences allow disparate spatial data to be consistently viewed and analyzed together. Geometry, Layer, and GraphicsOverlay classes have a SpatialReference that determines the system in which the data is stored, and the SpatialReference of each GeoView determines how it displays the data it contains. There are two main categories of coordinate system that can be represented by a SpatialReference:

- Geographic coordinate systems use a three-dimensional spherical surface to define locations on the earth. Coordinates are defined using angular units such as degrees.
- Projected coordinate systems use flat, two-dimensional surface to define locations on the earth. Coordinates are defined using linear units such as meters or miles.

In some cases, more than one WKID value can refer to the same spatial reference. For example, 3857 and 102100 both refer to WGS 1984 Web Mercator (Auxiliary Sphere). There can also be subtle differences between two WKT strings that represent the same spatial reference. To mitigate this situation, the SpatialReference class provides spatial reference comparison methods.

Use the Create method to create a SpatialReference by specifying the WKID of a coordinate system, or use the members of SpatialReferences to return instances of the most commonly used SpatialReferences.

See Projected Coordinate Systems and Geographic Coordinate Systems for the list of supported spatial references and their corresponding definition strings.

## Member Function Documentation

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

Move constructor from *other* SpatialReference.

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

Copy constructor from *other* SpatialReference.

### SpatialReference::SpatialReference(int *wkid*, int *verticalWkid*)

Constructor using a *wkid* (well-known ID) that represents the spatial reference and a *verticalWkid* (vertical coordinate system well-known ID).

### SpatialReference::SpatialReference(int *wkid*)

Constructor using a *wkid* (well-known ID) that represents the spatial reference.

Tolerance is set to 0.0.

### SpatialReference::SpatialReference(const QString &*wktext*)

Constructor using a *wktext* (well-known text string) that represents the spatial reference.

The wkid property is also initialized based on the provided *wktext*. You can use a *wktext* extracted from another SpatialReference. If the *wktext* parameter is a null or empty string, this method creates an empty SpatialReference.

### SpatialReference::SpatialReference()

Default constructor. Constructs an empty SpatialReference object.

The WKID and vertical WKID are set to -1 and the WKT is set to an empty string.

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

Move operator from *other* SpatialReference.

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

Assignment operator from *other* SpatialReference.

`[override virtual] `

SpatialReference::~SpatialReference()

Destructor.

### Esri::ArcGISRuntime::SpatialReference SpatialReference::baseGeographic() const

Returns the base geographic coordinate system if this is a projected coordinate system.

### double SpatialReference::convergenceAngle(const Esri::ArcGISRuntime::Point &*point*) const

Returns the grid convergence in degrees for a spatial reference at a given *point*.

The grid convergence is the angle between True North and Grid North at a point on a map. The grid convergence can be used to convert a horizontal direction expressed as an azimuth in a geographic coordinate system (relative to True North) to a direction expressed as a bearing in a projected coordinate system (relative to Grid North), and vice versa.

**Sign convention**

The grid convergence returned by this method is positive when Grid North lies east of True North. The following formula demonstrates how to obtain a bearing (b) from an azimuth (a) using the grid convergence (c) returned by this method:

`b = a - c`

This sign convention is sometimes named the Gauss-Bomford convention.

**Other notes**

- Returns
`0`

if the spatial reference is a geographic coordinate system. - Returns
`NAN`

if the point is outside the projection's horizon or on error. - If the point has no spatial reference, it is assumed to be in the given spatial reference.
- If the point's spatial reference differs from the spatial reference given, its location will be transformed automatically to the given spatial reference.

This function was introduced in Esri::ArcGISRuntime 100.3.

`[static] `

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

Creates a new SpatialReference from an ArcGIS JSON representation.

*json*- The JSON text.

### bool SpatialReference::hasVertical() const

Returns `true`

if spatial reference has a vertical coordinate system set; `false`

otherwise.

A spatial reference can optionally include a definition for a vertical coordinate system (VCS), which can be used to interpret the z-values of a geometry. A VCS defines linear units of measure, the origin of z-values, and whether z-values are "positive up" (representing heights above a surface) or "positive down" (indicating that values are depths below a surface).

A SpatialReference may have a VCS set, for example by calling the SpatialReference::SpatialReference(int, int) constructor. SpatialReference::verticalWkid and SpatialReference::wkText provide more information about the specific VCS set on this instance.

VCSs are used when projecting geometries using a HorizontalVerticalTransformation.

This function was introduced in Esri::ArcGISRuntime 100.9.

**See also **SpatialReference::verticalWkid.

### bool SpatialReference::isEmpty() const

Returns `true`

if this SpatialReference is empty.

### bool SpatialReference::isGeographic() const

Returns `true`

if this is a geographic coordinate system.

### bool SpatialReference::isPannable() const

Returns `true`

if this SpatialReference supports wrap around.

### bool SpatialReference::isProjected() const

Returns `true`

if this SpatialReference is a projected coordinate system.

`[override virtual] `

QString SpatialReference::toJson() const

Reimplements: JsonSerializable::toJson() const.

Returns this SpatialReference as an ArcGIS json SpatialReference representation.

### Esri::ArcGISRuntime::Unit SpatialReference::unit() const

Returns the unit from a spatial reference.

Returns a null Unit if the spatial reference is invalid.

`[override virtual] `

QJsonObject SpatialReference::unknownJson() const

Reimplements: JsonSerializable::unknownJson() const.

Gets the unknown JSON of this object.

**See also **JsonSerializable.

`[override virtual] `

QJsonObject SpatialReference::unsupportedJson() const

Reimplements: JsonSerializable::unsupportedJson() const.

Gets the unsupported JSON of this object.

**See also **JsonSerializable.

### int SpatialReference::verticalWkid() const

Returns the vertical coordinate system well-known spatial reference identifier (WKID).

Returns `0`

if no vertical WKID has been specified.

**Note: **In versions prior to Esri::ArcGISRuntime 100.9. This method returned -1 if no vertical WKID had been specified.

`[static] `

Esri::ArcGISRuntime::SpatialReference SpatialReference::webMercator()

Returns a spatial reference representing the WebMercator coordinate system (WKID:102100)

`[static] `

Esri::ArcGISRuntime::SpatialReference SpatialReference::wgs84()

Returns a spatial reference representing the WGS84 coordinate system (WKID:4326).

### QString SpatialReference::wkText() const

Returns the well-known text representation.

Returns an empty string if no WKT has been specified or if the SpatialReference is invalid.

This method always returns the minimal text representation that uniquely identifies a given SpatialReference.

### int SpatialReference::wkid() const

Returns the well-known spatial reference identifier (WKID).

Returns `0`

if no WKID has been specified.

**Note: **In versions prior to Esri::ArcGISRuntime 100.9. This method returned -1 if no WKID had been specified.

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

Inequality operator. Returns `true`

if this object and *other* are not equal.

**See also **SpatialReference::operator==.

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

Equivalency operator. Returns `true`

if this object and *other* are equal.

This is the only valid way to compare two spatial references. Comparing individual attributes for two objects can return misleading results and should be avoided.