Python中的多层.gdb文件? [英] Multi-Layer .gdb files in Python?

查看:190
本文介绍了Python中的多层.gdb文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从此处读取一些.gdb文件(文件夹?). >:.

I'm trying to read in some .gdb files(folders?) from here: .

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

I use GeoPandas and do the following:

# 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');

输出看起来像这样:

糟糕的地图-一种颜色

通常在GeoPandas或Python(Jupyter Notebook)中可以查看所有图层吗?

Is there a way in GeoPandas, or Python (Jupyter Notebook) in general to see all the layers?

推荐答案

是的,GeoPandas支持图层.由于各层的名称非常长,因此我建议使用各层的顺序.

Yes, GeoPandas support layers. As names of your layers are terribly long, I recommend using the order of layers.

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)

如果它们更多,则可以循环制作一次轻松地绘制它们.

If you have more of them you can then make a loop to go plot them all at once easily.

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

Geopandas is using Fiona under the hood for file handling, so if you want to see the list of your layers use

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

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

Loop over all layers will then look like this:

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)

这篇关于Python中的多层.gdb文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