Skip to content

Commit 69c60f6

Browse files
committed
Fix bug in hole in polygon algo
In trying to find a sample point, we iterate the ring's triplet coordinates and add add the second coord from the end to allow checking the last triplet. Previously the second coordinate was added by changing the main coords list in-place, but that messes with the point-in-polygon algorithm. Fixed by only iterating through the points instead of changing the coords list. Fixes #205.
1 parent 059cef1 commit 69c60f6

14 files changed

+8
-2
lines changed

shapefile.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,15 @@ def ring_sample(coords, ccw=False):
237237
The orientation of the ring is assumed to be clockwise, unless ccw
238238
(counter-clockwise) is set to True.
239239
"""
240-
coords = tuple(coords) + (coords[1],) # add the second coordinate to the end to allow checking the last triplet
241240
triplet = []
242-
for p in coords:
241+
def itercoords():
242+
# iterate full closed ring
243+
for p in coords:
244+
yield p
245+
# finally, yield the second coordinate to the end to allow checking the last triplet
246+
yield coords[1]
247+
248+
for p in itercoords():
243249
# add point to triplet (but not if duplicate)
244250
if p not in triplet:
245251
triplet.append(p)

shapefiles/test/balancing.dbf

0 Bytes
Binary file not shown.

shapefiles/test/contextwriter.dbf

0 Bytes
Binary file not shown.

shapefiles/test/dtype.dbf

0 Bytes
Binary file not shown.

shapefiles/test/line.dbf

0 Bytes
Binary file not shown.

shapefiles/test/linem.dbf

0 Bytes
Binary file not shown.

shapefiles/test/linez.dbf

0 Bytes
Binary file not shown.

shapefiles/test/multipatch.dbf

0 Bytes
Binary file not shown.

shapefiles/test/multipoint.dbf

0 Bytes
Binary file not shown.

shapefiles/test/onlydbf.dbf

0 Bytes
Binary file not shown.

shapefiles/test/point.dbf

0 Bytes
Binary file not shown.

shapefiles/test/polygon.dbf

0 Bytes
Binary file not shown.

shapefiles/test/shapetype.dbf

0 Bytes
Binary file not shown.

shapefiles/test/testfile.dbf

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)