我需要使用大熊猫来绘制德国州的地图。
在哪里可以找到德国的.shp
文件?德国有两个州/市边界?
答案 0 :(得分:1)
选择一个来源,了解更多详情,请查看 this topic,例如DIVA-GIS | Administrative 你需要的地方'DEU_adm1.shp'
试试下面的代码
import io
import zipfile
import requests
import geopandas as gpd
import matplotlib.pyplot as plt
local_path = 'tmp/'
url = "https://biogeo.ucdavis.edu/data/diva/adm/DEU_adm.zip"
r = requests.get(url)
z = zipfile.ZipFile(io.BytesIO(r.content))
z.extractall(path=local_path)
gdf = gpd.read_file(local_path + '/DEU_adm1.shp')
gdf.plot(color='white',
edgecolor='black')
plt.show()
并得到输出
有关详细信息,请查看这篇文章 Reading Shapefile ZIPs from a URL in Python 3
答案 1 :(得分:0)
欢迎使用Stackoverflow。
如果您输入Google:“德国国家shapefile”,则会得到以下结果:
https://www.igismap.com/download-germany-shapefile-free-boundary-line-polygon-shapefile/
下载shapefile后,您将如下读取:
import geopandas as gpd
gdf = gpd.read_file("path/to/shapefile/shapefile.shp")