简体   繁体   中英

Plot German states using geopandas

I need to plot German states using geopandas.

Where could I find .shp file for Germany which has either state/city borders?

Welcome to Stackoverflow.

If you type in Google: "german states shapefile", you will get this result:

https://www.igismap.com/download-germany-shapefile-free-boundary-line-polygon-shapefile/

After you download a shapefile, you read it like this:

import geopandas as gpd

gdf = gpd.read_file("path/to/shapefile/shapefile.shp")
  1. Choose a source, for more details check this topic , eg DIVA-GIS | Administrative where you need 'DEU_adm1.shp'

  2. Try the code below

    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()

and get the output

结果

For more details check this article Reading Shapefile ZIPs from a URL in Python 3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM