Closed james-willis closed 2 months ago
In general JTS does not guarantee results for invalid geometry inputs. Buffer does a bit better than this, in that it can produce reasonable results for invalid inputs. But it guarantees that the output is valid. In this case, the only way to produce a valid result that is faithful to the input linework is to convert the shape into a MultiPolygon.
Note that while in the past buffer(0)
was the recommended way (hack!) to turn invalid polygons into valid geometry, this has been superseded by the GeometryFixer
API. This is likely available in Shapely as well, as make_valid
.
Thanks for the quick and informative response.
I noticed the following quote from the GeometryFixer documentation:
Polygon: transform into a valid polygon...
However, my testing revealed that the GeometryFixer (and make_valid in shapely) has the same behavior as buffer(0).
Is this intended behavior? If so I could submit a PR to update the documentation to reflect that fixing a polygon may return a multipolygon
I noticed the following quote from the GeometryFixer documentation:
Polygon: transform into a valid polygon...
However, my testing revealed that the GeometryFixer (and make_valid in shapely) has the same behavior as buffer(0).
Is this intended behavior? If so I could submit a PR to update the documentation to reflect that fixing a polygon may return a multipolygon
Yes, that is intended behaviour. Feel free to submit a PR, or I can update it.
I have the an invalid polygon with a bowtie in it. when I call buffer(0) on it I am returned a MultiPolygon when I was expecting a Polygon. Is this expected behavior? shapely/GEOS does the same thing as JTS on the example below.
I though buffering a polygon with an arg >= 0 should always return a polygon.
As a work around I am getting the first geometry from the MultiPolygon using
.getGeometryN(0)
example polygon:
example result after calling buffer(0):