Python处理矢量数据(例shp文件)
- ogr:GDAL项目中用于处理矢量数据的模块
- fiona:基于ogr的封装,提供了更简洁了API
- geopandas:基于fiona进行封装,并在pandas的基础上添加了对空间数据的支持,实现了读取空间数据以及对空间数据进行处理
【相关链接】
1.GeoPandas官方文档
【学习链接】
1.使用Python实现子区域数据分类统计
2.GeoPandas官方中文文档—译著
3.GeoPandas随笔
安装
Python安装
先安装 GDAL,Fiona, pyproj , Shapely等依赖包,再利用pip install geopandas安装
geopandas依赖库很多,比较不好安装,不建议云安装 建议使用whl包,本地安装
查看Python版本,记得之后下载的安装包都要下载38版本的
以下安装包都在这个网站上下载即可:网址
- 下载geopandas的安装包(geopandas‑0.10.2‑py2.py3‑none‑any.whl)
- 安装:
pip install geopandas‑0.10.2‑py2.py3‑none‑any.whl- 发现geopandas的依赖包fiona安装失败

- 下载fiona>=1.8(Fiona‑1.8.20‑cp38‑cp38‑win_amd64.whl)
- 安装失败,查看报错信息,发现GDAL安装失败,继续找GDAL的安装包
- gdal~=3.3.0(GDAL-3.3.3-cp38-cp38-win_amd64.whl)

- 再回过头来安装fiona>=1.8

- 再回过头来安装geopandas

引用包:import geopandas查看是否安装成功
问题一:Unable to import required dependencies:numpy

引用包时,可能报这个错误
ImportError: Unable to import required dependencies:numpy:IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!Importing the numpy C-extensions failed. This error can happen formany reasons, often due to issues with your setup or how NumPy wasinstalled.We have compiled some common reasons and troubleshooting tips at:https://numpy.org/devdocs/user/troubleshooting-importerror.htmlPlease note and check the following:* The Python version is: Python3.8 from "C:\Users\2107\anaconda3\python.exe"* The NumPy version is: "1.20.1"and make sure that they are the versions you expect.Please carefully study the documentation linked above for further help.
只需要把numpy卸载,重装即可
pip uninstall numpypip install numpy
Anaconda安装
打开Anaconda Prompt
# 切换清华镜像源conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/conda config --set show_channel_urls yes# 安装conda install geopandas#或者conda install --channel conda-forge geopandas
相关设置
编码问题
保存shp文件,字段成乱码GeoDataFrame.to_file('D:\tmp.shp', encoding="utf-8")
