使用 pyqgis 列出 Geopackage 中的所有栅格图层
List all raster layers in Geopackage using pyqgis
使用以下代码可以非常容易地列出地理包中的所有矢量图层:
my_gpkg = r'PATH_TO_GEOPACKAGE'
gpkg_layers = [l.GetName() for l in ogr.Open(my_gpkg )]
是否还有一种方法可以在地理包中列出所有栅格图层?
可以借助这个 post 解决我的问题: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()
使用以下代码可以非常容易地列出地理包中的所有矢量图层:
my_gpkg = r'PATH_TO_GEOPACKAGE'
gpkg_layers = [l.GetName() for l in ogr.Open(my_gpkg )]
是否还有一种方法可以在地理包中列出所有栅格图层?
可以借助这个 post 解决我的问题: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()