Skip to content

Commit

Permalink
fixes for browser (GDAL rasters) : skip *.aux.xml files ; add suffix …
Browse files Browse the repository at this point in the history
…to raster file names in browser ; add HDF4 file suffix (.hdf) in buildSupportedRasterFileFilterAndExtensions()
  • Loading branch information
etiennesky authored and jef-n committed Mar 9, 2012
1 parent 3e0fb86 commit a2b80be
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/core/qgsdataitem.cpp
Expand Up @@ -194,7 +194,8 @@ bool QgsDataItem::hasChildren()

void QgsDataItem::addChildItem( QgsDataItem * child, bool refresh )
{
QgsDebugMsg( "mName = " + child->mName );
QgsDebugMsg( QString( "add child #%1 - %2" ).arg( mChildren.size() ).arg( child->mName ) );

int i;
for ( i = 0; i < mChildren.size(); i++ )
{
Expand Down
14 changes: 10 additions & 4 deletions src/providers/gdal/qgsgdaldataitems.cpp
Expand Up @@ -79,6 +79,12 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
QgsDebugMsg( "extensions: " + extensions.join( " " ) );
QgsDebugMsg( "wildcards: " + wildcards.join( " " ) );
}
// skip *.aux.xml files (GDAL auxilary metadata files)
// unless that extension is in the list (*.xml might be though)
if ( thePath.right( 8 ) == ".aux.xml" &&
extensions.indexOf( "aux.xml" ) < 0 )
return 0;

if ( extensions.indexOf( info.suffix().toLower() ) < 0 )
{
bool matches = false;
Expand Down Expand Up @@ -107,7 +113,8 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )

QgsDebugMsg( "GdalDataset opened " + thePath );

QString name = info.completeBaseName();
//extract basename with extension
QString name = info.completeBaseName() + "." + QFileInfo( thePath ).suffix();
QString uri = thePath;

QgsLayerItem * item = new QgsGdalLayerItem( parentItem, name, thePath, uri );
Expand All @@ -124,11 +131,10 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
if ( hChildDS )
{
GDALClose( hChildDS );
QgsDebugMsg( QString( "add child #%1 - %2" ).arg( i ).arg( sublayers[i] ) );

QString name = sublayers[i];
name.replace( thePath, QFileInfo( thePath ).completeBaseName() );

//replace full path with basename+extension
name.replace( thePath, QFileInfo( thePath ).completeBaseName() + "." + QFileInfo( thePath ).suffix() );
childItem = new QgsGdalLayerItem( item, name, thePath + "/" + name, sublayers[i] );
if ( childItem )
item->addChildItem( childItem );
Expand Down
12 changes: 11 additions & 1 deletion src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -1267,7 +1267,10 @@ QStringList QgsGdalProvider::subLayers( GDALDatasetH dataset )
}
}

QgsDebugMsg( "sublayers:\n " + subLayers.join( "\n " ) );
if ( subLayers.size() > 0 )
{
QgsDebugMsg( "sublayers:\n " + subLayers.join( "\n " ) );
}

return subLayers;
}
Expand Down Expand Up @@ -1801,6 +1804,13 @@ void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString
theFileFiltersString += ";;[GDAL] " + myGdalDriverLongName + " (" + glob.toLower() + " " + glob.toUpper() + ")";
theWildcards << "hdr.adf";
}
else if ( myGdalDriverDescription == "HDF4" )
{
// HDF4 extension missing in driver metadata
QString glob = "*.hdf";
theFileFiltersString += ";;[GDAL] " + myGdalDriverLongName + " (" + glob.toLower() + " " + glob.toUpper() + ")";
theExtensions << "hdf";
}
else
{
catchallFilter << QString( GDALGetDescription( myGdalDriver ) );
Expand Down

0 comments on commit a2b80be

Please sign in to comment.