最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Difference between centroid and centerOfMass in turf - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question asked May 4, 2019 at 12:23 YaryckaYarycka 1951 silver badge10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 15

You've got three options, not two:

  • turf.center (the center of the wrapped bbox)
  • turf.centroid (the purely arithmetic center)
  • turf.centerOfMass (the center of mass you know from physics)

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:

For a concave one, the differences are noticeable:


I personally tend to use centerOfMass the most.

发布评论

评论列表(0)

  1. 暂无评论