turf
turf copied to clipboard
@turf/buffer stretches polygons infinitely when buffering close to 180 degrees longitude
When buffering a polygon that is close to 180 degrees longitude, if the buffered polygon exceeds the 180 degree threshold it gets stretched around the whole world.
Example here: http://jsfiddle.net/60L7vxwq/4/
This is a complex problem, see this blog post for a fuller discussion. TurfJS is producing valid coordinates, however leaflet is not sure how to render features that cross the anti-meridian. Not sure if I have a simple answer for this sorry
Oh wow I’ll do some reading then.
FYI this behaves the same on Mapbox.
On Mon, 18 Jan 2021 at 5:00 PM, Rowan Winsemius [email protected] wrote:
This is a complex problem, see this blog post https://tmcw.github.io/2016/09/26/the-180th-meridian.html for a fuller discussion. TurfJS is producing valid coordinates, however leaflet is not sure how to render features that cross the anti-meridian. Not sure if I have a simple answer for this sorry
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Turfjs/turf/issues/2003#issuecomment-761964599, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5ATECRPLGKN32NKF6ZQ6TS2OW6VANCNFSM4WFFXV5Q .
@hally9k maybe you can find something inspirational here and here. If you came up with a nice function to safely display any GeoJSON feature on the map we could maybe add to Turf 😃
@stebogit Thanks for the resources, they were a good read. I'll see if I have time to try my hand at a fix next week.
Is there any update on this issue? As I have recently encountered the same issue when playing about with buffers in mapbox
@MacaScull According to https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678, we can map longitude ourselves.
const bufferedFeature = buffer(featureCollection, 500, { units: 'kilometers' })
const coordinates = bufferedFeature.geometry.coordinates[0]
for (let i = 1; i < coordinates.length - 1; ++i) {
const coords = coordinates[i]
const prevCoords = coordinates[i - 1]
coordinates[i][0] =
coords[0] + (coords[0] - prevCoords[0] > 180 ? -360 : prevCoords[0] - coords[0] > 180 ? 360 : 0)
}