Skip to main content
Version: Next

centerOfMass

Description

Takes any Feature or a FeatureCollection and returns its center of mass using this formula: Centroid of Polygon.

Parameters

NameTypeDescription
geojsonGeoJSONGeoJSON to be centered
options?ObjectOptional Parameters (default {})
options.properties?ObjectTranslate Properties to Feature (default {})

Returns

Feature<Point> the center of mass

Examples

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

var center = turf.centerOfMass(polygon);

Installation

$ npm install @turf/center-of-mass

import { centerOfMass } from "@turf/center-of-mass";
const result = centerOfMass(...);
$ npm install @turf/turf

import * as turf from "@turf/turf";
const result = turf.centerOfMass(...);