Skip to content
Permalink
Browse files
Fix sublayer name of aigrid files with uris pointing to .adf file
  • Loading branch information
nyalldawson committed Jul 12, 2021
1 parent 1321b33 commit d7d50c5154580d7bdc779c697b9f98de7dcf72f8
Showing with 20 additions and 1 deletion.
  1. +8 −1 src/core/providers/gdal/qgsgdalprovider.cpp
  2. +12 −0 tests/src/core/testqgsgdalprovider.cpp
@@ -3639,8 +3639,15 @@ QList<QgsProviderSublayerDetails> QgsGdalProviderMetadata::querySublayers( const
const QVariantMap parts = decodeUri( uri );
if ( parts.contains( QStringLiteral( "path" ) ) )
{
QFileInfo fi( parts.value( QStringLiteral( "path" ) ).toString() );
const QFileInfo fi( parts.value( QStringLiteral( "path" ) ).toString() );
name = fi.baseName();

if ( fi.suffix().compare( QLatin1String( "adf" ), Qt::CaseInsensitive ) == 0 )
{
// for .adf files, we use the directory name as layer name
const QString dirName = fi.path();
name = QFileInfo( dirName ).completeBaseName();
}
}
details.setName( name.isEmpty() ? uri : name );
return {details};
@@ -503,6 +503,18 @@ void TestQgsGdalProvider::testGdalProviderQuerySublayers()
rl.reset( qgis::down_cast< QgsRasterLayer * >( res.at( 0 ).toLayer( options ) ) );
QVERIFY( rl->isValid() );

// aigrid, pointing to .adf file
res = gdalMetadata->querySublayers( QStringLiteral( TEST_DATA_DIR ) + "/aigrid/hdr.adf" );
QCOMPARE( res.count(), 1 );
QCOMPARE( res.at( 0 ).layerNumber(), 1 );
QCOMPARE( res.at( 0 ).name(), QStringLiteral( "aigrid" ) );
QCOMPARE( res.at( 0 ).description(), QString() );
QCOMPARE( res.at( 0 ).uri(), QStringLiteral( "%1/aigrid/hdr.adf" ).arg( QStringLiteral( TEST_DATA_DIR ) ) );
QCOMPARE( res.at( 0 ).providerKey(), QStringLiteral( "gdal" ) );
QCOMPARE( res.at( 0 ).type(), QgsMapLayerType::RasterLayer );
rl.reset( qgis::down_cast< QgsRasterLayer * >( res.at( 0 ).toLayer( options ) ) );
QVERIFY( rl->isValid() );

// aigrid, with fast scan
res = gdalMetadata->querySublayers( QStringLiteral( TEST_DATA_DIR ) + "/aigrid", Qgis::SublayerQueryFlag::FastScan );
QCOMPARE( res.count(), 1 );

0 comments on commit d7d50c5

Please sign in to comment.