Skip to main content
Version: 6.5.0

centroid

Description

Takes one or more features and calculates the centroid using the mean of all vertices. This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.

Parameters

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

Returns

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(...);