Skip to content
Permalink
Browse files

addressed comments, ran prepare-commit.sh

  • Loading branch information
AndrewAnnex authored and nyalldawson committed Oct 9, 2018
1 parent c04accd commit 8fbb71758044c7e2a221737285946f1ccc6cdb22
Showing with 35 additions and 43 deletions.
  1. +32 −28 src/providers/gdal/qgsgdalprovider.cpp
  2. +3 −15 tests/src/providers/testqgsgdalprovider.cpp
@@ -935,64 +935,68 @@ QString QgsGdalProvider::generateBandName( int bandNumber ) const

if ( strcmp( GDALGetDriverShortName( GDALGetDatasetDriver( mGdalDataset ) ), "netCDF" ) == 0 || strcmp( GDALGetDriverShortName( GDALGetDatasetDriver( mGdalDataset ) ), "GTiff" ) == 0 )
{
char **GDALmetadata = GDALGetMetadata(mGdalDataset, nullptr);
char **GDALmetadata = GDALGetMetadata( mGdalDataset, nullptr );
if ( GDALmetadata )
{
QStringList metadata = QgsOgrUtils::cStringListToQStringList(GDALmetadata);
QStringList metadata = QgsOgrUtils::cStringListToQStringList( GDALmetadata );
QStringList dimExtraValues;
QMap<QString, QString> unitsMap;
for (QStringList::const_iterator i = metadata.constBegin(); i != metadata.constEnd(); ++i) {
QString val(*i);
if ( !val.startsWith(QLatin1String("NETCDF_DIM_EXTRA")) && !val.startsWith(QLatin1String("GTIFF_DIM_EXTRA")) && !val.contains(QLatin1String("#units=")) )
for ( QStringList::const_iterator i = metadata.constBegin(); i != metadata.constEnd(); ++i )
{
QString val( *i );
if ( !val.startsWith( QLatin1String( "NETCDF_DIM_EXTRA" ) ) && !val.startsWith( QLatin1String( "GTIFF_DIM_EXTRA" ) ) && !val.contains( QLatin1String( "#units=" ) ) )
continue;
QStringList values = val.split('=');
val = values.at(1);
if ( values.at(0) == QLatin1String("NETCDF_DIM_EXTRA") || values.at(0) == QLatin1String("GTIFF_DIM_EXTRA") ) {
dimExtraValues = val.replace('{', QString()).replace('}', QString()).split(',');
QStringList values = val.split( '=' );
val = values.at( 1 );
if ( values.at( 0 ) == QLatin1String( "NETCDF_DIM_EXTRA" ) || values.at( 0 ) == QLatin1String( "GTIFF_DIM_EXTRA" ) )
{
dimExtraValues = val.replace( '{', QString() ).replace( '}', QString() ).split( ',' );
//http://qt-project.org/doc/qt-4.8/qregexp.html#capturedTexts
} else {
unitsMap[values.at(0).split('#').at(0)] = val;
}
else
{
unitsMap[values.at( 0 ).split( '#' ).at( 0 )] = val;
}
}
if ( !dimExtraValues.isEmpty() )
{
QStringList bandNameValues;
GDALRasterBandH gdalBand = GDALGetRasterBand(mGdalDataset, bandNumber);
GDALmetadata = GDALGetMetadata(gdalBand, nullptr);
GDALRasterBandH gdalBand = GDALGetRasterBand( mGdalDataset, bandNumber );
GDALmetadata = GDALGetMetadata( gdalBand, nullptr );
if ( GDALmetadata )
{
metadata = QgsOgrUtils::cStringListToQStringList(GDALmetadata);
for (QStringList::const_iterator i = metadata.constBegin(); i != metadata.constEnd(); ++i)
metadata = QgsOgrUtils::cStringListToQStringList( GDALmetadata );
for ( QStringList::const_iterator i = metadata.constBegin(); i != metadata.constEnd(); ++i )
{
QString val(*i);
if ( !val.startsWith(QLatin1String("NETCDF_DIM_")) && !val.startsWith(QLatin1String("GTIFF_DIM_")) )
QString val( *i );
if ( !val.startsWith( QLatin1String( "NETCDF_DIM_" ) ) && !val.startsWith( QLatin1String( "GTIFF_DIM_" ) ) )
continue;
QStringList values = val.split('=');
for (QStringList::const_iterator j = dimExtraValues.constBegin(); j != dimExtraValues.constEnd(); ++j)
QStringList values = val.split( '=' );
for ( QStringList::const_iterator j = dimExtraValues.constBegin(); j != dimExtraValues.constEnd(); ++j )
{
QString dim = (*j);
if ( values.at(0) != "NETCDF_DIM_" + dim && values.at(0) != "GTIFF_DIM_" + dim )
QString dim = ( *j );
if ( values.at( 0 ) != "NETCDF_DIM_" + dim && values.at( 0 ) != "GTIFF_DIM_" + dim )
continue;
if ( unitsMap.contains(dim) && !unitsMap[dim].isEmpty() && unitsMap[dim] != QLatin1String("none") )
bandNameValues.append(dim + '=' + values.at(1) + " (" + unitsMap[dim] + ')');
if ( unitsMap.contains( dim ) && !unitsMap[dim].isEmpty() && unitsMap[dim] != QLatin1String( "none" ) )
bandNameValues.append( dim + '=' + values.at( 1 ) + " (" + unitsMap[dim] + ')' );
else
bandNameValues.append(dim + '=' + values.at(1));
bandNameValues.append( dim + '=' + values.at( 1 ) );
}
}
}
if ( !bandNameValues.isEmpty() )
{
return tr("Band") + QStringLiteral(" %1 / %2").arg(bandNumber, 1 + (int) std::log10((float) bandCount()), 10, QChar('0')).arg(bandNameValues.join(QStringLiteral(" / ")));
return tr( "Band" ) + QStringLiteral( " %1: %2" ).arg( bandNumber, 1 + ( int ) std::log10( ( float ) bandCount() ), 10, QChar( '0' ) ).arg( bandNameValues.join( QStringLiteral( " / " ) ) );
}
}
}
}
QString generatedBandName = QgsRasterDataProvider::generateBandName( bandNumber );
GDALRasterBandH myGdalBand = getBand( bandNumber );
QString gdalBandName(GDALGetDescription(myGdalBand));
if( !gdalBandName.isEmpty() )
QString gdalBandName( GDALGetDescription( myGdalBand ) );
if ( !gdalBandName.isEmpty() )
{
return generatedBandName + QStringLiteral(": ") + gdalBandName;
return generatedBandName + QStringLiteral( ": " ) + gdalBandName;
}
return generatedBandName;
}
@@ -251,11 +251,7 @@ void TestQgsGdalProvider::bandName()
QgsDataProvider *provider = QgsProviderRegistry::instance()->createProvider( QStringLiteral( "gdal" ), raster, QgsDataProvider::ProviderOptions() );
QgsRasterDataProvider *rp = dynamic_cast< QgsRasterDataProvider * >( provider );
QVERIFY( rp );
if ( rp )
{
qDebug() << "Band Name 1: " << rp->generateBandName( 1 );
QCOMPARE( rp->generateBandName( 1 ), QStringLiteral( "Band 1 / wvln=1.234 (um)" ) );
}
QCOMPARE( rp->generateBandName( 1 ), QStringLiteral( "Band 1: wvln=1.234 (um)" ) );
delete provider;
}

