Skip to content

Commit

Permalink
Update dependency to pyshp v2.1.1 to correctly display shapefiles wit…
Browse files Browse the repository at this point in the history
…h multi-polygon holes (#1653)

* Make full use of pyshp's convenience functions

The Shapefile reader code wasn't making use of the full range of pyshp's convenience functions, duplicating some of the things pyshp already does behind the scenes, making it more error prone and potentially less efficient.

* Require pyshp 2, to avoid shapefile multipolygon rendering issue
  • Loading branch information
karimbahgat authored Sep 28, 2020
1 parent b71173b commit 304b6d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions lib/cartopy/io/shapereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def close(self):
return self._reader.close()

def __len__(self):
return self._reader.numRecords
return len(self._reader)

def geometries(self):
"""
Expand All @@ -152,8 +152,7 @@ def geometries(self):
:meth:`~Record.geometry` method.
"""
for i in range(self._reader.numRecords):
shape = self._reader.shape(i)
for shape in self._reader.iterShapes():
# Skip the shape that can not be represented as geometry.
if shape.shapeType != shapefile.NULL:
yield sgeom.shape(shape)
Expand All @@ -166,9 +165,8 @@ def records(self):
# Ignore the "DeletionFlag" field which always comes first
fields = self._reader.fields[1:]
field_names = [field[0] for field in fields]
for i in range(self._reader.numRecords):
shape_record = self._reader.shapeRecord(i)
attributes = dict(zip(field_names, shape_record.record))
for shape_record in self._reader.iterShapeRecords():
attributes = shape_record.record.as_dict()
yield Record(shape_record.shape, attributes, fields)


Expand Down
2 changes: 1 addition & 1 deletion requirements/default.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy>=1.10
shapely>=1.5.6
pyshp>=1.1.4
pyshp>=2
setuptools>=0.7.2

0 comments on commit 304b6d4

Please sign in to comment.