0

使用以下代码,列出地理包中的所有矢量图层非常容易:

my_gpkg = r'PATH_TO_GEOPACKAGE'
gpkg_layers = [l.GetName() for l in ogr.Open(my_gpkg )]

还有一种方法可以列出地理包中的所有栅格图层吗?

4

1 回答 1

0

可以在这篇文章的帮助下解决我的问题:https ://gis.stackexchange.com/questions/287997/counting-the-number-of-layers-in-a-geopackage

这是我的解决方案:

import sqlite3

my_gpkg = r'PATH_TO_GEOPACKAGE'
            
sqliteConnection = sqlite3.connect(my_gpkg)
cursor = sqliteConnection.cursor()

# the table gpkg_contents is mandatory in every geopackage
sqlite_select_query = """Select table_name from gpkg_contents where data_type = 'tiles'"""
cursor.execute(sqlite_select_query)
records = cursor.fetchall()
raster_layers = []
for row in records:
    layer_name = row[0]
    raster_layers.append(layer_name)
            
print('These are the raster layers in your geopackage: {}'.format(raster_layers))

cursor.close()
于 2021-11-15T19:01:46.260 回答