Skip to content
import { execute, supportsCurves } from "@arcgis/core/geometry/operators/centroidOperator.js";
Since
ArcGIS Maps SDK for JavaScript 4.31

Calculates the centroid for a 2D geometry. The centroid represents the geometric center of mass, where the mass is equally distributed at each point/vertex of the geometry. For example, the centroid of a straight line is the midpoint. The centroid of a point is the point itself. It is not guaranteed to be within or on the geometry. The centroid of a donut polygon is the center of the hole, which is outside the polygon. The centroid of a curved polyline is not located on the line itself, but will be some distance away from it.

Centroid operator

See also

Functions

NameReturn TypeObject

execute

Function

Performs the centroid operation on a geometry.

Signature
execute (geometry: GeometryUnion): Point
Parameters
ParameterTypeDescriptionRequired
geometry

The geometry in which to calculate the centroid.

Returns
Point

The centroid of the geometry.

Example
// Return the centroid of a polygon
const centroid = centroidOperator.execute(polygon);
console.log(`x: ${centroid.x}, y: ${centroid.y}`);

Variables

supportsCurves

Variable

Indicates if the operator supports input geometries that contain curves. The value will always be true.

Type
boolean