Skip to content

Commit 80de89a

Browse files
borysiastynyalldawson
authored andcommittedSep 12, 2022
Backport 825482d in order to fix removing a single raster from GPKG
1 parent d7dc1ef commit 80de89a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎src/core/providers/gdal/qgsgdalprovider.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3827,7 +3827,13 @@ QList<QgsProviderSublayerDetails> QgsGdalProviderMetadata::querySublayers( const
38273827

38283828
QString name;
38293829
const QVariantMap parts = decodeUri( uri );
3830-
if ( !parts.value( QStringLiteral( "vsiSuffix" ) ).toString().isEmpty() )
3830+
3831+
const QString identifier = GDALGetMetadataItem( dataset.get(), "IDENTIFIER", "" );
3832+
if ( !identifier.isEmpty() )
3833+
{
3834+
name = identifier;
3835+
}
3836+
else if ( !parts.value( QStringLiteral( "vsiSuffix" ) ).toString().isEmpty() )
38313837
{
38323838
name = parts.value( QStringLiteral( "vsiSuffix" ) ).toString();
38333839
if ( name.startsWith( '/' ) )

‎tests/src/core/testqgsgdalprovider.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,16 @@ void TestQgsGdalProvider::testGdalProviderQuerySublayers()
489489
QCOMPARE( res.at( 1 ).driverName(), QStringLiteral( "GPKG" ) );
490490
rl.reset( qgis::down_cast< QgsRasterLayer * >( res.at( 1 ).toLayer( options ) ) );
491491
QVERIFY( rl->isValid() );
492+
// geopackage with one raster layer with an identifier
493+
res = mGdalMetadata->querySublayers( QStringLiteral( TEST_DATA_DIR ) + "/qgis_server/test_project_wms_grouped_layers.gpkg" );
494+
QCOMPARE( res.count(), 1 );
495+
QCOMPARE( res.at( 0 ).layerNumber(), 1 );
496+
QCOMPARE( res.at( 0 ).name(), QStringLiteral( "osm" ) );
497+
QCOMPARE( res.at( 0 ).description(), QString() );
498+
QCOMPARE( res.at( 0 ).uri(), QStringLiteral( "%1/qgis_server/test_project_wms_grouped_layers.gpkg" ).arg( QStringLiteral( TEST_DATA_DIR ) ) );
499+
QCOMPARE( res.at( 0 ).providerKey(), QStringLiteral( "gdal" ) );
500+
QCOMPARE( res.at( 0 ).type(), QgsMapLayerType::RasterLayer );
501+
QCOMPARE( res.at( 0 ).driverName(), QStringLiteral( "GPKG" ) );
492502

493503
// aigrid file
494504
res = gdalMetadata->querySublayers( QStringLiteral( TEST_DATA_DIR ) + "/aigrid" );

0 commit comments

Comments
 (0)
Please sign in to comment.