Skip to content

Commit

Permalink
update raster format and pyramid save widgets for python, add pyramid…
Browse files Browse the repository at this point in the history
… config options support to raster writer, other fixes
  • Loading branch information
etiennesky committed Jan 18, 2013
1 parent 0dbb781 commit 2fb78db
Show file tree
Hide file tree
Showing 21 changed files with 455 additions and 187 deletions.
28 changes: 19 additions & 9 deletions python/core/raster/qgsrasterdataprovider.sip
Expand Up @@ -169,10 +169,11 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
virtual QStringList subLayers() const;

/** \brief Create pyramid overviews */
virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
const QString & theResamplingMethod = "NEAREST",
RasterPyramidsFormat theFormat = PyramidsGTiff );

virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
const QString & theResamplingMethod = "NEAREST",
RasterPyramidsFormat theFormat = PyramidsGTiff,
const QStringList & theConfigOptions = QStringList() );

/** \brief Accessor for ths raster layers pyramid list.
* @param overviewList used to construct the pyramid list (optional), when empty the list is defined by the provider.
* A pyramid list defines the
Expand Down Expand Up @@ -269,13 +270,22 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
/** Remove dataset*/
virtual bool remove();

static QStringList pyramidResamplingMethods( QString providerKey );
/** Returns a list of pyramid resampling method names for given provider */
static QStringList pyramidResamplingMethods( QString providerKey = "gdal" );
/** Returns the pyramid resampling argument that corresponds to a given method */
static QString pyramidResamplingArg( QString method, QString providerKey = "gdal" );

/** Validates creation options for a specific dataset and destination format.
* @note used by GDAL provider only
* @note see also validateCreationOptionsFormat() in gdal provider for validating options based on format only */
virtual QString validateCreationOptions( const QStringList& createOptions, QString format );

/** Validates creation options for a specific dataset and destination format - used by GDAL provider only.
* See also validateCreationOptionsFormat() in gdal provider for validating options based on format only. */
virtual QString validateCreationOptions( const QStringList& createOptions, QString format );
/** Validates pyramid creation options for a specific dataset and destination format
* @note used by GDAL provider only */
virtual QString validatePyramidsConfigOptions( RasterPyramidsFormat pyramidsFormat,
const QStringList & theConfigOptions, const QString & fileFormat );

signals:
signals:
/** Emit a signal to notify of the progress event.
* Emited theProgress is in percents (0.0-100.0) */
void progress( int theType, double theProgress, QString theMessage );
Expand Down
4 changes: 3 additions & 1 deletion python/core/raster/qgsrasterfilewriter.sip
Expand Up @@ -59,8 +59,10 @@ class QgsRasterFileWriter
void setMaxTileHeight( int h );
int maxTileHeight() const;

// for now not putting createOptions in all methods, use createOptions()
void setCreateOptions( const QStringList& list );
QStringList createOptions() const;

QStringList pyramidsConfigOptions() const;
void setPyramidsConfigOptions( const QStringList& list );
};

2 changes: 2 additions & 0 deletions python/gui/qgsrasterformatsaveoptionswidget.sip
Expand Up @@ -24,8 +24,10 @@ class QgsRasterFormatSaveOptionsWidget : QWidget
void setFormat( QString format );
void setProvider( QString provider );
void setRasterLayer( QgsRasterLayer* rasterLayer );
void setRasterFileName( const QString& file );
QStringList options() const;
void setType( QgsRasterFormatSaveOptionsWidget::Type type = Default );
void setPyramidsFormat( QgsRasterDataProvider::RasterPyramidsFormat format );

public slots:

Expand Down
5 changes: 3 additions & 2 deletions python/gui/qgsrasterlayersaveasdialog.sip
Expand Up @@ -48,10 +48,11 @@ class QgsRasterLayerSaveAsDialog : QDialog
QgsRectangle outputRectangle() const;
QList<QgsRasterNuller::NoData> noData() const;

