gpt4 book ai didi

python - Python 中的多层 .gdb 文件?

转载 作者:太空狗 更新时间:2023-10-30 02:51:51 27 4
gpt4 key购买 nike

我正在尝试从 here 中读取一些 .gdb 文件(文件夹?) : .

我使用 GeoPandas 并执行以下操作:

# file from local path
mallard = gpd.read_file('./bird-species/E00039600_mallard.gdb/')
# geopandas included map, filtered to just this hemisphere
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
westhem = world[(world['continent'] == 'North America') |
(world['continent'] == 'South America')]

# making sure the coordinates line up:
mallard = mallard.to_crs(world.crs)

#establishing figure axes
base = westhem.plot(color='white', edgecolor='black',figsize=(11,11))

# cmap because I'd LIKE the multiple layers to exist
bbw_duck.plot(ax=base, cmap = 'Reds');

输出看起来像这样:

lousy map - one color

在 GeoPandas 或 Python (Jupyter Notebook) 中有没有一种方法可以查看所有图层?

最佳答案

是的,GeoPandas 支持图层。由于您的层名称非常长,我建议使用层的顺序。

mallard_0 = gpd.read_file('./bird-species/E00039600_mallard.gdb/', layer=0)
mallard_1 = gpd.read_file('./bird-species/E00039600_mallard.gdb/', layer=1)

# geopandas included map, filtered to just this hemisphere
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
westhem = world[(world['continent'] == 'North America') |
(world['continent'] == 'South America')]

# making sure the coordinates line up:
mallard_0 = mallard_0.to_crs(world.crs)
mallard_1 = mallard_1.to_crs(world.crs)

# establishing figure axes
base = westhem.plot(color='white', edgecolor='black', figsize=(11, 11))

# cmap because I'd LIKE the multiple layers to exist
mallard_0.plot(ax=base, color='red', alpha=.5)
mallard_1.plot(ax=base, color='blue', alpha=.5)

如果你有更多的它们,你可以做一个循环来轻松地一次绘制它们。 result of the script above

编辑:Geopandas 在后台使用 Fiona 进行文件处理,因此如果您想查看图层列表,请使用

import fiona
fiona.listlayers('./bird-species/E00039600_mallard.gdb')

Edit2:遍历所有层将如下所示:

import fiona

# geopandas included map, filtered to just this hemisphere
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
westhem = world[(world['continent'] == 'North America') |
(world['continent'] == 'South America')]
base = westhem.plot(color='white', edgecolor='black', figsize=(11, 11))

layers = fiona.listlayers('./bird-species/E00039600_mallard.gdb')

for l in layers:
mallard = gpd.read_file('./bird-species/E00039600_mallard.gdb', layer=l)
mallard = mallard.to_crs(world.crs)
mallard.plot(ax=base, color='red', alpha=.1)

second example using loop

关于python - Python 中的多层 .gdb 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54562069/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com