GeospatialPython / pyshp

This library reads and writes ESRI Shapefiles in pure Python.
MIT License
1.1k stars 259 forks source link

Unexpected error: Unable to find a ring sample point #205

Closed sebhinck closed 4 years ago

sebhinck commented 4 years ago

Hi, after the update from 2.1.0 to 2.1.2 I am getting errors for some Polygons when I try to access the __geo_interface__: Unexpected error: Unable to find a ring sample point I guess it is related to 2d207e2743bc85494d6248c5caf941e56e62922b

It might be related to holes in the Polygon, but I couldn't figure out why for some there is an error and for some there is no problem.

I create the polygons using the Shapely package. Here is a shapefile containing one example Polygon that fails: poly_fail.zip

Maybe this helps you finding the problem!

Thank you for providing this great tool!

sebhinck commented 4 years ago

I might have solved the problem. It seems that my input polygon was corrupted. There were polygons overlapping others. If I fix this everything seems to work.

I'm closing it again..

karimbahgat commented 3 years ago

Glad that you were able to solve your problem, and yes overlapping polygons in a multipolygon would be considered invalid. However, after looking at your example file, the bug you encountered highlighted an actual problem with the hole-in-polygon code when it tries to find a sample point for a hole. It was a simple bug where the list of the hole coordinates was inadvertedly given an extra coordinate, which messed with the point-in-polygon test for short simple polygons as you had in your example file. Anyway, added a bug fix for that now, so thanks for stumbling across this!

sebhinck commented 3 years ago

Ok, great you found and fixed a bug!