require(["esri/geometry/projection"], function(projection) { /* code goes here */ });
Description
(Added at v3.24)
A client-side projection engine for converting geometries from one
SpatialReference to another. When projecting geometries the starting spatial reference must be specified on the input geometry. You can specify a specific geographic (datum) transformation for the
projection operation, or accept the default transformation if one is needed.
Things to consider:
- The browser must support WebAssembly for the client-side projection engine to work.
- Only equation-based geographic transformations are supported.
Samples
Search for
samples that use this class.
Methods
Method Details
Gets the default geographic transformation used to convert the geometry from the input spatial reference to the output spatial reference.
The default transformation is used when
converting geometries where the datum transformation is required but when one was not specified in the
project parameter.
- This method returns equation-based geographic transformation only.
- Geographic transformation is returned with its maximum number of
steps. Currently, number of steps is limited to 2.
Parameters:
<SpatialReference > inSpatialReference |
Required |
The input spatial reference from which to project geometries. |
<SpatialReference > outSpatialReference |
Required |
The spatial reference to which you are converting the geometries. |
<Extent > extent |
Optional |
An extent used to determine the suitability of the returned transformation. The extent will be re-projected to the inSpatialReference if it has a different spatial reference. |
Returns a list of all geographic transformations suitable to convert geometries from the input spatial reference to the specified output spatial reference. The list is ordered in descending order by suitability, with the
most suitable being first in the list. The list will be empty if the provided extent lies out of the area of use for the input spatial reference.
- This method returns all the suitable equation-based geographic transformations.
- Geographic transformations are returned with their maximum number of steps. Currently, number of steps is limited to 2.
Parameters:
<SpatialReference > inSpatialReference |
Required |
The spatial reference that the geometries are currently using. |
<SpatialReference > outSpatialReference |
Required |
The spatial reference to which you are converting the geometries to. |
<Extent > extent |
Optional |
An extent used to determine the suitability of the returned transformations. The extent will be re-projected to the input spatial reference if necessary. |
Indicates if all dependencies of this module have been loaded. Returns true if this module's dependencies have been loaded.
Indicates if this module is supported in the browser. The browser must support
WebAssembly.
Sample:
if (!projection.isSupported()) {
console.error("projection is not supported");
return;
}
Load this module's dependencies.
Sample:
projection.load().then(function() {
// the projection module loaded.
// Geometries can be reprojected.
...
}
Projects a geometry or an array of geometries to the specified output spatial reference. A default geographic transformation is used if not explicitly provided, but required. Use the
getTransformation() method to find out which transformation is used by default for the given input and output spatial references.
- Note that you must load() this module before attempting to project geometries.
- This method uses the spatial reference of the first geometry as an input spatial reference. Therefore all geometries in the array must have the same spatial reference.
Parameters:
<Geometry | Geometry[] > geometry |
Required |
The geometry or geometries to project. |
<SpatialReference > outSpatialReference |
Required |
The spatial reference to which you are converting the geometries' coordinates. |
<GeographicTransformation > geographicTransformation |
Optional |
The geographic transformation used to transform the geometries. Specify this parameter to project a geometry when the default transformation is not appropriate for your requirements. |
Sample:
// Project each polygon in the array. project() will use the spatial
// reference of the first geometry in the array as an input spatial
// reference. It will use the default transformation. If one is required
// when converting from input spatial reference to the output spatial reference.
var outSpatialReference = new SpatialReference({
wkid: 53008 //Sphere_Sinusoidal
});
polygonGraphics.forEach(function(graphic) {
graphic.geometry = projection.project(graphic.geometry, outSpatialReference);
});
var outSpatialReference = new SpatialReference({
wkid: 54044
});
// Project array of points
var projectedPoints = projection.project(wgsPoints, outSpatialReference);
projectedPoints.forEach(function(point) {
console.log(point.x, point.y);
});