From 564a06370d896a6ad8d404d42b96dfbad8bb766d Mon Sep 17 00:00:00 2001 From: rldhont Date: Mon, 30 Nov 2015 14:25:54 +0100 Subject: [PATCH] Open adf raster file as a directory adf raster files are Arc/Info Binary Grid. This format is the internal binary format for Arc/Info Grid, and takes the form of a coverage level directory in an Arc/Info database. To open the coverage select the coverage directory, or an .adf file (such as hdr.adf) from within it. If the directory does not contain file(s) with names like w001001.adf then it is not a grid coverage. This mean that if a user open an adf file, it is the same as open the directory containing this adf file. To do it, this patch replaces file path and name by its directory. Funded by Ifremer --- src/app/qgisapp.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index ec93455ff8e..4a49b430a97 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -4602,7 +4602,14 @@ bool QgisApp::openLayer( const QString & fileName, bool allowInteractive ) // try to load it as raster if ( QgsRasterLayer::isValidRasterFileName( fileName ) ) { - ok = addRasterLayer( fileName, fileInfo.completeBaseName() ); + // open .adf as a directory + if ( fileName.toLower().endsWith( ".adf" ) ) + { + QString dirName = fileInfo.path(); + ok = addRasterLayer( dirName, QFileInfo( dirName ).completeBaseName() ); + } + else + ok = addRasterLayer( fileName, fileInfo.completeBaseName() ); } // TODO - should we really call isValidRasterFileName() before addRasterLayer() // this results in 2 calls to GDALOpen() @@ -9871,7 +9878,13 @@ QgsRasterLayer* QgisApp::addRasterLayerPrivate( // XXX ya know QgsRasterLayer can snip out the basename on its own; // XXX why do we have to pass it in for it? // ET : we may not be getting "normal" files here, so we still need the baseName argument - if ( providerKey.isEmpty() ) + if ( !providerKey.isEmpty() && uri.toLower().endsWith( ".adf" ) ) + { + QFileInfo fileInfo( uri ); + QString dirName = fileInfo.path(); + layer = new QgsRasterLayer( dirName, QFileInfo( dirName ).completeBaseName(), "gdal" ); + } + else if ( providerKey.isEmpty() ) layer = new QgsRasterLayer( uri, baseName ); // fi.completeBaseName()); else layer = new QgsRasterLayer( uri, baseName, providerKey ); @@ -10002,16 +10015,9 @@ bool QgisApp::addRasterLayers( QStringList const &theFileNameQStringList, bool g if ( QgsRasterLayer::isValidRasterFileName( *myIterator, errMsg ) ) { QFileInfo myFileInfo( *myIterator ); - // get the directory the .adf file was in - QString myDirNameQString = myFileInfo.path(); - //extract basename - QString myBaseNameQString = myFileInfo.completeBaseName(); - //only allow one copy of a ai grid file to be loaded at a - //time to prevent the user selecting all adfs in 1 dir which - //actually represent 1 coverage, // try to create the layer - QgsRasterLayer *layer = addRasterLayerPrivate( *myIterator, myBaseNameQString, + QgsRasterLayer *layer = addRasterLayerPrivate( *myIterator, myFileInfo.completeBaseName(), QString(), guiWarning, true ); if ( layer && layer->isValid() ) { @@ -10019,7 +10025,7 @@ bool QgisApp::addRasterLayers( QStringList const &theFileNameQStringList, bool g //time to prevent the user selecting all adfs in 1 dir which //actually represent 1 coverate, - if ( myBaseNameQString.toLower().endsWith( ".adf" ) ) + if ( myFileInfo.fileName().toLower().endsWith( ".adf" ) ) { break; }