||
一直在使用Basemap画各类地图,觉得很好用,重新使用conda之后安装了basemap出现了如下错误:
Traceback (most recent call last):
File "plot_rice_mask.py", line 39, in <module>
m.readshapefile('/Users/qingsun/GGCM/mask_rice/new_cn_map_shp2014/province1', 'states', drawbounds=True)
File "/miniconda2/envs/basemap/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 2156, in readshapefile
for shprec in shf.shapeRecords():
File "/miniconda2/envs/basemap/lib/python2.7/site-packages/shapefile.py", line 1039, in shapeRecords
for rec in zip(self.shapes(), self.records())])
File "/miniconda2/envs/basemap/lib/python2.7/site-packages/shapefile.py", line 1012, in records
r = self.__record(oid=i)
File "/miniconda2/envs/basemap/lib/python2.7/site-packages/shapefile.py", line 987, in __record
value = u(value, self.encoding, self.encodingErrors)
File "/miniconda2/envs/basemap/lib/python2.7/site-packages/shapefile.py", line 136, in u
return v.decode(encoding, encodingErrors)
File "/miniconda2/envs/basemap/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb0 in position 0: invalid start byte
可能原因:
可能是由于字符编码的问题,utf-8不识别shp地图中的字符串。
解决方法:
参考了https://stackoverflow.com/questions/45660904/matplotlib-basemap-drawcounties-having-issues
将"/miniconda2/envs/basemap/lib/python2.7/site-packages/shapefile.py"文件中的第136行改为:
return v.decode('latin-1')
然后读取shp地图文件没有任何问题了。比起一些重新保存shp地图文件的方法简单易行。
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2025-1-5 15:10
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社