Turfjs / Turfjs/turf

Antimeridian option for Center of Mass (suggestion)

Open
#2,888 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
10.5k
Forks
1k
Avg merge
1h 11m
Merged PRs (30d)
4

Description

A quick suggestion related to center of mass calculations when a feature crosses the antimeridian.

Here's the problem:

You have a small island in the Pacific Ocean, and the center of mass is the average of +179.5° in the west and -179.5° in the east. The calculation, without a doubt, yields 0°, i.e. close to London.

This can be solved be translating the polygon back and forth on the map, or by making the barycenter calculations using coordinates between 0° and 360°, and going back to [-180,+180] afterwards.

In the previous example, you then would get the average of 179.5 and 180.5, which is 180°, indeed in the Pacific Ocean!

It could be very nice to provide this option in the centerOfMass function (something like { antimeridian: true }).

Thanks for all the good work at Turf, and good luck to the team!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the centerOfMass function and review how it currently averages longitudes, then locate its existing tests if available. Done means the function supports an antimeridian option and returns a center near 180° for a feature spanning ±180°, without changing the default behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
data
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.