【问题标题】:Plot German states using geopandas使用 geopandas 绘制德国各州
【发布时间】:2019-07-04 00:19:41
【问题描述】:

我需要使用 geopandas 绘制德国各州。

我在哪里可以找到具有州/城市边界的德国的 .shp 文件?

【问题讨论】:

标签: python python-3.x pandas geopandas


【解决方案1】:

欢迎来到 Stackoverflow。

如果你输入谷歌:“german states 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")

【讨论】:

  • 感谢 Marjan 提供信息。我能够将德国的轮廓作为地图,但找不到地区/城市的分隔。你能指点我如何想象德国的 16 个州吗?提前致谢!
  • 在我链接的页面中间有一个指向状态 shapefile 的链接...请记住,查找源数据与 geopandas 和 python 无关...
【解决方案2】:
  1. 选择一个来源,更多详情请查看this topic,例如DIVA-GIS | Administrative你需要的地方'DEU_adm1.shp'

  2. 试试下面的代码

    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

【讨论】:

    猜你喜欢
    • 2012-06-08
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    • 2021-08-22
    相关资源
    最近更新 更多