sunqing3020590的个人博客分享 http://blog.sciencenet.cn/u/sunqing3020590

博文

Basemap 错误 UnicodeDecodeError: \'utf-8\' codec can\'t decode by

已有 2504 次阅读 2019-8-22 15:52 |系统分类:科研笔记| python, Basemap, error

一直在使用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地图文件的方法简单易行。



http://blog.sciencenet.cn/blog-2410131-1194788.html

上一篇:惊出一身冷汗!Mac中office word闪退,把即将完成的博士论文文档自动删除,如何恢复?

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2021-11-28 17:00

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部