Skip to content

Breaking change in buffer between 4.7.3 and 4.7.4 #1470

Closed

Description

@garthk

Please provide the following when reporting an issue:

There was a breaking change to @turf/buffer in a patch release:

Major version X (X.y.z | X > 0) MUST be incremented if any backwards incompatible changes are introduced to the public API.

The schema is the same, but I strongly disagree with the proposition that a result change this big is backwards compatible.

Activity

  1. garthk commented on Aug 30, 2018

    @garthk
    ContributorAuthor

    For the curious, the radii projected to EPSG:28356 are:

    version radius (m)
    4.7.3 499.713
    4.7.4 420.053
  2. rowanwins commented on Aug 30, 2018

    @rowanwins
    Member

    Hi @garthk

    yeah unfortunantly the buffer issue is a known issue.

    Im currently working on the v7 branch which will seek to resolve some the issues around the buffer module. If you want check out that branch and the approach let me know

  3. garthk commented on Aug 30, 2018

    @garthk
    ContributorAuthor

    Cheers @rowanwins; found #1246 now.

    I had a go at bisecting to nail down which commit it was, but couldn't reliably get lerna bootstrap at the root to complete without failure. I was left with this list of commits:

    commit version author comment
    7bb8dc4 4.6.1 @DenisCarriere Merge branch 'master' into buffer
    adee2d9 4.6.1 @stebogit refactored with @turf/projection
    95cef56 4.6.1 @stebogit uses transverse mercator above 50 degrees
    a7c6035 4.6.1 @stebogit adds test issue #916
    10dc77e 4.6.1 @stebogit adds test issue #815
    90f886c 4.7.1 @stebogit Merge branch 'master' into buffer-line-fix
    f3ebe31 4.7.1 @stebogit sets reference to @turf/projection
    44b453a 4.7.3 @DenisCarriere Merge branch 'master' into buffer-line-fix
    b9d1cf8 4.7.4 @DenisCarriere Patch release for @turf/buffer 4.7.4

    There's no v4.7.4 tag, so I used b9d1cf8 for git bisect bad.

  4. rowanwins commented on Aug 30, 2018

    @rowanwins
    Member

    Yeah from memory the main change that I think is responsible was that they were attempting to project coordinates so that buffers would be more accurate, particularly as you headed towards the poles. This was a good idea in theory but I'm not sure the execution quite worked or was thoroughly tested.

    In v7 I'm proposing to do similar but hopefully with better results. I'll be following the postgis approach of transforming the coords to the relevant UTM zone. In my initial testing against QGIS and ArcMap this is producing much better results. But I'm happy for input, and as mentioned it may be that we undertake some more substantial changes to the buffer module while we have the chance.

  5. stebogit commented on Aug 30, 2018

    @stebogit
    Collaborator

    Hey @garthk
    could this depend on the value of earth radius? I remember we discussed it here and here, and then it was changed; as you can see here though the change was actually considered a bug fix (fixing an incorrect value) instead of a major change.
    However, later it was reverted, for some reason (although it was changed to 6373km despite the PR title...).

    I'm not sure how we ended up with the right value now. 😅

    cc @rowanwins

  6. jgwconsulting commented on Feb 13, 2019

    @jgwconsulting

    Hi @rowanwins I hate bugging OSS devs who are doing amazing work out of the kindness of their hearts and often for very little thanks but I was wondering how v7 is progressing, particularly in relation to the issue with buffer.

    We've, foolishly, found this issue very late and with a recently imposed deadline in two weeks time we're looking around for a solution. Considering spinning up an AWS RD Postgres + PostGIS instance to use the ST_BUFFER function but I thought I should check in first 🙂

  7. rowanwins commented on Feb 14, 2019

    @rowanwins
    Member

    Hi @jgwconsulting

    Unfortunately there won't be anything ready in the next fortnight. I'm waiting on a final upstream change to another module that we'll be using for unions/difference/clipping before I push another release of the alpha.
    In the meantime I'm working on a standalone buffer module over here which I hope to eventually incorporate here in Turf.

  8. jgwconsulting commented on Feb 20, 2019

    @jgwconsulting

    Thanks for getting back to me so quickly and for all your good work. It's been a pleasure to use TurfJS and you and @stebogit have been exceptionally helpful.

  9. justinstenning commented on May 27, 2019

    @justinstenning

    @rowanwins

    they were attempting to project coordinates so that buffers would be more accurate, particularly as you headed towards the poles. This was a good idea in theory but I'm not sure the execution quite worked or was thoroughly tested.

    I have just implemented a similar solution in a project (replacing the calls to toMercator and toWgs84 in a copy of the buffer/bufferFeature code with our own implementation using OpenLayers ol.proj.transform with proj4js projections). Basically we calculate the UTM zone +south/north of the centroid and then define a proj4 utm projection that uses that zone. This generally provides quite good results across most of the globe with a error of less than +/- 20metres for a 50km buffer (more error towards the poles - and far better than the +/-20% that we were previously getting).

    Example proj4 with zone 52/south: +proj=utm +zone=52 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs

    From looking at the original code it looks like this was the intent, however the execution using the d3-geo transverseMercator doesn't appear to work consistently (I'm not sure how to address this with d3-geo and how the d3-geo transverseMercator is the same/differs to proj4 utm projection).

    Anyway - I just wanted to provide some feedback that the intent of the underlying approach, when implemented correctly, does appear to work quite well as a default global option.

    In my opinion, the ability for the caller to specify that no projection transform needs to take place (i.e. already passes the GeoJSON in meters), with projection transforms occurring before and after the buffer call would be a good option for those that require more control over the projections used.

  10. cHewN commented on Mar 2, 2020

    @cHewN

    We've also come across this problem and have implemented the PostGIS solution @jgwconsulting has posted before. We would prefer using Turf.js though :)

    I don't see a clear example in any of the open issues, so I've created a CodeSandbox that displays the problem clearly: https://codesandbox.io/s/multiple-buffers-in-react-leaflet-qc722

    You can use the measure tool in the top right corner to see that PostGIS buffer is 100m, where Turf.js is ~89m.

    EDIT: I forgot to mention, this is also on the v4.7.3 branch of Turf.js. My best guess is the issue described at the start is for buffers based on a Point, not a Polygon.

    @rowanwins the above sandbox also shows another bug when using turf with a FeatureCollection with multiple Features > Polygons. Turf will add a buffer to each Feature, instead of one buffer for the entire Collection. A workaround could be to merge all the Polygons before using turf to find a buffer but maybe this should be an option in the future? Would you like for me to move/add this to a separate issue?

  11. smallsaucepan commented on Dec 9, 2023

    @smallsaucepan
    Contributor

    Updated the code sandbox from @cHewN to use v7.0.0-alpha.2 and the initially reported bugs described has been fixed, possibly by #1956. The red Turf and yellow PostGIS polygons overlap exactly.

    As for buffer() returning multiple buffers, is that covered by #2522? Will close this given the initially reported behaviour has been fixed. Perhaps expand on #2522 or report a specific new issue if the remaining behaviour is still problematic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions