Skip to content
Permalink
Browse files

responding to github comments, simplified behavior to display the ban…

…d name if present 'Band #: Band Name'. removed options
  • Loading branch information
AndrewAnnex authored and nyalldawson committed Oct 8, 2018
1 parent b86f84e commit c4872b844b38ffb8c28893294b064e08ec997075
Showing with 55 additions and 122 deletions.
  1. +0 −15 src/app/qgsoptions.cpp
  2. +55 −67 src/providers/gdal/qgsgdalprovider.cpp
  3. +0 −40 src/ui/qgsoptionsbase.ui
@@ -418,20 +418,6 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
cmbPromptRasterSublayers->addItem( tr( "Load all" ) );
cmbPromptRasterSublayers->setCurrentIndex( mSettings->value( QStringLiteral( "/qgis/promptForRasterSublayers" ), 0 ).toInt() );

// decide how qgis should use band names (if present) in raster sources
// 0 = Band Number -> Default behavior is to just use band numbers
// 1 = Band Name -> Uses available band name
// 2 = Band Name & Number -> Uses available band name with a band number-> "name (band #)"
// 3 = Band Name & Number -> Uses band number with available band name-> "band # (name)"
// 4 = Use _DIM_EXTRA -> Uses "_DIM_EXTRA" metadata attribute in netCDF and geotiff
cmbUseOfRasterBandNames->clear();
cmbUseOfRasterBandNames->addItem( tr( "Band Number" ) );
cmbUseOfRasterBandNames->addItem( tr( "Band Name" ) );
cmbUseOfRasterBandNames->addItem( tr( "Band Name & Number" ) );
cmbUseOfRasterBandNames->addItem( tr( "Band Number & Name" ) );
cmbUseOfRasterBandNames->addItem( tr( "Use _DIM_EXTRA" ) );
cmbUseOfRasterBandNames->setCurrentIndex( mSettings->value( QStringLiteral( "/qgis/useOfRasterBandNames" ), 0 ).toInt() );

// Scan for valid items in the browser dock
cmbScanItemsInBrowser->clear();
cmbScanItemsInBrowser->addItem( tr( "Check file contents" ), "contents" ); // 0
@@ -1403,7 +1389,6 @@ void QgsOptions::saveOptions()
mSettings->setValue( QStringLiteral( "/qgis/attributeTableView" ), mAttrTableViewComboBox->currentData() );
mSettings->setValue( QStringLiteral( "/qgis/attributeTableRowCache" ), spinBoxAttrTableRowCache->value() );
mSettings->setValue( QStringLiteral( "/qgis/promptForRasterSublayers" ), cmbPromptRasterSublayers->currentIndex() );
mSettings->setValue( QStringLiteral( "/qgis/useOfRasterBandNames" ), cmbUseOfRasterBandNames->currentIndex() );
mSettings->setValue( QStringLiteral( "/qgis/scanItemsInBrowser2" ),
cmbScanItemsInBrowser->currentData().toString() );
mSettings->setValue( QStringLiteral( "/qgis/scanZipInBrowser2" ),
@@ -933,77 +933,65 @@ QString QgsGdalProvider::generateBandName( int bandNumber ) const
if ( !const_cast<QgsGdalProvider *>( this )->initIfNeeded() )
return QString();

if ( strcmp( GDALGetDriverShortName( GDALGetDatasetDriver( mGdalDataset ) ), "netCDF" ) == 0 || strcmp( GDALGetDriverShortName( GDALGetDatasetDriver( mGdalDataset ) ), "GTiff" ) == 0 )
{
char **GDALmetadata = GDALGetMetadata(mGdalDataset, nullptr);
if (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=")))
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(',');
//http://qt-project.org/doc/qt-4.8/qregexp.html#capturedTexts
} else {
unitsMap[values.at(0).split('#').at(0)] = val;
}
}
if (!dimExtraValues.isEmpty())
{
QStringList bandNameValues;
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)
{
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)
{
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] + ')');
else
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(" / ")));
}
}
}
QString generatedBandName = QgsRasterDataProvider::generateBandName( bandNumber );
GDALRasterBandH myGdalBand = getBand( bandNumber );
QString gdalBandName(GDALGetDescription(myGdalBand));

QgsSettings settings;
switch(settings.value(QStringLiteral( "/qgis/useOfRasterBandNames" )).toInt()) {
case 0 :
return generatedBandName;
case 1 :
if ( !gdalBandName.isEmpty() ) {
return gdalBandName;
}
// if we didn't find a band name use the generated one
break;
case 2 :
return gdalBandName + QStringLiteral(" (") + generatedBandName + QStringLiteral(")");
case 3 :
return generatedBandName + QStringLiteral(" (") + gdalBandName + QStringLiteral(")");
case 4 :
if ( strcmp( GDALGetDriverShortName( GDALGetDatasetDriver( mGdalDataset ) ), "netCDF" ) == 0 || strcmp( GDALGetDriverShortName( GDALGetDatasetDriver( mGdalDataset ) ), "GTiff" ) == 0 ) {
char **GDALmetadata = GDALGetMetadata(mGdalDataset, nullptr);

if (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=")))
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(',');
//http://qt-project.org/doc/qt-4.8/qregexp.html#capturedTexts
} else {
unitsMap[values.at(0).split('#').at(0)] = val;
}
}
if (!dimExtraValues.isEmpty()) {
QStringList bandNameValues;
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) {
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) {
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] + ')');
else
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(" / ")));
}
}
}
break;
if(!gdalBandName.isEmpty())
{
return generatedBandName + QStringLiteral(": ") + gdalBandName;
}

return generatedBandName;
}

@@ -2007,45 +2007,6 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_38">
<item>
<widget class="QLabel" name="textLabel1_15">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Change raster band name behavior</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_38">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="cmbUseOfRasterBandNames">
<item>
<property name="text">
<string/>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="cbxIgnoreShapeEncoding">
<property name="toolTip">
@@ -5645,7 +5606,6 @@ p, li { white-space: pre-wrap; }
<tabstop>cmbScanItemsInBrowser</tabstop>
<tabstop>cmbScanZipInBrowser</tabstop>
<tabstop>cmbPromptRasterSublayers</tabstop>
<tabstop>cmbUseOfRasterBandNames</tabstop>
<tabstop>cbxIgnoreShapeEncoding</tabstop>
<tabstop>cbxAddPostgisDC</tabstop>
<tabstop>cbxAddOracleDC</tabstop>

0 comments on commit c4872b8

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