QList< int > overviewList() const;
QList< int > pyramidsList() const;
QgsRasterDataProvider::RasterBuildPyramids buildPyramidsFlag() const;
QString pyramidsResampling() const;
QString pyramidsResamplingMethod() const;
QgsRasterDataProvider::RasterPyramidsFormat pyramidsFormat() const;
QStringList pyramidsConfigOptions() const;

void hideFormat();
void hideOutput();
Expand Down
11 changes: 10 additions & 1 deletion python/gui/qgsrasterpyramidsoptionswidget.sip
Expand Up @@ -12,17 +12,26 @@ class QgsRasterPyramidsOptionsWidget: QWidget
QgsRasterPyramidsOptionsWidget( QWidget* parent = 0, QString provider = "gdal" );
~QgsRasterPyramidsOptionsWidget();

QStringList createOptions() const;
QStringList configOptions() const;
QgsRasterFormatSaveOptionsWidget* createOptionsWidget() /Factory/;
const QList<int> overviewList() const;
QgsRasterDataProvider::RasterPyramidsFormat pyramidsFormat() const;
QString resamplingMethod() const;
void setRasterLayer( QgsRasterLayer* rasterLayer );
void setRasterFileName( const QString& file );

public slots:

void apply();
void checkAllLevels( bool checked );

private slots:

void on_cbxPyramidsLevelsCustom_toggled( bool toggled );
void on_cbxPyramidsFormat_currentIndexChanged( int index );
void setOverviewList();
void updateUi();

signals:
void overviewListChanged();
};
5 changes: 3 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -4204,9 +4204,10 @@ void QgisApp::saveAsRasterFile()
fileWriter.setCreateOptions( d.createOptions() );

fileWriter.setBuildPyramidsFlag( d.buildPyramidsFlag() );
fileWriter.setPyramidsList( d.overviewList() );
fileWriter.setPyramidsResampling( d.pyramidsResampling() );
fileWriter.setPyramidsList( d.pyramidsList() );
fileWriter.setPyramidsResampling( d.pyramidsResamplingMethod() );
fileWriter.setPyramidsFormat( d.pyramidsFormat() );
fileWriter.setPyramidsConfigOptions( d.pyramidsConfigOptions() );

QgsRasterFileWriter::WriterError err = fileWriter.writeRaster( pipe, d.nColumns(), d.nRows(), d.outputRectangle(), d.outputCrs(), &pd );
if ( err != QgsRasterFileWriter::NoError )
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgis.h
Expand Up @@ -336,6 +336,8 @@ const double DEFAULT_LINE_WIDTH = 0.26;
/** default snapping tolerance for segments (@note added in 1.8) */
const double DEFAULT_SEGMENT_EPSILON = 1e-8;

typedef QMap<QString, QString> QgsStringMap;

// FIXME: also in qgisinterface.h
#ifndef QGISEXTERN
#ifdef WIN32
Expand Down
57 changes: 57 additions & 0 deletions src/core/raster/qgsrasterdataprovider.cpp
Expand Up @@ -387,6 +387,63 @@ QString QgsRasterDataProvider::lastErrorFormat()
return "text/plain";
}

// pyramids resampling

// TODO move this to gdal provider
// but we need some way to get a static instance of the provider
// or use function pointers like in QgsRasterFormatSaveOptionsWidget::helpOptions()

// see http://www.gdal.org/gdaladdo.html
// http://www.gdal.org/classGDALDataset.html#a2aa6f88b3bbc840a5696236af11dde15
// http://www.gdal.org/classGDALRasterBand.html#afaea945b13ec9c86c2d783b883c68432

// from http://www.gdal.org/gdaladdo.html
// average_mp is unsuitable for use thus not included

// from qgsgdalprovider.cpp (removed)
// NOTE magphase is disabled in the gui since it tends
// to create corrupted images. The images can be repaired
// by running one of the other resampling strategies below.
// see ticket #284
QStringList QgsRasterDataProvider::mPyramidResamplingListGdal = QStringList();
QgsStringMap QgsRasterDataProvider::mPyramidResamplingMapGdal = QgsStringMap();

