9

我想用 geopandas 读取地理包文件,它可以读取第一层或带有 layer='' 参数的特定层。但是它怎么能读取所有层呢?可能是这样的:

all_layers = gp.read_xxxx('xxx.gpkg')
for layer in layers:
    # fetch this layer
4

1 回答 1

14

您可以通过 fiona 执行此操作,并通过图层名称进行迭代 https://fiona.readthedocs.io/en/latest/README.html#reading-multilayer-data

for layername in fiona.listlayers('tests/data.gpkg'):
    with fiona.open('tests/data.gpkg', layer=layername) as src:
        print(layername, len(src))

如果你将它传递给 geopandas:

for layername in fiona.listlayers('test/data.gpkg'):
    geopkg = gpd.read_file(r'test/data.gpkg', layer=layername)
    i = 0
    for name in geopkg.columns:
        print(name)
        i += 1
于 2019-09-17T09:32:37.700 回答