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

Shapely buffer returns empty polygon #2009

Open
sor-droneup opened this issue Mar 7, 2024 · 1 comment
Open

Shapely buffer returns empty polygon #2009

sor-droneup opened this issue Mar 7, 2024 · 1 comment

Comments

@sor-droneup
Copy link

sor-droneup commented Mar 7, 2024

Expected behavior and actual behavior.

I'm using a buffer to reduce precision error before applying contains operation on my geometries. Geometry that is expected to contain another one gets small buffer applied to catch a cases when there is some rounding issue eg. -85.1234 and -85.123400000000055.

However some polygons after having this operation applied returns empty geometry:

example polygon:
POLYGON ((-8486160.859752608 4407005.311912118, -8486322.012133999 4419552.266313265, -8498821.965759974 4419382.682467878, -8498646.158633558 4406836.479565462, -8486160.859752608 4407005.311912118))

buffer(1e-9) - ok
buffer(1e-10) - ok
buffer(1e-11) - POLYGON EMPTY

Steps to reproduce the problem.

wkt = "POLYGON ((-8486160.859752608 4407005.311912118, -8486322.012133999 4419552.266313265, -8498821.965759974 4419382.682467878, -8498646.158633558 4406836.479565462, -8486160.859752608 4407005.311912118))"
poly = shapely.wkt.loads(wkt)
print(poly.buffer(1e-11))

Operating system

Alpine (docker image - ghcr.io/osgeo/gdal:alpine-small-3.8.2)

Shapely version and provenance

shapely - 2.0.3 installed through poetry

@theroggy
Copy link
Contributor

theroggy commented Mar 7, 2024

In some rare cases this indeed happens when a negative buffer is applied :-(.

Shapely is actually mainly a python wrapper around a C++ library, GEOS, where the actual algorithms are implemented. So I added this example to an existing issue about this problem in the GEOS project: libgeos/geos#984

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

No branches or pull requests

2 participants