turf centroid module
Takes a Feature or FeatureCollection of any type and calculates the centroid using the arithmetic mean of all vertices. This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.
| parameter | type | description |
|---|---|---|
features |
GeoJSON | a Feature or FeatureCollection of any type |
var poly = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[
[105.818939,21.004714],
[105.818939,21.061754],
[105.890007,21.061754],
[105.890007,21.004714],
[105.818939,21.004714]
]]
}
};
var centroidPt = turf.centroid(poly);
var result = {
"type": "FeatureCollection",
"features": [poly, centroidPt]
};
//=resultRequires nodejs.
$ npm install turf-centroid$ npm test