Skip to content

Commit 6035d98

Browse files
committed
Merge pull request #2517 from rldhont/raster_open_adf
Open adf raster file as a directory
2 parents 4f0b9dd + 564a063 commit 6035d98

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/app/qgisapp.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4597,7 +4597,14 @@ bool QgisApp::openLayer( const QString & fileName, bool allowInteractive )
45974597
// try to load it as raster
45984598
if ( QgsRasterLayer::isValidRasterFileName( fileName ) )
45994599
{
4600-
ok = addRasterLayer( fileName, fileInfo.completeBaseName() );
4600+
// open .adf as a directory
4601+
if ( fileName.toLower().endsWith( ".adf" ) )
4602+
{
4603+
QString dirName = fileInfo.path();
4604+
ok = addRasterLayer( dirName, QFileInfo( dirName ).completeBaseName() );
4605+
}
4606+
else
4607+
ok = addRasterLayer( fileName, fileInfo.completeBaseName() );
46014608
}
46024609
// TODO - should we really call isValidRasterFileName() before addRasterLayer()
46034610
// this results in 2 calls to GDALOpen()
@@ -9866,7 +9873,13 @@ QgsRasterLayer* QgisApp::addRasterLayerPrivate(
98669873
// XXX ya know QgsRasterLayer can snip out the basename on its own;
98679874
// XXX why do we have to pass it in for it?
98689875
// ET : we may not be getting "normal" files here, so we still need the baseName argument
9869-
if ( providerKey.isEmpty() )
9876+
if ( !providerKey.isEmpty() && uri.toLower().endsWith( ".adf" ) )
9877+
{
9878+
QFileInfo fileInfo( uri );
9879+
QString dirName = fileInfo.path();
9880+
layer = new QgsRasterLayer( dirName, QFileInfo( dirName ).completeBaseName(), "gdal" );
9881+
}
9882+
else if ( providerKey.isEmpty() )
98709883
layer = new QgsRasterLayer( uri, baseName ); // fi.completeBaseName());
98719884
else
98729885
layer = new QgsRasterLayer( uri, baseName, providerKey );
@@ -9997,24 +10010,17 @@ bool QgisApp::addRasterLayers( QStringList const &theFileNameQStringList, bool g
999710010
if ( QgsRasterLayer::isValidRasterFileName( *myIterator, errMsg ) )
999810011
{
999910012
QFileInfo myFileInfo( *myIterator );
10000-
// get the directory the .adf file was in
10001-
QString myDirNameQString = myFileInfo.path();
10002-
//extract basename
10003-
QString myBaseNameQString = myFileInfo.completeBaseName();
10004-
//only allow one copy of a ai grid file to be loaded at a
10005-
//time to prevent the user selecting all adfs in 1 dir which
10006-
//actually represent 1 coverage,
1000710013

1000810014
// try to create the layer
10009-
QgsRasterLayer *layer = addRasterLayerPrivate( *myIterator, myBaseNameQString,
10015+
QgsRasterLayer *layer = addRasterLayerPrivate( *myIterator, myFileInfo.completeBaseName(),
1001010016
QString(), guiWarning, true );
1001110017
if ( layer && layer->isValid() )
1001210018
{
1001310019
//only allow one copy of a ai grid file to be loaded at a
1001410020
//time to prevent the user selecting all adfs in 1 dir which
1001510021
//actually represent 1 coverate,
1001610022

10017-
if ( myBaseNameQString.toLower().endsWith( ".adf" ) )
10023+
if ( myFileInfo.fileName().toLower().endsWith( ".adf" ) )
1001810024
{
1001910025
break;
1002010026
}

0 commit comments

Comments
 (0)