Skip to content

Commit

Permalink
Fix sublayer name of aigrid files with uris pointing to .adf file
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 12, 2021
1 parent 1321b33 commit d7d50c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/core/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -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};
Expand Down
12 changes: 12 additions & 0 deletions tests/src/core/testqgsgdalprovider.cpp
Expand Up @@ -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 );
Expand Down

0 comments on commit d7d50c5

Please sign in to comment.