Turfjs / Turfjs/turf

Buffer should split polygons at the antimeridian

Open
#3,029 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

The current behavior of the buffer package is that it will normalize longitude values to [-180, 180], but the way that it does this can result in very large polygons that span the world, instead of much smaller shapes around the antimeridian itself.

I think that the expected behavior here is to split the polygons down the antimeridian, so a rectangle from -181 to -179 would turn into one from 179 to 180 and another from -180, -179. I believe this would be a breaking change, so I'd like to file this away for v8 before changing the behavior. Happy for feedback on this ticket in the meantime.

Interestingly Mapbox seems to wrap the world, but Cesium decides that this should cross the antimeridian instead. I suspect that Cesium is determining that the points are more than 180 degrees apart in longitude and joins them in the opposite direction instead. For the curious, Mapbox renders longitudes outside [-180, 180] in a predictable way, so it is possible to visually span the antimeridian by denormalizing the longitudes before rendering.

Cesium rendering of a box (with a hole in it) at the antimeridian and equator:
Image

Mapbox rendering of the same output geojson:
Image

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 in the buffer package and reproduce the longitude-normalization case described: a rectangle from -181 to -179. Compare the resulting GeoJSON with the expected split at ±180; done means polygons no longer span the world and are divided at the antimeridian. The issue flags this as a possible v8 breaking change, so confirm scope before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
data
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.