import * as centroidOperator from "@arcgis/core/geometry/operators/centroidOperator.js";
const centroidOperator = await $arcgis.import("@arcgis/core/geometry/operators/centroidOperator.js");
@arcgis/core/geometry/operators/centroidOperator
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.
Property Overview
Name | Type | Summary | Object |
---|---|---|---|
Indicates if the operator supports input geometries that contain curves. | centroidOperator |
Property Details
-
supportsCurves
supportsCurves Booleanreadonly
-
Indicates if the operator supports input geometries that contain curves.
- Default Value:true
Method Overview
Name | Return Type | Summary | Object |
---|---|---|---|
Performs the centroid operation on a geometry. | centroidOperator |
Method Details
-
execute
execute(geometry){Point}
-
Performs the centroid operation on a geometry.
Parametergeometry GeometryUnionThe geometry in which to calculate the centroid.
ReturnsType Description Point The centroid of the geometry. Example// Return the centroid of a polygon const centroid = operatorCentroid.execute(polygon); console.log(`x: ${centroid.x}, y: ${centroid.y}`);