@@ -265,11 +261,7 @@ void TestQgsGdalProvider::bandNameNoDescription()
QgsDataProvider *provider = QgsProviderRegistry::instance()->createProvider( QStringLiteral( "gdal" ), raster, QgsDataProvider::ProviderOptions() );
QgsRasterDataProvider *rp = dynamic_cast< QgsRasterDataProvider * >( provider );
QVERIFY( rp );
if ( rp )
{
qDebug() << "Band Name 1: " << rp->generateBandName( 1 );
QCOMPARE( rp->generateBandName( 1 ), QStringLiteral( "Band 1" ) );
}
QCOMPARE( rp->generateBandName( 1 ), QStringLiteral( "Band 1" ) );
delete provider;
}

@@ -279,11 +271,7 @@ void TestQgsGdalProvider::bandNameWithDescription()
QgsDataProvider *provider = QgsProviderRegistry::instance()->createProvider( QStringLiteral( "gdal" ), raster, QgsDataProvider::ProviderOptions() );
QgsRasterDataProvider *rp = dynamic_cast< QgsRasterDataProvider * >( provider );
QVERIFY( rp );
if ( rp )
{
qDebug() << "Band Name 1: " << rp->generateBandName( 1 );
QCOMPARE( rp->generateBandName( 1 ), QStringLiteral( "Band 1: 1.234 um" ) );
}
QCOMPARE( rp->generateBandName( 1 ), QStringLiteral( "Band 1: 1.234 um" ) );
delete provider;
}

0 comments on commit 8fbb717

Please sign in to comment.
You can’t perform that action at this time.