The center
method in Turf's Measurement module is used to calculate the geographic center of a Feature or a FeatureCollection. The center is defined as the arithmetic mean coordinate for all vertices of all features.
geojson
(Feature or FeatureCollection): The Feature or FeatureCollection for which the center is to be calculated.A Point
representing the geographic center of the input Feature or FeatureCollection.
var feature = {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[0, 0],
[10, 5],
[5, 10],
[0, 0]
]
]
}
};
var centerPoint = turf.center(feature);
If the input GeoJSON object is missing coordinates or has an unsupported geometry type, this method will throw an error.
The center point of a FeatureCollection may not lie within any of its constituent features. When calculating the center of a set of features, consider whether the centroid or bounding box might be more appropriate for your use-case.