Skip to content


Open adf raster file as a directory
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rldhont committed Nov 30, 2015
1 parent d2b506c commit 564a063
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
ok = addRasterLayer( fileName, fileInfo.completeBaseName() );
// TODO - should we really call isValidRasterFileName() before addRasterLayer()
// this results in 2 calls to GDALOpen()
Expand Down Expand Up @@ -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());
layer = new QgsRasterLayer( uri, baseName, providerKey );
Expand Down Expand Up @@ -10002,24 +10015,17 @@ 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() )
//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 coverate,

if ( myBaseNameQString.toLower().endsWith( ".adf" ) )
if ( myFileInfo.fileName().toLower().endsWith( ".adf" ) )
Expand Down

0 comments on commit 564a063

Please sign in to comment.