void QgsRasterDataProvider::initPyramidResamplingDefs()
{
mPyramidResamplingListGdal.clear();
mPyramidResamplingListGdal << tr( "Nearest Neighbour" ) << tr( "Average" ) << tr( "Gauss" ) << tr( "Cubic" ) << tr( "Mode" ) << tr( "None" ); // << tr( "Average magphase" )
mPyramidResamplingMapGdal.clear();
mPyramidResamplingMapGdal[ tr( "Nearest Neighbour" )] = "NEAREST";
mPyramidResamplingMapGdal[ tr( "Average" )] = "AVERAGE";
mPyramidResamplingMapGdal[ tr( "Gauss" )] = "GAUSS";
mPyramidResamplingMapGdal[ tr( "Cubic" )] = "CUBIC";
mPyramidResamplingMapGdal[ tr( "Mode" )] = "MODE";
// mPyramidResamplingMapGdal[ tr( "Average magphase" ) ] = "average_magphase";
mPyramidResamplingMapGdal[ tr( "None" )] = "NONE" ;
}

QStringList QgsRasterDataProvider::pyramidResamplingMethods( QString providerKey )
{
if ( mPyramidResamplingListGdal.isEmpty() )
initPyramidResamplingDefs();

return providerKey == "gdal" ? mPyramidResamplingListGdal : QStringList();
}

QString QgsRasterDataProvider::pyramidResamplingArg( QString method, QString providerKey )
{
if ( providerKey != "gdal" )
return QString();

if ( mPyramidResamplingListGdal.isEmpty() )
initPyramidResamplingDefs();

if ( mPyramidResamplingMapGdal.contains( method ) )
return mPyramidResamplingMapGdal.value( method );
else
return "NEAREST";
}

bool QgsRasterDataProvider::hasPyramids()
{
QList<QgsRasterPyramid> myPyramidList = buildPyramidList();
Expand Down
35 changes: 23 additions & 12 deletions src/core/raster/qgsrasterdataprovider.h
Expand Up @@ -290,11 +290,13 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
}

/** \brief Create pyramid overviews */
virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
const QString & theResamplingMethod = "NEAREST",
RasterPyramidsFormat theFormat = PyramidsGTiff )
virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
const QString & theResamplingMethod = "NEAREST",
RasterPyramidsFormat theFormat = PyramidsGTiff,
const QStringList & theConfigOptions = QStringList() )
{
Q_UNUSED( thePyramidList ); Q_UNUSED( theResamplingMethod ); Q_UNUSED( theFormat );
Q_UNUSED( thePyramidList ); Q_UNUSED( theResamplingMethod );
Q_UNUSED( theFormat ); Q_UNUSED( theConfigOptions );
return "FAILED_NOT_SUPPORTED";
};

Expand Down Expand Up @@ -443,18 +445,23 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
/** Remove dataset*/
virtual bool remove() { return false; }

static QStringList pyramidResamplingMethods( QString providerKey )
{
return providerKey == "gdal" ?
QStringList() << tr( "Average" ) << tr( "Nearest Neighbour" ) << tr( "Gauss" ) <<
tr( "Cubic" ) << tr( "Mode" ) << tr( "None" ) : QStringList();
}
/** Returns a list of pyramid resampling method names for given provider */
static QStringList pyramidResamplingMethods( QString providerKey = "gdal" );
/** Returns the pyramid resampling argument that corresponds to a given method */
static QString pyramidResamplingArg( QString method, QString providerKey = "gdal" );

/** Validates creation options for a specific dataset and destination format - used by GDAL provider only.
* See also validateCreationOptionsFormat() in gdal provider for validating options based on format only. */
/** Validates creation options for a specific dataset and destination format.
* @note used by GDAL provider only
* @note see also validateCreationOptionsFormat() in gdal provider for validating options based on format only */
virtual QString validateCreationOptions( const QStringList& createOptions, QString format )
{ Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }

