Skip to content

Commit

Permalink
Merge pull request #2517 from rldhont/raster_open_adf
Browse files Browse the repository at this point in the history
Open adf raster file as a directory
  • Loading branch information
rldhont committed Dec 7, 2015
2 parents 4f0b9dd + 564a063 commit 6035d98
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/app/qgisapp.cpp
Expand Up @@ -4597,7 +4597,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()
Expand Down Expand Up @@ -9866,7 +9873,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 );
Expand Down Expand Up @@ -9997,24 +10010,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" ) )
{
break;
}
Expand Down

0 comments on commit 6035d98

Please sign in to comment.