Skip to content
Permalink
Browse files

[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)
  • Loading branch information
rouault committed May 27, 2016
1 parent 2861cf1 commit 1ce34c363fc402e5d31184ed271548535fa42d89
@@ -31,6 +31,9 @@

QMap< QString, QStringList > QgsRasterFormatSaveOptionsWidget::mBuiltinProfiles;

static const QString PYRAMID_JPEG_YCBCR_COMPRESSION( "JPEG_QUALITY_OVERVIEW=75 COMPRESS_OVERVIEW=JPEG PHOTOMETRIC_OVERVIEW=YCBCR INTERLEAVE_OVERVIEW=PIXEL" );
static const QString PYRAMID_JPEG_COMPRESSION( "JPEG_QUALITY_OVERVIEW=75 COMPRESS_OVERVIEW=JPEG INTERLEAVE_OVERVIEW=PIXEL" );

QgsRasterFormatSaveOptionsWidget::QgsRasterFormatSaveOptionsWidget( QWidget* parent, const QString& format,
QgsRasterFormatSaveOptionsWidget::Type type, const QString& provider )
: QWidget( parent )
@@ -81,7 +84,7 @@ QgsRasterFormatSaveOptionsWidget::QgsRasterFormatSaveOptionsWidget( QWidget* par
<< "COMPRESS_OVERVIEW=DEFLATE PREDICTOR_OVERVIEW=2 ZLEVEL=9" ); // how to set zlevel?
mBuiltinProfiles[ "z__pyramids_gtiff_4jpeg" ] =
( QStringList() << "_pyramids" << tr( "JPEG compression" )
<< "JPEG_QUALITY_OVERVIEW=75 COMPRESS_OVERVIEW=JPEG PHOTOMETRIC_OVERVIEW=YCBCR INTERLEAVE_OVERVIEW=PIXEL" );
<< PYRAMID_JPEG_YCBCR_COMPRESSION );
}

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

// If the default JPEG compression profile was selected, remove PHOTOMETRIC_OVERVIEW=YCBCR
// if the raster is not RGB. Otherwise this is bound to fail afterwards.
if ( mRasterLayer && mRasterLayer->bandCount() != 3 &&
myOptions == PYRAMID_JPEG_YCBCR_COMPRESSION )
{
myOptions = PYRAMID_JPEG_COMPRESSION;
}

if ( mOptionsStackedWidget->currentIndex() == 0 )
{
mOptionsTable->setRowCount( 0 );
@@ -21,6 +21,8 @@
#include "qgsrasterformatsaveoptionswidget.h"
#include "qgsgenericprojectionselector.h"

#include "gdal.h"

#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
@@ -2970,7 +2970,7 @@ QString QgsGdalProvider::validateCreationOptions( const QStringList& createOptio
return message;
}

QString QgsGdalProvider::validatePyramidsCreationOptions( QgsRaster::RasterPyramidsFormat pyramidsFormat,
QString QgsGdalProvider::validatePyramidsConfigOptions( QgsRaster::RasterPyramidsFormat pyramidsFormat,
const QStringList & theConfigOptions, const QString & fileFormat )
{
// Erdas Imagine format does not support config options
@@ -2985,21 +2985,19 @@ QString QgsGdalProvider::validatePyramidsCreationOptions( QgsRaster::RasterPyram
else if ( pyramidsFormat == QgsRaster::PyramidsInternal )
{
QStringList supportedFormats;
supportedFormats << "gtiff" << "georaster" << "hfa" << "jp2kak" << "mrsid" << "nitf";
supportedFormats << "gtiff" << "georaster" << "hfa" << "gpkg" << "rasterlite" << "nitf";
if ( ! supportedFormats.contains( fileFormat.toLower() ) )
return QString( "Internal pyramids format only supported for gtiff/georaster/hfa/jp2kak/mrsid/nitf files (using %1)" ).arg( fileFormat );
// TODO - check arguments for georaster hfa jp2kak mrsid nitf
// for now, only test gtiff
else if ( fileFormat.toLower() != "gtiff" )
return QString();
return QString( "Internal pyramids format only supported for gtiff/georaster/gpkg/rasterlite/nitf files (using %1)" ).arg( fileFormat );
}

// for gtiff external or internal pyramids, validate gtiff-specific values
// PHOTOMETRIC_OVERVIEW=YCBCR requires a source raster with only 3 bands (RGB)
if ( theConfigOptions.contains( "PHOTOMETRIC_OVERVIEW=YCBCR" ) )
else
{
if ( GDALGetRasterCount( mGdalDataset ) != 3 )
return "PHOTOMETRIC_OVERVIEW=YCBCR requires a source raster with only 3 bands (RGB)";
// for gtiff external pyramids, validate gtiff-specific values
// PHOTOMETRIC_OVERVIEW=YCBCR requires a source raster with only 3 bands (RGB)
if ( theConfigOptions.contains( "PHOTOMETRIC_OVERVIEW=YCBCR" ) )
{
if ( GDALGetRasterCount( mGdalDataset ) != 3 )
return "PHOTOMETRIC_OVERVIEW=YCBCR requires a source raster with only 3 bands (RGB)";
}
}

return QString();
@@ -244,8 +244,8 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
bool remove() override;

QString validateCreationOptions( const QStringList& createOptions, const QString& format ) override;
QString validatePyramidsCreationOptions( QgsRaster::RasterPyramidsFormat pyramidsFormat,
const QStringList & theConfigOptions, const QString & fileFormat );
QString validatePyramidsConfigOptions( QgsRaster::RasterPyramidsFormat pyramidsFormat,
const QStringList & theConfigOptions, const QString & fileFormat ) override;

private:
// update mode

0 comments on commit 1ce34c3

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