一、相应包下载安装
- 本人根据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_DATA
、cpl_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()