python 安装 geopandas及报错解决办法以及示例

一、相应包下载安装
  • 本人根据python版本、系统版本,多次尝试不同版本GDAL 、Fiona 安装
    在这里插入图片描述
    pip install GDAL-3.1.4-cp36-cp36m-win32.whl
    pip install fiona-1.8.18-cp36-cp36m-win32.whl
    
    pip install geopandas
    
    感谢主终于成功啦
二、常见错误
  • error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools“
    VisualCppBuildTools下载、解压、安装
    Visual Studio 2015 用方式安装则报错
    在这里插入图片描述

  • A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable.
    解决

    set GDAL_DATA=%GDAL_DATA%;C:\Users\Administrator\AppData\src\Lib\site-packages\osgeo\include\gdal
    
  • fiona/_transform.cpp(606): fatal error C1083: Cannot open include file: 'cpl_conv.h': No such file or directory error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2
    解决 根据python版本与系统多次尝试不同版本fiona安装

  • UserWarning: Unknown distribution option: 'use_2to3_fixers' UserWarning: Unknown distribution option: 'use_2to3_exclude_fixers' warnings.warn(msg)
    解决 下载的whl版本错误

三、心酸历程
  • ①首先pip install geopandas 果断报错error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools

  • ②安装VisualCppBuildTools 15版本,pip install gdal安装后仍报错,后查资料仅.whl 格式安装

  • ③ 于是下载gdal.whl 格式,根据系统与python 版本出现平台不支持格式。

  • ④ 每个版本都测试一下,终于安装gdal成功(你以为成功啦,高兴太早啦)

  • ⑤ fiona进行 pip install fiona 然后各种报错。又进行 fiona.whl 支持各版本重试又是各种报错设置 set GDAL_DATAcpl_conv.h 又是两个错误。

  • pip install fiona***.whl 报错,试了各版本终于成功。

  • 中间省略10个坑

    error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools“:

四、简单示例
url = 'https://native-land.ca/wp-content/themes/NLD-2021/files/indigenousTerritories.json'


geopandas 数据读取
    gdf = gpd.read_file(r'gis/sz.json')
    
import geopandas as gpd

# geopandas 数据读取
gdf = gpd.read_file(r'gis/sz.json')

# 存储文件
shp = gdf.to_file(r'gis/sz.shp')
dic = gdf.to_dict(r'gis/sz.dict')
cv = gdf.to_csv(r'gis/sz.dict')
sql = gdf.to_sql(r'gis/sz.dict')
js = gdf.to_json(r'gis/sz.dict')
ge = gdf._to_geo(r'gis/sz.dict')

geojson = gdf.to_file(r'gis/sz.json', driver='GeoJSON')

gdf.to_file('dataframe.geojson', driver='GeoJSON')
import geopandas as gpd
from shapely.geometry import Polygon
from geojson import Feature, Point, FeatureCollection, Polygon, dump


# geopandas 数据读取
gdf = gpd.read_file(r'河北省.json')
print(gdf)
plt = gdf.plot()
print(plt)
# gdf.to_file(r'gis/szl1', encoding='utf-8')
# gdf.to_file(r'gis/szl3.json', driver='GeoJSON')
import geopandas
import matplotlib.pyplot as plt
gdf = geopandas.GeoDataFrame
census = gdf.from_file("GIS_CensusTract_poly.shp")
census.plot()
plt.show()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风华浪浪

讨个老婆本呗

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值