Class SpatialReference
- java.lang.Object
-
- com.esri.arcgisruntime.geometry.SpatialReference
-
- All Implemented Interfaces:
JsonSerializable
public final class SpatialReference extends Object implements JsonSerializable
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. TheisGeographic()
method returns true for spatial references with a geographic coordinate system. - Projected coordinate systems use a flat, two-dimensional surface to define locations on the earth. Coordinates
are defined using
linear
units such as meters or miles. TheisProjected()
method returns true for spatial references with a projected coordinate system.
Use the
create(int)
constructor to create a SpatialReference by specifying the WKID of a coordinate system, or use the static members ofSpatialReferences
to return instances of the most commonly-used SpatialReferences.A SpatialReference can also include a vertical coordinate system, that can be set when you create a projected or geographic coordinate system by using the
create(int, int)
constructor.For more information about spatial references, see the 'Fundamentals' > 'Spatial references' topic in the Guide.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SpatialReference
create(int wkid)
Creates a new spatial reference from the given well-known ID (WKID) number.static SpatialReference
create(int wkid, int verticalWkid)
Creates a new spatial reference with the given well-known ID (WKID) numbers for both a horizontal and a vertical coordinate system.static SpatialReference
create(String wkText)
Creates a new spatial reference from the given well-known text (WKT) string.boolean
equals(Object obj)
static SpatialReference
fromJson(String json)
Creates a SpatialReference instance from a JSON string.SpatialReference
getBaseGeographic()
Gets the underlying geographic coordinate system of this spatial reference.double
getConvergenceAngle(Point point)
Gets the calculated grid convergence angle for a given point, which is the angle between True North and Grid North.Unit
getUnit()
Gets the units of measurement defined by this instance.Map<String,Object>
getUnknownJson()
SpatialReferences never have any unknown JSON so this returns an empty Map.Map<String,Object>
getUnsupportedJson()
SpatialReferences never have any unsupported JSON so this returns an empty Map.LinearUnit
getVerticalUnit()
Gets the unit of measure for the vertical coordinate system of this spatial reference.int
getVerticalWkid()
Gets the well-known ID (WKID) number of the vertical coordinate system of this instance.int
getWkid()
Gets the well-known ID (WKID) number of this instance.String
getWKText()
Gets the well-known text (WKT) representation of this instance.int
hashCode()
boolean
hasVertical()
Indicates if this instance has a vertical coordinate system set.boolean
isGeographic()
Indicates if this instance represents a geographic coordinate system.boolean
isPannable()
Indicates if an ArcGISMap with this SpatialReference can be continuously horizontally pannable.boolean
isProjected()
Indicates if this instance represents a projected coordinate system.String
toJson()
Serializes this object to a JSON string.
-
-
-
Method Detail
-
create
public static SpatialReference create(int wkid)
Creates a new spatial reference from the given well-known ID (WKID) number.The WKID refers to a specific coordinate system. WKIDs are defined by standards bodies or organizations. ArcGIS supports a variety of WKIDs, typically those defined by the European Petroleum Survey Group (EPSG) or Esri, as well as a few other commonly used IDs.
SpatialReferences can also be created from a well-known text (WKT) string using
create(String)
. Alternatively, use the static methods onSpatialReferences
to return instances of the most commonly-used SpatialReferences.- Parameters:
wkid
- the WKID number of the required SpatialReference- Returns:
- a SpatialReference with the given WKID number
- Since:
- 100.0.0
- See Also:
getWkid()
-
create
public static SpatialReference create(String wkText)
Creates a new spatial reference from the given well-known text (WKT) string.WKTs are full-text definitions of all of the parameters that specify a spatial reference.
SpatialReferences can also be created from a well-known ID (WKID number) string using
create(int)
. Alternatively, use the static methods onSpatialReferences
to return instances of the most commonly-used SpatialReferences.- Parameters:
wkText
- a string containing a well-known text representation of a SpatialReference- Returns:
- a SpatialReference based on the given WKT string
- Since:
- 100.0.0
- See Also:
getWKText()
-
create
public static SpatialReference create(int wkid, int verticalWkid)
Creates a new spatial reference with the given well-known ID (WKID) numbers for both a horizontal and a vertical coordinate system. Vertical coordinate systems are not spatial references themselves, but control how z values are displayed.- Parameters:
wkid
- the WKID number of the required horizontal SpatialReferenceverticalWkid
- the WKID number of the required vertical SpatialReference- Returns:
- a SpatialReference with the given WKID numbers
- Since:
- 100.0.0
- See Also:
getWkid()
,getVerticalWkid()
-
fromJson
public static SpatialReference fromJson(String json)
Creates a SpatialReference instance from a JSON string.- Parameters:
json
- a JSON string that represents a SpatialReference- Returns:
- a SpatialReference instance
- Throws:
IllegalArgumentException
- if json is null or empty- Since:
- 100.0.0
-
toJson
public String toJson()
Description copied from interface:JsonSerializable
Serializes this object to a JSON string. Note that unknown JSON is omitted from the serialized string.- Specified by:
toJson
in interfaceJsonSerializable
- Returns:
- a JSON string
-
getUnknownJson
public Map<String,Object> getUnknownJson()
SpatialReferences never have any unknown JSON so this returns an empty Map.- Specified by:
getUnknownJson
in interfaceJsonSerializable
- Returns:
- an empty unmodifiable Map
- Since:
- 100.0.0
-
getUnsupportedJson
public Map<String,Object> getUnsupportedJson()
SpatialReferences never have any unsupported JSON so this returns an empty Map.- Specified by:
getUnsupportedJson
in interfaceJsonSerializable
- Returns:
- an empty unmodifiable Map
- Since:
- 100.0.0
-
getWkid
public int getWkid()
Gets the well-known ID (WKID) number of this instance. WKIDs are unique numbers that refer to a specific predefined coordinate system.- Returns:
- The WKID number of the coordinate system this instance represents. Returns 0 if this instance represents a custom coordinate system, or -1 if it is invalid.
- Since:
- 100.0.0
- See Also:
create(int)
-
getVerticalUnit
public LinearUnit getVerticalUnit()
Gets the unit of measure for the vertical coordinate system of this spatial reference.Is null if
hasVertical()
is false.- Returns:
- the unit of measure for the vertical coordinate system of this spatial reference, or null if none
- Since:
- 100.14.0
-
getVerticalWkid
public int getVerticalWkid()
Gets the well-known ID (WKID) number of the vertical coordinate system of this instance. WKIDs are unique numbers that refer to a specific predefined coordinate system.- Returns:
- The WKID number of the vertical coordinate system this instance represents. Returns 0 if a vertical coordinate system was not set when this instance was created. Returns -1 if an invalid vertical coordinate system was specified.
- Since:
- 100.0.0
- See Also:
getWkid()
,create(int, int)
-
getBaseGeographic
public SpatialReference getBaseGeographic()
Gets the underlying geographic coordinate system of this spatial reference. Intended for use when this spatial reference is a projected coordinate system. If this spatial reference is a geographic coordinate system then a new reference to itself is returned.- Returns:
- the underlying geographic coordinate system
- Since:
- 100.1.0
- See Also:
isGeographic()
,isProjected()
-
hasVertical
public boolean hasVertical()
Indicates if this instance has a vertical coordinate system set.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 (
Point.getZ()
). 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 if it was created usingcreate(int, int)
.getVerticalWkid()
andgetWKText()
provide more information about the specific VCS set on this instance.VCSs are used when projecting geometries using a
HorizontalVerticalTransformation
.- Returns:
- true if this instance has a vertical coordinate system set, false otherwise.
- Since:
- 100.9.0
- See Also:
getVerticalWkid()
-
isGeographic
public boolean isGeographic()
Indicates if this instance represents a geographic coordinate system. Geographic coordinate systems useangular
units to define coordinates.- Returns:
- true if this instance represents a geographic coordinate system, false otherwise
- Since:
- 100.0.0
- See Also:
isProjected()
,getUnit()
-
isProjected
public boolean isProjected()
Indicates if this instance represents a projected coordinate system. Projected coordinate systems uselinear
units to define coordinates.- Returns:
- true if this instance represents a projected coordinate system; false otherwise
- Since:
- 100.0.0
- See Also:
isProjected()
,getUnit()
-
isPannable
public boolean isPannable()
Indicates if an ArcGISMap with this SpatialReference can be continuously horizontally pannable. A continuously pannable spatial reference is one of the requirements for awrap-around map
, where a user is able to continuously pan the map across the anti-meridian (approximately equal to the international date line). Only the two most common coordinate systems are continuously pannable; WGS 1984 (WKID 4326), and Web Mercator Auxilliary Sphere (WKID 102113, 102100, or 3857).- Returns:
- true if continuously horizontally pannable; false otherwise
- Since:
- 100.0.0
- See Also:
GeoView.isWrapAroundEnabled()
,MapView.getWrapAroundMode()
-
getWKText
public String getWKText()
Gets the well-known text (WKT) representation of this instance. WKTs are full-text definitions of all of the parameters that specify a spatial reference.SpatialReferences can be created from a WKT string using
create(String)
.- Returns:
- a string containing a WKT representation of this instance
- Since:
- 100.0.0
-
getUnit
public Unit getUnit()
Gets the units of measurement defined by this instance. The Unit of the SpatialReference of a Geometry or Layer determine the units used by its coordinates.- Returns:
- the units of measurement of this instance
- Since:
- 100.0.0
- See Also:
Unit.getUnitType()
,isGeographic()
,isProjected()
-
getConvergenceAngle
public double getConvergenceAngle(Point point)
Gets the calculated grid convergence angle for a given point, which is the angle between True North and Grid North.This value 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.
The grid convergence returned by this method is positive when Grid North lies east of True North, following the Gauss-Bomford convention. The formula
bearing = azimuth - convergence
can be used to obtain a bearing from an azimuth using the grid convergence.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
- Parameters:
point
- the point at which to calculate the convergence. If this point has a different spatial reference, it will be reprojected to this spatial reference; if the spatial reference is null, the point is assumed to already be defined in this spatial reference.- Returns:
- the convergence angle in degrees. Returns 0 if this spatial reference represents a geographic coordinate
system (
isGeographic()
is true). ReturnsDouble.NaN
if the point lies outside this spatial reference's horizon. - Throws:
IllegalArgumentException
- if point is null- Since:
- 100.3.0
-
-