Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enabling negative buffers #736

Merged

Conversation

rafaelalmeida
Copy link
Contributor

@rafaelalmeida rafaelalmeida commented May 12, 2017

Pull Request #718 introduced a very welcome improvement in the turf-buffer module with buffered polygons being equidistant in all directions.

However, one particular change, which I've traced exactly to the line ce8bac8#diff-dfff186196a7762bb1ab6352156dd94fR42, removes the ability to do negative buffers directly at API entrypoint level.

As I understand it, turf uses the jsts module to really compute the buffer. I have inspected this module and it does seem to support negative buffers without any problem, so I see no reason to restrict turf-buffer from calculating negative buffers.

This change actually broke some production code which had been running for a couple weeks with no issues, which did two buffer operations to do a morphological closing (a dilation followed by an erosion).

Besides, negative buffers are important morphological operations in GIS, to the point of Wikipedia plain mentioning their existence in the relevant entry: https://en.wikipedia.org/wiki/Buffer_(GIS)

I've also took the liberty of also allowing zero-sized buffers, which can be used as a 'repair geometry' operation (see this SO link for example - it's related to a Python lib, but this trick works with other buffer implementations as well).

I removed the line and ran the tests again. Since all pass, I'm submitting this Pull Request for the community to evaluate.

@@ -38,8 +38,8 @@ var distanceToRadians = helpers.distanceToRadians;
module.exports = function (geojson, radius, units, steps) {
// validation
if (!geojson) throw new Error('geojson is required');
if (!radius) throw new Error('radius is required');
if (radius <= 0) throw new Error('radius must be greater than 0');
Copy link
Member

@DenisCarriere DenisCarriere May 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops! @ralmeidastrider You are correct, this should allow positive or negative radius (didn't know jsts was able to support this). We should also include this in the test cases.
👍

@DenisCarriere
Copy link
Member

@ralmeidastrider Was the equidistance change beneficial or did this break any production code? From my point of view this was a bug.

👍 I agree about the re-enabling buffer (backfired attempt to add better input validation).

@DenisCarriere DenisCarriere added this to the 4.3.0 milestone May 12, 2017
@DenisCarriere DenisCarriere self-assigned this May 12, 2017
@DenisCarriere DenisCarriere merged commit ae2d2f1 into Turfjs:master May 13, 2017
@DenisCarriere
Copy link
Member

👍 I can confirm that negative buffers do work now.

Blue: Input GeoJSON
Red: Negative Buffer (-200 miles)
image

@rafaelalmeida
Copy link
Contributor Author

@DenisCarriere We hadn't had a chance to test the equidistance change itself since we could not do the negative buffer, unfortunately.

Since our use case is a morphological closing (positive buffer followed by negative buffer of the same amount), we're just "gluing" close polygons together, this particular change should make little difference to us.

I can definitely see the use in general, however!

@DenisCarriere
Copy link
Member

Thanks for your input, might be a good idea to include this morphological closing into the test cases. I doubt the equidistance change would impact this type of behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants