Skip to content

描述 ​

接收任何 Feature 或 FeatureCollection,使用以下公式返回其 center of mass:Centroid of Polygon。

参数 ​

名称类型描述
geojsonGeoJSON待居中的 GeoJSON
options?Object可选参数 (默认 {})
options.properties?Object将属性转换到 Feature (默认 {})

返回值 ​

Feature<Point> 重心

示例 ​

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

var center = turf.centerOfMass(polygon);

安装 ​

javascript
$ npm install @turf/center-of-mass

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

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