多层.GDB在Python文件?

问题描述 投票:4回答:1

我试图从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笔记本电脑)一般办法看到所有的层?

python gis geopandas
1个回答
4
投票

是的,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是罩用于文件处理下,使用菲奥娜,所以如果你想看到你的图层使用的列表

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

© www.soinside.com 2019 - 2024. All rights reserved.