SpatialReference

require(["esri/geometry/SpatialReference"], function(SpatialReference) { /* code goes here */ });
Class: esri/geometry/SpatialReference
Inheritance: SpatialReference Accessor
Since: ArcGIS API for JavaScript 4.0

Defines the spatial reference of a view, layer, or task parameters. This indicates the Projected Coordinate System or the Geographic Coordinate System used to locate geographic features in the map. Each projected and geographic coordinate system is defined by either a well-known ID (WKID) or a definition string (WKT). Note that for versions prior to ArcGIS 10, only WKID was supported. For a full list of supported spatial reference IDs and their corresponding definition strings, see the links below.

See also:

Constructors

new SpatialReference(properties)
Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
NameTypeSummaryClass
String

The name of the class.

more details
more detailsAccessor
Object

An image coordinate system defines the spatial reference used to display the image in its original coordinates without distortion, map transformations or ortho-rectification.

more details
more detailsSpatialReference
Boolean

Indicates if the spatial reference refers to a geographic coordinate system.

more details
more detailsSpatialReference
Boolean

Indicates if the wkid of the spatial reference object is one of the following values: 102113, 102100, 3857.

more details
more detailsSpatialReference
Boolean

Indicates if the wkid of the spatial reference object is 4326.

more details
more detailsSpatialReference
Boolean

Indicates if the spatial reference of the map supports wrapping around the International Date Line.

more details
more detailsSpatialReference
SpatialReference

A convenience spatial reference instance for Web Mercator.

more details
more detailsSpatialReference
SpatialReference

A convenience spatial reference instance for WGS84.

more details
more detailsSpatialReference
Number

The well-known ID of a spatial reference.

more details
more detailsSpatialReference
String

The well-known text that defines a spatial reference.

more details
more detailsSpatialReference

Property Details

declaredClass Stringreadonly inherited
Since: ArcGIS API for JavaScript 4.7

The name of the class. The declared class name is formatted as esri.folder.className.

imageCoordinateSystem Object
Since: ArcGIS API for JavaScript 4.13

An image coordinate system defines the spatial reference used to display the image in its original coordinates without distortion, map transformations or ortho-rectification. Typically, ImageryLayer is displayed in the spatialReference of the view. In some cases, converting images into map coordinates can cause your images to look skewed or distorted because of the various transformations and terrain corrections that are used. Since there is no distortion with images in the image coordinate system, it is ideal for using with oblique imagery and mensuration.

The image can be displayed in its original coordinates only in 2D MapView with a top-uprotation which is always oriented in the look of direction of the dataset. This works similarly to an in-car navigation system where the choices are often either north is at the top of the screen (therefore, not using a top up option) or the screen rotates so the travel direction is always displayed at the top.

See also:
Example:
// get image coordinate system of the specified catalog item
// for example Raster.OBJECTID = 1600
layer.getCatalogItemICSInfo(imageId).then(function(info) {
// create a spatialReference object and set its
// imageCoordinateSystem property
 var sr = { // autocasts to esri/geometry/SpatialReference
   imageCoordinateSystem: { id: imageId }
 };

 // Calculate an extent for the mapview based on the image's extent
 // in its original coordinate system
 const width = document.getElementById("viewDiv").getBoundingClientRect().width;
 const height = document.getElementById("viewDiv").getBoundingClientRect().height;
 const newExt = info.icsExtent.clone();
 const scaleFactor = 5;
 newExt.xmin = (newExt.xmin + newExt.xmax - width * scaleFactor) / 2;
 newExt.xmax = newExt.xmin + width * scaleFactor;
 newExt.ymin = (newExt.ymin + newExt.ymax - height * scaleFactor) / 2;
 newExt.ymax = newExt.ymin + height * scaleFactor;
 newExt.spatialReference = sr;

 // set the MapView's spatialReference to the image's coordinate system
 // and the extent to the extent calculated above
 view = new MapView({
   container: "viewDiv",
   map: map,
   spatialReference: sr,
   extent: newExt
 });
});
isGeographic Booleanreadonly

Indicates if the spatial reference refers to a geographic coordinate system.

isWebMercator Booleanreadonly

Indicates if the wkid of the spatial reference object is one of the following values: 102113, 102100, 3857.

isWGS84 Booleanreadonly

Indicates if the wkid of the spatial reference object is 4326.

isWrappable Booleanreadonly

Indicates if the spatial reference of the map supports wrapping around the International Date Line. Value is true if the spatial reference is Web Mercator or WGS84.

WebMercator SpatialReferencestatic

A convenience spatial reference instance for Web Mercator.

Example:
// returns true if the webMercatorUtils can
// project geometries from WGS84 to Web Mercator
var canProjectWGS84toWebMercator = webMercatorUtils.canProject(SpatialReference.WGS84, SpatialReference.WebMercator);
WGS84 SpatialReferencestatic

A convenience spatial reference instance for WGS84.

Example:
// returns true if the webMercatorUtils can
// project geometries from WGS84 to Web Mercator
var canProjectWGS84toWebMercator = webMercatorUtils.canProject(SpatialReference.WGS84, SpatialReference.WebMercator);
wkid Number

The well-known ID of a spatial reference. See Projected Coordinate Systems and Geographic Coordinate Systems for the list of supported spatial references.

wkt String

The well-known text that defines a spatial reference.

Method Overview

NameReturn TypeSummaryClass
SpatialReference

Returns a deep clone of the spatial reference object.

more details
more detailsSpatialReference
Boolean

Checks if the specified spatial reference object has the same wkid or wkt as this spatial reference object.

more details
more detailsSpatialReference
*

Creates a new instance of this class and initializes it with values from a JSON object generated from a product in the ArcGIS platform.

more details
more detailsSpatialReference
Object

Converts an instance of this class to its ArcGIS portal JSON representation.

more details
more detailsSpatialReference

Method Details

Returns a deep clone of the spatial reference object.

Returns:
TypeDescription
SpatialReferenceReturns a deep clone of the spatial reference object.
equals(spatialReference){Boolean}

Checks if the specified spatial reference object has the same wkid or wkt as this spatial reference object.

Parameter:
spatialReference SpatialReference

The spatial reference to compare to.

Returns:
TypeDescription
BooleanReturns true if the input spatial reference object has the same wkid or wkt as this spatial reference object.
Example:
require(["esri/geometry/SpatialReference"], function(SpatialReference) {
  const sr1 = new SpatialReference({ wkid: 4326 });
  const sr2 = new SpatialReference({ wkid: 4326 });
  console.log(sr1.equals(sr2)); // true
});
fromJSON(json){*}static

Creates a new instance of this class and initializes it with values from a JSON object generated from a product in the ArcGIS platform. The object passed into the input json parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.

Parameter:
json Object

A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.

Returns:
TypeDescription
*Returns a new instance of this class.
toJSON(){Object}

Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() topic in the Guide for more information.

Returns:
TypeDescription
ObjectThe ArcGIS portal JSON representation of an instance of this class.

API Reference search results

NameTypeModule
Loading...