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
convex_hull of simple polygon returns invalid convex hull #541
Comments
@tobiasmaier confirmed on my mac with the same Shapely (and GEOS library) version. This kind of bug drives me nuts. Even without changing coordinate values, I get different results by closing the polygon on a different vertex. Results that are what we'd expect. Check out this code: import matplotlib.pyplot as plt
import numpy as np
from shapely.geometry import Polygon
x = [163.29604426963272, 133.88336054231894, 55.360841751097887, 30.360841751097915, 20.26827882848472,
204.2523809886139, 163.29604426963272]
y = [-0.7051283277805496, 4.933187636462063, 4.933187636462094, 24.778118339507945, 26.712829880088947,
4.933187636462042, -0.7051283277805496]
# Open and close the polygon at the second vertex in the original sequence.
x = x[1:] + [x[1]]
y = y[1:] + [y[1]]
poly = Polygon(zip(x, y))
convex_hull_x, convex_hull_y = [z.tolist() for z in poly.convex_hull.exterior.coords.xy]
plt.figure(1)
plt.plot(x, y, '-x')
for idx, (i, j) in enumerate(zip(x, y)):
plt.text(i, j, str(idx))
plt.figure(2)
plt.plot(convex_hull_x, convex_hull_y)
for idx, (i, j) in enumerate(zip(convex_hull_x, convex_hull_y)):
plt.text(i, j, str(idx))
plt.show() Yields: and |
@tobiasmaier would you be willing to try downgrading to |
@sgillies the bug is already in the old GEOS version (3.4.2). |
Thanks for checking @tobiasmaier . I don't think that moving the closing point is a good work-around, but it's a data point I'll take upstream to the GEOS issue tracker. |
Closing. We've had 5 minor versions of GEOS since. Let's reopen if needed. |
Expected behavior and actual behavior.
convex_hull should give a valid convex hull.
Input Polygon:
Returned "convex hull":
Note that changing one of the coordinates [0, 1, 3, 4] a little bit leads to an expected convex hull.
Steps to reproduce the problem.
Operating system
Linux
Shapely version and provenance
1.6.2post1 installed from PyPI using pip
The text was updated successfully, but these errors were encountered: