Skip to content

Commit 7a4b00f

Browse files
committed
Replace another test of in dict_.keys() with a defaultdict, and simplify nearby code.
1 parent b327f6b commit 7a4b00f

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

shapefile.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
__version__ = "2.3.1"
1010

1111
import array
12+
import collections
1213
import io
1314
import logging
1415
import os
@@ -393,12 +394,11 @@ def organize_polygon_rings(rings, return_errors=None):
393394
return polys
394395

395396
# first determine each hole's candidate exteriors based on simple bbox contains test
396-
hole_exteriors = dict([(hole_i, []) for hole_i in xrange(len(holes))])
397-
exterior_bboxes = [ring_bbox(ring) for ring in exteriors]
398-
for hole_i in hole_exteriors.keys():
397+
hole_exteriors = collections.defaultdict(list)
398+
for hole_i in xrange(len(holes)):
399399
hole_bbox = ring_bbox(holes[hole_i])
400-
for ext_i, ext_bbox in enumerate(exterior_bboxes):
401-
if bbox_contains(ext_bbox, hole_bbox):
400+
for ext_i, ring in enumerate(exteriors):
401+
if bbox_contains(ring_bbox(ring), hole_bbox):
402402
hole_exteriors[hole_i].append(ext_i)
403403

404404
# then, for holes with still more than one possible exterior, do more detailed hole-in-ring test

0 commit comments

Comments
 (0)