import SpatialReference from "@arcgis/core/geometry/SpatialReference.js";const SpatialReference = await $arcgis.import("@arcgis/core/geometry/SpatialReference.js");- Inheritance:
- SpatialReference→
Accessor
- Since
- ArcGIS Maps SDK for JavaScript 4.0
Defines the spatial reference of a view, layer, or method parameters. This indicates the projected or 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 Using spatial references.
Examples
// set the spatial reference of a view to WebMercator using wkidconst view = new SceneView({ container: "viewDiv", map: map, spatialReference: { wkid: 3857 }});// set the spatial reference of a geometry// to WGS84 using the WGS84 propertyconst point = new Point({ x: 10.1, y: 47.4, spatialReference: SpatialReference.WGS84});Constructors
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | | |
Properties
| Property | Type | Class |
|---|---|---|
WebMercator readonly static | | |
WGS84 readonly static | | |
declaredClass readonly inherited | ||
| | ||
| | ||
| | ||
| | ||
| | ||
isGeographic readonly | | |
isWebMercator readonly | | |
isWGS84 readonly | | |
isWrappable readonly | | |
| | ||
| | ||
metersPerUnit readonly | | |
| | ||
| | ||
unit readonly | ProjectionLengthUnit | "degrees" | null | undefined | |
| | ||
| | ||
| | ||
| | ||
| | ||
| | ||
| | ||
| |
WebMercator
- Type
- SpatialReference
A convenience spatial reference instance for Web Mercator.
Example
// returns true if the webMercatorUtils can// project geometries from WGS84 to Web Mercatorlet canProjectWGS84toWebMercator = webMercatorUtils.canProject(SpatialReference.WGS84, SpatialReference.WebMercator); WGS84
- Type
- SpatialReference
A convenience spatial reference instance for WGS84.
Example
// returns true if the webMercatorUtils can// project geometries from WGS84 to Web Mercatorlet canProjectWGS84toWebMercator = webMercatorUtils.canProject(SpatialReference.WGS84, SpatialReference.WebMercator); imageCoordinateSystem
- Since
- ArcGIS Maps SDK 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 MapView.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.
Example
// get image coordinate system of the specified catalog item// for example Raster.OBJECTID = 1600layer.getCatalogItemICSInfo(imageId).then(function(info) {// create a spatialReference object and set its// imageCoordinateSystem property let 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
- Type
- boolean
Indicates if the spatial reference refers to a geographic coordinate system.
isWrappable
- Type
- boolean
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.
metersPerUnit
- Type
- number
- Since
- ArcGIS Maps SDK for JavaScript 4.26
The factor to convert one unit value in the spatial reference's unit to meters.
Examples
// Convert 1 pixel in a MapView to metersconst pixelInMeter = view.resolution * view.spatialReference.metersPerUnit;// Measure the geodesic distance between two points in the view's unitconst distanceInViewUnit = geodesicUtils.geodesicDistance(pointA, pointB, "meters") / view.spatialReference.metersPerUnit;const DPI = 96const inchesPerMeter = 39.37;
// Get the scale for an extentfunction getScale(extent, viewWidth) { const unitValue = extent.spatialReference.metersPerUnit; return (extent.width / viewWidth) * unitValue * inchesPerMeter * DPI;} mTolerance
- Since
- ArcGIS Maps SDK for JavaScript 5.0
The tolerance value reflects the accuracy of coordinates. If one coordinate is within the tolerance value of another, they are interpreted as being at the same location. This value is used in relational and topological operations when determining whether two points are close enough to be given the same coordinate value or they are far enough apart to each have their own coordinate value. The default tolerance is set to 0.001 meters or its equivalent in map units.
unit
- Type
- ProjectionLengthUnit | "degrees" | null | undefined
- Since
- ArcGIS Maps SDK for JavaScript 4.26
The unit of the spatial reference. Returns null if no unit could be determined.
Some values of the possible values listed here cannot be used as parameters for certain functions.
For example, geodesicDistance() only accepts meters, feet, us-feet.
For other values, you can use the meters unit and use metersPerUnit convert to the spatial reference's unit.
- See also
wkid
The well-known ID of a spatial reference. See Using spatial references for a list of supported spatial references.
xyTolerance
- Since
- ArcGIS Maps SDK for JavaScript 5.0
The tolerance value reflects the accuracy of coordinates. If one coordinate is within the tolerance value of another, they are interpreted as being at the same location. This value is used in relational and topological operations when determining whether two points are close enough to be given the same coordinate value or they are far enough apart to each have their own coordinate value. The default tolerance is set to 0.001 meters or its equivalent in map units.
zTolerance
- Since
- ArcGIS Maps SDK for JavaScript 5.0
The tolerance value reflects the accuracy of coordinates. If one coordinate is within the tolerance value of another, they are interpreted as being at the same location. This value is used in relational and topological operations when determining whether two points are close enough to be given the same coordinate value or they are far enough apart to each have their own coordinate value. The default tolerance is set to 0.001 meters or its equivalent in map units.
Methods
fromJSON
- Signature
-
fromJSON (json: any): any
Creates a new instance of this class and initializes it with values from a JSON object
generated from an ArcGIS product. 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.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| json | 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
- any
Returns a new instance of this class.
clone
- Signature
-
clone (): SpatialReference
Returns a deep clone of the spatial reference object.
- Returns
- SpatialReference
Returns a deep clone of the spatial reference object.
equals
- Signature
-
equals (spatialReference: SpatialReference | null | undefined): boolean
Checks if the specified spatial reference object has the same wkid or wkt as this spatial reference object.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| spatialReference | The spatial reference to compare to. | |
- Returns
- boolean
Returns
trueif the input spatial reference object has the same wkid or wkt as this spatial reference object.
Example
const SpatialReference = await $arcgis.import("@arcgis/core/geometry/SpatialReference.js");const sr1 = new SpatialReference({ wkid: 4326 });const sr2 = new SpatialReference({ wkid: 4326 });console.log(sr1.equals(sr2)); // true toJSON
- Signature
-
toJSON (): any
Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.
- Returns
- any
The ArcGIS portal JSON representation of an instance of this class.