# 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: | JsonSerializable |

## Public Functions

SpatialReference() | |

SpatialReference(const QString &wktext) | |

SpatialReference(int wkid) | |

SpatialReference(int wkid, int verticalWkid) | |

SpatialReference(const SpatialReference &other) | |

SpatialReference(SpatialReference &&other) | |

~SpatialReference() | |

SpatialReference | baseGeographic() const |

double | convergenceAngle(const Point &point) const |

bool | isEmpty() const |

bool | isGeographic() const |

bool | isPannable() const |

bool | isProjected() const |

Unit | unit() const |

int | verticalWkid() const |

QString | wkText() const |

int | wkid() const |

bool | operator!=(const SpatialReference &other) const |

SpatialReference & | operator=(const SpatialReference &other) |

SpatialReference & | operator=(SpatialReference &&other) |

bool | operator==(const SpatialReference &other) const |

## Reimplemented Public Functions

virtual QString | toJson() const |

virtual QJsonObject | unknownJson() const |

virtual QJsonObject | unsupportedJson() const |

- 3 public functions inherited from Esri::ArcGISRuntime::JsonSerializable

## Static Public Members

SpatialReference | fromJson(const QString &json) |

SpatialReference | webMercator() |

SpatialReference | wgs84() |

## Detailed Description

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

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()

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.

### 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(int *wkid*)

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

Tolerance is set to 0.0.

### 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(const SpatialReference &*other*)

Copy constructor from *other* SpatialReference.

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

Move constructor from *other* SpatialReference.

### SpatialReference::~SpatialReference()

Destructor.

### SpatialReference SpatialReference::baseGeographic() const

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

### double SpatialReference::convergenceAngle(const 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, it's location will be transformed automatically to the given spatial reference.

This function was introduced in Esri::ArcGISRuntime 100.3.

`[static] `

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

Creates a new SpatialReference from an ArcGIS JSON representation.

*json*- The JSON text.

### 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.

`[virtual] `

QString SpatialReference::toJson() const

Reimplemented from JsonSerializable::toJson().

Returns this SpatialReference as an ArcGIS json SpatialReference representation.

### Unit SpatialReference::unit() const

Returns the unit from a spatial reference.

Returns a null Unit if the spatial reference is invalid.

`[virtual] `

QJsonObject SpatialReference::unknownJson() const

Reimplemented from JsonSerializable::unknownJson().

Gets the unknown JSON of this object.

**See also **JsonSerializable.

`[virtual] `

QJsonObject SpatialReference::unsupportedJson() const

Reimplemented from JsonSerializable::unsupportedJson().

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 `-1`

if no vertical WKID has been specified.

`[static] `

SpatialReference SpatialReference::webMercator()

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

`[static] `

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 `-1`

if no WKID has been specified.

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

Inequality operator. Returns `true`

if this object and *other* are not equal.

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

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

Assignment operator from *other* SpatialReference.

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

Move operator from *other* SpatialReference.

### bool SpatialReference::operator==(const 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.