Basemap使用自带的shapefile.py处理ESRI的shapefile,但是Basemap自带的shapefile版本过低(1.1.x),其中存在一个bug导致使用Python 3.x版本时无法正确处理Windows-1252编码的二进制文件。典型错误:

解决方法一:

使用pip安装pyshp ( pip install pyshp ),或者手动下载最新版本的pyshp,并且将shapefile.py拷贝到Basemap的目录中( <python-install-prefix>\lib\site-packages\mpl_toolkits\basemap )。

解决方法二:

按照一的方式使用pip安装pyshp,并且修改Basemap的源代码,将__init__.py中shapefile模块的import语句略作修改,不再使用相对路径的导入方式并删除Basemap目录中的shapefile.py。修改之前为

修改之后为

使用方法二的一个好处是,使用pip更新pyshp后不需要再更新Basemap中的shapefile.py

Python 3使用Basemap导入ESRI信息的问题

1 comment

  • 2017-05-14 at 13:29
    Permalink

    改完第二句应该是from shapefile import Reader,少了个from。
    感谢博主,解决了我的问题!

    Reply

Leave a Reply to Lauhonman Cancel reply

Your email address will not be published.