Atlaslog
Atlaslog / Turf.js / API / centroid
Turf.js · API reference

centroid

Quick answer

Computes the centroid as the mean of all vertices within the object.

Last verified 2026-11-03 · Turf.js 7.x · Cite this page
Runnable examplesChinese noteAll API topics

Description​

Computes the centroid as the mean of all vertices within the object.

Parameters​

NameTypeDescription
geojsonGeoJSONGeoJSON to be centered
options?ObjectOptional Parameters (default {})
options.properties?Objectan Object that is used as the Feature's properties (default {})

Returns​

Feature<Point> the centroid of the input object

Examples​

var polygon = turf.polygon([
[
[-81, 41],
[-88, 36],
[-84, 31],
[-80, 33],
[-77, 39],
[-81, 41],
],
]);

var centroid = turf.centroid(polygon);

Installation​

$ npm install @turf/centroid

import { centroid } from "@turf/centroid";
const result = centroid(...);
$ npm install @turf/turf

import * as turf from "@turf/turf";
const result = turf.centroid(...);
TutorialsAPI index
English reference text adapted from the official Turf.js documentation, © Turf.js contributors, licensed under MIT.
Original page: https://turfjs.org/docs/api/centroid · Chinese note: /turf/api/centroid.html
Cite this page

Atlaslog (2026). centroid. https://www.jingweizhi.com/en/turf/api/centroid.html (accessed 2026-11-03).