You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Breaking change in buffer between 4.7.3 and 4.7.4 #1470
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
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:
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.
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. 😅
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 🙂
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.
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.
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.
We've also come across this problem and have implemented the PostGIS solution @jgwconsulting has posted before. We would prefer using Turf.js though :)
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?
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.
Activity
garthk commentedon Aug 30, 2018
For the curious, the radii projected to EPSG:28356 are:
rowanwins commentedon Aug 30, 2018
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
garthk commentedon Aug 30, 2018
Cheers @rowanwins; found #1246 now.
I had a go at bisecting to nail down which commit it was, but couldn't reliably get
lerna bootstrapat the root to complete without failure. I was left with this list of commits:There's no
v4.7.4tag, so I used b9d1cf8 forgit bisect bad.rowanwins commentedon Aug 30, 2018
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.
stebogit commentedon Aug 30, 2018
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
jgwconsulting commentedon Feb 13, 2019
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 🙂
rowanwins commentedon Feb 14, 2019
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.
jgwconsulting commentedon Feb 20, 2019
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.
justinstenning commentedon May 27, 2019
@rowanwins
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_defsFrom 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.
cHewN commentedon Mar 2, 2020
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?
smallsaucepan commentedon Dec 9, 2023
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.