Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can geopandas get a geopackage's (or other vector file) all layers?

I want to use geopandas read a geopackage file, It can read the first layer or specific layer with layer='' parameter. But how can it read all layers? May be like:

all_layers = gp.read_xxxx('xxx.gpkg')
for layer in layers:
    # fetch this layer
like image 852
wsf1990 Avatar asked May 16 '19 09:05

wsf1990


People also ask

What files can GeoPandas read?

GeoPandas supports writing and reading the Apache Parquet and Feather file formats.

Can GeoPandas read GDB?

Yes, GeoPandas support layers.

How do I read a GPKG file in Python?

Use the geopackage driver gdal.org/drivers/vector/gpkg.html from OGR in python or shell the command (subprocess. Popen(['ogr2ogr', '-f', '"esri shapefile"', os. path. join(os.

What is GeoPandas Python?

GeoPandas is an open source project to make working with geospatial data in python easier. GeoPandas extends the datatypes used by pandas to allow spatial operations on geometric types. Geometric operations are performed by shapely. Geopandas further depends on fiona for file access and matplotlib for plotting.


1 Answers

You can do this by fiona and itter through the layernames 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))

If you pass it to 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
like image 194
Xeppit Avatar answered Sep 18 '22 09:09

Xeppit