turf.center
What is turf.center?
turf.center returns a Point at the midpoint of the bounding box of any GeoJSON Feature, FeatureCollection, or Geometry. Unlike turf.centroid (which averages vertices) or turf.centerOfMass (which uses polygon area), this function is a simple extent midpoint — fast, deterministic, and unaffected by vertex density.
turf.center(geojson, options?) → Feature<Point>Options include:
properties— object assigned to the output point'spropertiesbbox— optional pre-computed bboxid— output feature id
When would you use turf.center?
Use turf.center when you need a label anchor or a map "fly to" target and you care only about geometric extent, not mass distribution. For instance, placing a country name on a choropleth, picking a zoom target for a user-drawn selection, or anchoring a popup over a FeatureCollection.
Because it is based on the bounding box, turf.center is predictable and fast even for large collections — good for Node.js services that precompute label positions or for client-side map interactions where you want consistent behaviour regardless of how densely the geometry is digitised.
undefinedFAQs
How is turf.center different from turf.centroid and turf.centerOfMass?
turf.center is the midpoint of the bounding box — ignores vertex distribution and shape. turf.centroid is the mean of all vertices — biased by vertex density. turf.centerOfMass is the true polygon centroid weighted by area — most accurate for labelling but slower.
Will the center always fall inside the shape?
No. For concave shapes like a crescent, the bbox midpoint can fall outside the feature. If you need a point guaranteed to lie on the feature, use turf.pointOnFeature.
How do I install just turf.center?
npm install @turf/center. The package is tiny and depends only on @turf/helpers and @turf/bbox, so it plays well with tree-shaking in Vite or Webpack.
Can I attach custom properties to the output?
Yes. Pass { properties: { … } } as the second argument. This is especially useful when generating label points — you can carry the source feature's name or id straight onto the center point for rendering in a MapLibre symbol layer.