/** Validates pyramid creation options for a specific dataset and destination format
* @note used by GDAL provider only */
virtual QString validatePyramidsConfigOptions( RasterPyramidsFormat pyramidsFormat,
const QStringList & theConfigOptions, const QString & fileFormat )
{ Q_UNUSED( pyramidsFormat ); Q_UNUSED( theConfigOptions ); Q_UNUSED( fileFormat ); return QString(); }

signals:
/** Emit a signal to notify of the progress event.
* Emited theProgress is in percents (0.0-100.0) */
Expand Down Expand Up @@ -496,5 +503,9 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast

QgsRectangle mExtent;

static void initPyramidResamplingDefs();
static QStringList mPyramidResamplingListGdal;
static QgsStringMap mPyramidResamplingMapGdal;

};
#endif
5 changes: 3 additions & 2 deletions src/core/raster/qgsrasterfilewriter.cpp
Expand Up @@ -717,9 +717,10 @@ void QgsRasterFileWriter::buildPyramids( const QString& filename )
myPyramidList[myCounterInt].build = true;
}

QgsDebugMsg( QString( "building pyramids : %1 pyramids, %2 resampling, %3 format" ).arg( myPyramidList.count() ).arg( mPyramidsResampling ).arg( mPyramidsFormat ) );
QgsDebugMsg( QString( "building pyramids : %1 pyramids, %2 resampling, %3 format, %4 options" ).arg( myPyramidList.count() ).arg( mPyramidsResampling ).arg( mPyramidsFormat ).arg( mPyramidsConfigOptions.count() ) );
// QApplication::setOverrideCursor( Qt::WaitCursor );
QString res = destProvider->buildPyramids( myPyramidList, mPyramidsResampling, mPyramidsFormat );
QString res = destProvider->buildPyramids( myPyramidList, mPyramidsResampling,
mPyramidsFormat, mPyramidsConfigOptions );
// QApplication::restoreOverrideCursor();

// TODO put this in provider or elsewhere
Expand Down
5 changes: 4 additions & 1 deletion src/core/raster/qgsrasterfilewriter.h
Expand Up @@ -88,10 +88,12 @@ class CORE_EXPORT QgsRasterFileWriter
void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
int maxTileHeight() const { return mMaxTileHeight; }

// for now not putting createOptions in all methods, use createOptions()
void setCreateOptions( const QStringList& list ) { mCreateOptions = list; }
QStringList createOptions() const { return mCreateOptions; }

void setPyramidsConfigOptions( const QStringList& list ) { mPyramidsConfigOptions = list; }
QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }

private:
QgsRasterFileWriter(); //forbidden
//WriterError writeDataRaster( QgsRasterIterator* iter, int nCols, int nRows, const QgsRectangle& outputExtent,
Expand Down Expand Up @@ -157,6 +159,7 @@ class CORE_EXPORT QgsRasterFileWriter
QString mPyramidsResampling;
QgsRasterDataProvider::RasterBuildPyramids mBuildPyramidsFlag;
QgsRasterDataProvider::RasterPyramidsFormat mPyramidsFormat;
QStringList mPyramidsConfigOptions;

QDomDocument mVRTDocument;
QList<QDomElement> mVRTBands;
Expand Down
1 change: 0 additions & 1 deletion src/core/symbology-ng/qgssymbolv2.h
Expand Up @@ -36,7 +36,6 @@ class QgsSymbolLayerV2;
class QgsRenderContext;
class QgsVectorLayer;

typedef QMap<QString, QString> QgsStringMap;
typedef QList<QgsSymbolLayerV2*> QgsSymbolLayerV2List;

class CORE_EXPORT QgsSymbolV2
Expand Down

0 comments on commit 2fb78db

Please sign in to comment.