Skip to content

Commit bb4784f

Browse files
author
Jeff Whitaker
committed
Merge pull request #93 from jswhit/master
fix drawcounties for python 3.3
2 parents 0451cf6 + 01c9c33 commit bb4784f

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

Changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
version 1.0.6 (not yet released)
22
--------------------------------
3+
* fix drawcounties for Python 3.3.
34
* update pyproj to version 1.9.3 (remove geographiclib python code, replace
45
with C code from proj4).
56
* in contourf and contour, all points outside the map projection

lib/mpl_toolkits/basemap/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,8 @@ def drawcounties(self,linewidth=0.1,linestyle='solid',color='k',antialiased=1,
19161916
"""
19171917
ax = ax or self._check_ax()
19181918
gis_file = os.path.join(basemap_datadir,'UScounties')
1919-
county_info = self.readshapefile(gis_file,'counties',drawbounds=drawbounds)
1919+
county_info = self.readshapefile(gis_file,'counties',\
1920+
default_encoding='latin-1',drawbounds=drawbounds)
19201921
counties = [coords for coords in self.counties]
19211922
counties = LineCollection(counties)
19221923
counties.set_linestyle(linestyle)
@@ -1991,7 +1992,8 @@ def is_land(self,xpt,ypt):
19911992
return landpt and not lakept
19921993

19931994
def readshapefile(self,shapefile,name,drawbounds=True,zorder=None,
1994-
linewidth=0.5,color='k',antialiased=1,ax=None):
1995+
linewidth=0.5,color='k',antialiased=1,ax=None,
1996+
default_encoding='utf-8'):
19951997
"""
19961998
Read in shape file, optionally draw boundaries on map.
19971999
@@ -2055,7 +2057,9 @@ def readshapefile(self,shapefile,name,drawbounds=True,zorder=None,
20552057
vertices. If ``drawbounds=True`` a
20562058
matplotlib.patches.LineCollection object is appended to the tuple.
20572059
"""
2060+
import shapefile as shp
20582061
from .shapefile import Reader
2062+
shp.default_encoding = default_encoding
20592063
if not os.path.exists('%s.shp'%shapefile):
20602064
raise IOError('cannot locate %s.shp'%shapefile)
20612065
if not os.path.exists('%s.shx'%shapefile):

lib/mpl_toolkits/basemap/shapefile.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import array
1515
#
1616
# Constants for shape types
17+
default_encoding = 'utf-8'
1718
NULL = 0
1819
POINT = 1
1920
POLYLINE = 3
@@ -35,7 +36,7 @@ def b(v):
3536
if PYTHON3:
3637
if isinstance(v, str):
3738
# For python 3 encode str to bytes.
38-
return v.encode('utf-8')
39+
return v.encode(default_encoding)
3940
elif isinstance(v, bytes):
4041
# Already bytes.
4142
return v
@@ -50,7 +51,7 @@ def u(v):
5051
if PYTHON3:
5152
if isinstance(v, bytes):
5253
# For python 3 decode bytes to str.
53-
return v.decode('utf-8')
54+
return v.decode(default_encoding)
5455
elif isinstance(v, str):
5556
# Already str.
5657
return v

0 commit comments

Comments
 (0)