Transformation

AMD: require(["esri/geometry/operators/support/Transformation"], (Transformation) => { /* code goes here */ });
ESM: import Transformation from "@arcgis/core/geometry/operators/support/Transformation.js";
Class: esri/geometry/operators/support/Transformation
Since: ArcGIS Maps SDK for JavaScript 4.31
beta

The Transformation class represents 2D transformations that can be applied to geometries using the affineTransformOperator. All transformations are applied in the spatial reference units of the input geometries.

Constructors

Transformation

Constructor
new Transformation()

Method Overview

Name Return Type Summary Class

Calculates distance errors for a transformation on a given set of the input points to the output points.

Transformation

Flips all the x coordinates of geometries on the vertical y-axis (right or left) that is centered between x0 and x1.

Transformation

Flips all the y coordinates of geometries on the horizontal x-axis (up or down) that is centered between y0 and y1.

Transformation

Initializes a new transformation from the input and output control points.

Transformation

Determines if the transformation is in its default state, which is an identity matrix.

Transformation

Rotates the geometries by the specified angle in degrees around the point specified by the x and y coordinates.

Transformation

Resizes the geometries by the specified scale factors defined by the x and y coordinates.

Transformation

Use this method to reset the transformation to its default state, which is an identity matrix.

Transformation

Use this method to swap the x and y coordinate values in the transformation.

Transformation

Shifts a geometry's points by the specified proportion in parallel to the x and y directions, except those points that are along the shear axis, which is a line defined by the x and y coordinates.

Transformation

Shifts all the coordinates of the geometries by the distance and direction between the specified x and y coordinates and their current location.

Transformation

Method Details

calculateErrors

Method
calculateErrors(input, output){ErrorResult}

Calculates distance errors for a transformation on a given set of the input points to the output points. This method is usually used to calculate errors for the transformation initialized by initializeFromControlPoints.

The length of the input and output arrays must be the same.

Parameters
input Point[]

The input points to transform from.

output Point[]

The output points to transform to.

Returns
Type Description
ErrorResult Returns an object representing the errors incurred during transformation.
Example
// Calculate the errors for a transformation
const errors = transformation.calculateErrors(inputPoints, outputPoints);
// Example returned object:
// { rms: 0.5, errorsOut: [0.1, 0.2, 0.3, 0.4, 0.5] }

flipX

Method
flipX(x0, x1)

Flips all the x coordinates of geometries on the vertical y-axis (right or left) that is centered between x0 and x1. For example, if x0 is 0 and x1 is 10, all the x coordinates of the geometries will be flipped, or mirrored, on the vertical axis centered at x = 5.

Parameters
x0 Number

The x-coordinate of the first geometry.

x1 Number

The x-coordinate of the second geometry.

Example
// Flip the x-coordinates of a geometry on the vertical axis
const transform = new Transformation();
transform.flipX(0, 10);
const result = affineTransformOperator.execute(polygon, transform);

// Flip the x-coordinates of a geometry on the vertical axis centered at the geometry's center
const centerX = polygon.extent.center.x;
transform.flipX(centerX, centerX);
const result = affineTransformOperator.execute(polygon, transform);

flipY

Method
flipY(y0, y1)

Flips all the y coordinates of geometries on the horizontal x-axis (up or down) that is centered between y0 and y1. For example, if y0 is 0 and y1 is 10, all the y coordinates of the geometries will be flipped, or mirrored, on the horizontal axis centered at y = 5.

Parameters
y0 Number

The y-coordinate of the first geometry.

y1 Number

The y-coordinate of the second geometry.

Example
// Flip the y-coordinates of a geometry on the vertical axis
transformation.flipY(0, 10);
const result = affineTransformOperator.execute(polygon, transform);

// Flip the y-coordinates of a geometry on the horizontal axis centered at the geometry's center
const centerY = polygon.extent.center.y;
transform.flipY(centerY, centerY);
const result = affineTransformOperator.execute(polygon, transform);

initializeFromControlPoints

Method
initializeFromControlPoints(type, input, output, inverseOut)

Initializes a new transformation from the input and output control points. Uses least squares method to find the best fit transformation. Adding control points allows you to snap lines and polygons to the input and output points on a map.

The length of the input and output arrays must be the same.

Parameters
type String

The type of transformation to initialize.

Value Description
"conformal" Preserves the angles between curves.
"general" Preserves lines and parallelisms. Does not preserve angles or lengths.

Possible Values:"conformal"|"general"

input Point[]

The input points to transform from.

output Point[]

The output points to transform to.

inverseOut Transformation
optional

The transformation instance that is the inverse of the calculated transformation.

Example
// Initialize a transformation from control points
transformation.initializeFromControlPoints("conformal", inputPoints, outputPoints);

isIdentity

Method
isIdentity(){Boolean}

Determines if the transformation is in its default state, which is an identity matrix.

Returns
Type Description
Boolean Returns true if the transformation is the default and has not been changed. There will be no change in the geometries when applying the transformation.
See also

rotate

Method
rotate(angleInDegrees, rotationX, rotationY)

Rotates the geometries by the specified angle in degrees around the point specified by the x and y coordinates. The point can be the center of the geometries or any other point.

Parameters
angleInDegrees Number

The angle to rotate the geometries in degrees.

rotationX Number

The x-coordinate of the point to rotate around.

rotationY Number

The y-coordinate of the point to rotate around.

Example
// Rotate a geometry
transformation.rotate(90, 0, 0);
const result = affineTransformOperator.execute(polygon, transform);

scale

Method
scale(x, y)

Resizes the geometries by the specified scale factors defined by the x and y coordinates. The coordinates define how much scaling is applied to the geometries in the x and y directions.

Parameters
x Number

The x-coordinate that defines the horizontal scale factor.

y Number

The y-coordinate that defines the vertical scale factor.

Example
// Scale a geometry
transformation.scale(2, 2);
const result = affineTransformOperator.execute(polygon, transform);

setIdentity

Method
setIdentity()

Use this method to reset the transformation to its default state, which is an identity matrix. This method is useful when reusing the class instance for multiple transformations.

setSwapCoordinates

Method
setSwapCoordinates()

Use this method to swap the x and y coordinate values in the transformation. An example usage is when slicing vertically with the polgonSlicerOperator.findSlicesByArea() method.

shear

Method
shear(proportionX, proportionY)

Shifts a geometry's points by the specified proportion in parallel to the x and y directions, except those points that are along the shear axis, which is a line defined by the x and y coordinates. This transformation preserves lines and parallelisms, however it may distort angles and distances. Applying this transformation will not change a geometry's area.

Parameters
proportionX Number

The proportion to shear the geometry in the x direction.

proportionY Number

The proportion to shear the geometry in the y direction.

Example
// Shear a geometry
transformation.shear(0.5, 0.5);
const result = affineTransformOperator.execute(polygon, transform);

shift

Method
shift(x, y)

Shifts all the coordinates of the geometries by the distance and direction between the specified x and y coordinates and their current location. This operation does not change the size or shape of the geometries.

Parameters
x Number

The x-coordinate to shift by.

y Number

The y-coordinate to shift by.

Example
// Shift the coordinates of a geometry
transformation.shift(5, 2);
const result = affineTransformOperator.execute(polygon, transform);

Type Definitions

ErrorResult

Type Definition
ErrorResult

Object returned from the calculateErrors() method.

Properties
rms Number

The root mean square (rms) of the 'average' distance error between the specified output points and the transformed input points.

errorsOut Number[]

Contains the errors of the individual distance differences between specific pairs of points.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.