Skip to content

Commit 1ce34c3

Browse files
committedMay 27, 2016
[GDAL provider] Fixes related to pyramid option validation
- The method QgsGdalProvider::validatePyramidsCreationOptions() was a wrong name and should have been an override of the base validatePyramidsConfigOptions(). This issue existed since it was introduced in 2fb78db, so this method couldn't be called - Fix in it the list of formats that accept internal overviews. And other clean-up - In QgsRasterFormatSaveOptionsWidget(), when called from the Save as dialog, add logic to avoid that selecting the "JPEG compression" profile for overviews results in PHOTOMETRIC_OVERVIEW=YCBCR to be added in the option string for non-RGB datasets (will now fail the validation, and previously would have caused overview generation to fail)
1 parent 2861cf1 commit 1ce34c3

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed
 

‎src/gui/qgsrasterformatsaveoptionswidget.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232
QMap< QString, QStringList > QgsRasterFormatSaveOptionsWidget::mBuiltinProfiles;
3333

34+
static const QString PYRAMID_JPEG_YCBCR_COMPRESSION( "JPEG_QUALITY_OVERVIEW=75 COMPRESS_OVERVIEW=JPEG PHOTOMETRIC_OVERVIEW=YCBCR INTERLEAVE_OVERVIEW=PIXEL" );
35+
static const QString PYRAMID_JPEG_COMPRESSION( "JPEG_QUALITY_OVERVIEW=75 COMPRESS_OVERVIEW=JPEG INTERLEAVE_OVERVIEW=PIXEL" );
36+
3437
QgsRasterFormatSaveOptionsWidget::QgsRasterFormatSaveOptionsWidget( QWidget* parent, const QString& format,
3538
QgsRasterFormatSaveOptionsWidget::Type type, const QString& provider )
3639
: QWidget( parent )
@@ -81,7 +84,7 @@ QgsRasterFormatSaveOptionsWidget::QgsRasterFormatSaveOptionsWidget( QWidget* par
8184
<< "COMPRESS_OVERVIEW=DEFLATE PREDICTOR_OVERVIEW=2 ZLEVEL=9" ); // how to set zlevel?
8285
mBuiltinProfiles[ "z__pyramids_gtiff_4jpeg" ] =
8386
( QStringList() << "_pyramids" << tr( "JPEG compression" )
84-
<< "JPEG_QUALITY_OVERVIEW=75 COMPRESS_OVERVIEW=JPEG PHOTOMETRIC_OVERVIEW=YCBCR INTERLEAVE_OVERVIEW=PIXEL" );
87+
<< PYRAMID_JPEG_YCBCR_COMPRESSION );
8588
}
8689

8790
connect( mProfileComboBox, SIGNAL( currentIndexChanged( const QString & ) ),
@@ -209,6 +212,14 @@ void QgsRasterFormatSaveOptionsWidget::updateOptions()
209212
QString myOptions = mOptionsMap.value( currentProfileKey() );
210213
QStringList myOptionsList = myOptions.trimmed().split( ' ', QString::SkipEmptyParts );
211214

215+
// If the default JPEG compression profile was selected, remove PHOTOMETRIC_OVERVIEW=YCBCR
216+
// if the raster is not RGB. Otherwise this is bound to fail afterwards.
217+
if ( mRasterLayer && mRasterLayer->bandCount() != 3 &&
218+
myOptions == PYRAMID_JPEG_YCBCR_COMPRESSION )
219+
{
220+
myOptions = PYRAMID_JPEG_COMPRESSION;
221+
}
222+
212223
if ( mOptionsStackedWidget->currentIndex() == 0 )
213224
{
214225
mOptionsTable->setRowCount( 0 );

‎src/gui/qgsrasterlayersaveasdialog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "qgsrasterformatsaveoptionswidget.h"
2222
#include "qgsgenericprojectionselector.h"
2323

24+
#include "gdal.h"
25+
2426
#include <QFileDialog>
2527
#include <QMessageBox>
2628
#include <QSettings>

‎src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,7 +2970,7 @@ QString QgsGdalProvider::validateCreationOptions( const QStringList& createOptio
29702970
return message;
29712971
}
29722972

2973-
QString QgsGdalProvider::validatePyramidsCreationOptions( QgsRaster::RasterPyramidsFormat pyramidsFormat,
2973+
QString QgsGdalProvider::validatePyramidsConfigOptions( QgsRaster::RasterPyramidsFormat pyramidsFormat,
29742974
const QStringList & theConfigOptions, const QString & fileFormat )
29752975
{
29762976
// Erdas Imagine format does not support config options
@@ -2985,21 +2985,19 @@ QString QgsGdalProvider::validatePyramidsCreationOptions( QgsRaster::RasterPyram
29852985
else if ( pyramidsFormat == QgsRaster::PyramidsInternal )
29862986
{
29872987
QStringList supportedFormats;
2988-
supportedFormats << "gtiff" << "georaster" << "hfa" << "jp2kak" << "mrsid" << "nitf";
2988+
supportedFormats << "gtiff" << "georaster" << "hfa" << "gpkg" << "rasterlite" << "nitf";
29892989
if ( ! supportedFormats.contains( fileFormat.toLower() ) )
2990-
return QString( "Internal pyramids format only supported for gtiff/georaster/hfa/jp2kak/mrsid/nitf files (using %1)" ).arg( fileFormat );
2991-
// TODO - check arguments for georaster hfa jp2kak mrsid nitf
2992-
// for now, only test gtiff
2993-
else if ( fileFormat.toLower() != "gtiff" )
2994-
return QString();
2990+
return QString( "Internal pyramids format only supported for gtiff/georaster/gpkg/rasterlite/nitf files (using %1)" ).arg( fileFormat );
29952991
}
2996-
2997-
// for gtiff external or internal pyramids, validate gtiff-specific values
2998-
// PHOTOMETRIC_OVERVIEW=YCBCR requires a source raster with only 3 bands (RGB)
2999-
if ( theConfigOptions.contains( "PHOTOMETRIC_OVERVIEW=YCBCR" ) )
2992+
else
30002993
{
3001-
if ( GDALGetRasterCount( mGdalDataset ) != 3 )
3002-
return "PHOTOMETRIC_OVERVIEW=YCBCR requires a source raster with only 3 bands (RGB)";
2994+
// for gtiff external pyramids, validate gtiff-specific values
2995+
// PHOTOMETRIC_OVERVIEW=YCBCR requires a source raster with only 3 bands (RGB)
2996+
if ( theConfigOptions.contains( "PHOTOMETRIC_OVERVIEW=YCBCR" ) )
2997+
{
2998+
if ( GDALGetRasterCount( mGdalDataset ) != 3 )
2999+
return "PHOTOMETRIC_OVERVIEW=YCBCR requires a source raster with only 3 bands (RGB)";
3000+
}
30033001
}
30043002

30053003
return QString();

‎src/providers/gdal/qgsgdalprovider.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
244244
bool remove() override;
245245

246246
QString validateCreationOptions( const QStringList& createOptions, const QString& format ) override;
247-
QString validatePyramidsCreationOptions( QgsRaster::RasterPyramidsFormat pyramidsFormat,
248-
const QStringList & theConfigOptions, const QString & fileFormat );
247+
QString validatePyramidsConfigOptions( QgsRaster::RasterPyramidsFormat pyramidsFormat,
248+
const QStringList & theConfigOptions, const QString & fileFormat ) override;
249249

250250
private:
251251
// update mode

0 commit comments

Comments
 (0)
Please sign in to comment.