Skip to content
Advertisement

Difference between centroid and centerOfMass in turf

I need to find the geospatial coordinates of point which is the mean of the distances between all the Features in my GeoJSON dataset. In turf.js both centroid and centerOfMass are presented. The explanation for centerOfMass is that it “takes any Feature or a FeatureCollection and returns its center of mass using this formula: Centroid of Polygon.” But centroid and centerOfMass applied to my Features give different results. What is the difference between them? What should be used then?

Advertisement

Answer

You’ve got three options, not two:


At the end of the day, they serve different purposes but you’d typically decide based on whether your polygon is convex or concave.

For a convex polygon, it doesn’t really matter which function you choose — if, say, you wanted to place the marker near the poly’s center:

Center & CenterOfMass roughly the same

For a concave one, the differences are noticeable:

Concave centers


I personally tend to use centerOfMass the most.

Advertisement