MEASUREMENT
COORDINATE MUTATION
TRANSFORMATION
FEATURE_CONVERSION
MISC
HELPER
RANDOM
GRIDS
AGGREGATION
META
ASSERTIONS
BOOLEANS
UNIT CONVERSION
DATA
JOINS
CLASSIFICATION

center

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.

Parameters

  • geojson (Feature or FeatureCollection): The Feature or FeatureCollection for which the center is to be calculated.

Return value

A Point representing the geographic center of the input Feature or FeatureCollection.

Example

var feature = {
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [0, 0],
        [10, 5],
        [5, 10],
        [0, 0]
      ]
    ]
  }
};

var centerPoint = turf.center(feature);

Exceptions

If the input GeoJSON object is missing coordinates or has an unsupported geometry type, this method will throw an error.

Note

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.

See also