Closed mxwell closed 6 years ago
@mxwell Thanks for pointing that out! 👍
I'm just curious, considering the polygon's structure, is there a reason for using such a large border density value (i.e. 10)? Have you tried reducing this value?
I'm asking because this library uses the scipy
's Voronoi algorithm for creating centerlines. Depending on the polygon's structure and the border density parameter set by the user, the Voronoi algorithm might not be able to produce enough vertices that lie completely inside the polygon (i.e. do not intersect the polygon's boundary). In that case, the output centerline can be reduced to a single line (which you were able to reproduce) or even a single point (an edge case that's already discarded).
This brings us to the problem at hand. Is this the result you were looking for?
Sorry for late reply.
Regarding my use case, this particular polygon is much smaller than others in the input and probably should be discarded by some kind of filter. But if I failed to filter it out or tune the density appropriately, then the single line will do.
My point is that the program could either (a) produce warning about too large density, leading to degeneration of center line, or (b) raise an exception with the same message. Currently, the error initially looks like a bug in shapely, which doesn't help during troubleshooting.
@mxwell I agree. I believe a RuntimeError
with a description would suffice, but the create_centerlines
function should simply log it and continue processing the data. Would you like to send a PR?
P.S. The density of the Voronoi grid is inversely proportional to the border density value.
For some inputs
_create_centerline()
returnsLineString
, which breaks MultiLineString constructor. Not sure, if that is so by design.Anyway, here is an example:
If you consider this an issue, I can provide PR.
Thanks.