Skip to content

Commit 564a063

Browse files
committedNov 30, 2015
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
1 parent d2b506c commit 564a063

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
@@ -4602,7 +4602,14 @@ bool QgisApp::openLayer( const QString & fileName, bool allowInteractive )
46024602
// try to load it as raster
46034603
if ( QgsRasterLayer::isValidRasterFileName( fileName ) )
46044604
{
4605-
ok = addRasterLayer( fileName, fileInfo.completeBaseName() );
4605+
// open .adf as a directory
4606+
if ( fileName.toLower().endsWith( ".adf" ) )
4607+
{
4608+
QString dirName = fileInfo.path();
4609+
ok = addRasterLayer( dirName, QFileInfo( dirName ).completeBaseName() );
4610+
}
4611+
else
4612+
ok = addRasterLayer( fileName, fileInfo.completeBaseName() );
46064613
}
46074614
// TODO - should we really call isValidRasterFileName() before addRasterLayer()
46084615
// this results in 2 calls to GDALOpen()
@@ -9871,7 +9878,13 @@ QgsRasterLayer* QgisApp::addRasterLayerPrivate(
98719878
// XXX ya know QgsRasterLayer can snip out the basename on its own;
98729879
// XXX why do we have to pass it in for it?
98739880
// ET : we may not be getting "normal" files here, so we still need the baseName argument
9874-
if ( providerKey.isEmpty() )
9881+
if ( !providerKey.isEmpty() && uri.toLower().endsWith( ".adf" ) )
9882+
{
9883+
QFileInfo fileInfo( uri );
9884+
QString dirName = fileInfo.path();
9885+
layer = new QgsRasterLayer( dirName, QFileInfo( dirName ).completeBaseName(), "gdal" );
9886+
}
9887+
else if ( providerKey.isEmpty() )
98759888
layer = new QgsRasterLayer( uri, baseName ); // fi.completeBaseName());
98769889
else
98779890
layer = new QgsRasterLayer( uri, baseName, providerKey );
@@ -10002,24 +10015,17 @@ bool QgisApp::addRasterLayers( QStringList const &theFileNameQStringList, bool g
1000210015
if ( QgsRasterLayer::isValidRasterFileName( *myIterator, errMsg ) )
1000310016
{
1000410017
QFileInfo myFileInfo( *myIterator );
10005-
// get the directory the .adf file was in
10006-
QString myDirNameQString = myFileInfo.path();
10007-
//extract basename
10008-
QString myBaseNameQString = myFileInfo.completeBaseName();
10009-
//only allow one copy of a ai grid file to be loaded at a
10010-
//time to prevent the user selecting all adfs in 1 dir which
10011-
//actually represent 1 coverage,
1001210018

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

10022-
if ( myBaseNameQString.toLower().endsWith( ".adf" ) )
10028+
if ( myFileInfo.fileName().toLower().endsWith( ".adf" ) )
1002310029
{
1002410030
break;
1002510031
}

0 commit comments

Comments
 (0)
Please sign in to comment.