Skip to content

Commit 2fb78db

Browse files
committedJan 18, 2013
update raster format and pyramid save widgets for python, add pyramid config options support to raster writer, other fixes
1 parent 0dbb781 commit 2fb78db

21 files changed

+455
-187
lines changed
 

‎python/core/raster/qgsrasterdataprovider.sip

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
169169
virtual QStringList subLayers() const;
170170

171171
/** \brief Create pyramid overviews */
172-
virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
173-
const QString & theResamplingMethod = "NEAREST",
174-
RasterPyramidsFormat theFormat = PyramidsGTiff );
175-
172+
virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
173+
const QString & theResamplingMethod = "NEAREST",
174+
RasterPyramidsFormat theFormat = PyramidsGTiff,
175+
const QStringList & theConfigOptions = QStringList() );
176+
176177
/** \brief Accessor for ths raster layers pyramid list.
177178
* @param overviewList used to construct the pyramid list (optional), when empty the list is defined by the provider.
178179
* A pyramid list defines the
@@ -269,13 +270,22 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
269270
/** Remove dataset*/
270271
virtual bool remove();
271272

272-
static QStringList pyramidResamplingMethods( QString providerKey );
273+
/** Returns a list of pyramid resampling method names for given provider */
274+
static QStringList pyramidResamplingMethods( QString providerKey = "gdal" );
275+
/** Returns the pyramid resampling argument that corresponds to a given method */
276+
static QString pyramidResamplingArg( QString method, QString providerKey = "gdal" );
277+
278+
/** Validates creation options for a specific dataset and destination format.
279+
* @note used by GDAL provider only
280+
* @note see also validateCreationOptionsFormat() in gdal provider for validating options based on format only */
281+
virtual QString validateCreationOptions( const QStringList& createOptions, QString format );
273282

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

278-
signals:
288+
signals:
279289
/** Emit a signal to notify of the progress event.
280290
* Emited theProgress is in percents (0.0-100.0) */
281291
void progress( int theType, double theProgress, QString theMessage );

‎python/core/raster/qgsrasterfilewriter.sip

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ class QgsRasterFileWriter
5959
void setMaxTileHeight( int h );
6060
int maxTileHeight() const;
6161

62-
// for now not putting createOptions in all methods, use createOptions()
6362
void setCreateOptions( const QStringList& list );
6463
QStringList createOptions() const;
64+
65+
QStringList pyramidsConfigOptions() const;
66+
void setPyramidsConfigOptions( const QStringList& list );
6567
};
6668

‎python/gui/qgsrasterformatsaveoptionswidget.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ class QgsRasterFormatSaveOptionsWidget : QWidget
2424
void setFormat( QString format );
2525
void setProvider( QString provider );
2626
void setRasterLayer( QgsRasterLayer* rasterLayer );
27+
void setRasterFileName( const QString& file );
2728
QStringList options() const;
2829
void setType( QgsRasterFormatSaveOptionsWidget::Type type = Default );
30+
void setPyramidsFormat( QgsRasterDataProvider::RasterPyramidsFormat format );
2931

3032
public slots:
3133

‎python/gui/qgsrasterlayersaveasdialog.sip

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ class QgsRasterLayerSaveAsDialog : QDialog
4848
QgsRectangle outputRectangle() const;
4949
QList<QgsRasterNuller::NoData> noData() const;
5050

51-
QList< int > overviewList() const;
51+
QList< int > pyramidsList() const;
5252
QgsRasterDataProvider::RasterBuildPyramids buildPyramidsFlag() const;
53-
QString pyramidsResampling() const;
53+
QString pyramidsResamplingMethod() const;
5454
QgsRasterDataProvider::RasterPyramidsFormat pyramidsFormat() const;
55+
QStringList pyramidsConfigOptions() const;
5556

5657
void hideFormat();
5758
void hideOutput();

‎python/gui/qgsrasterpyramidsoptionswidget.sip

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,26 @@ class QgsRasterPyramidsOptionsWidget: QWidget
1212
QgsRasterPyramidsOptionsWidget( QWidget* parent = 0, QString provider = "gdal" );
1313
~QgsRasterPyramidsOptionsWidget();
1414

15-
QStringList createOptions() const;
15+
QStringList configOptions() const;
1616
QgsRasterFormatSaveOptionsWidget* createOptionsWidget() /Factory/;
1717
const QList<int> overviewList() const;
1818
QgsRasterDataProvider::RasterPyramidsFormat pyramidsFormat() const;
1919
QString resamplingMethod() const;
20+
void setRasterLayer( QgsRasterLayer* rasterLayer );
21+
void setRasterFileName( const QString& file );
2022

2123
public slots:
2224

2325
void apply();
2426
void checkAllLevels( bool checked );
2527

28+
private slots:
29+
30+
void on_cbxPyramidsLevelsCustom_toggled( bool toggled );
31+
void on_cbxPyramidsFormat_currentIndexChanged( int index );
32+
void setOverviewList();
33+
void updateUi();
34+
2635
signals:
2736
void overviewListChanged();
2837
};

‎src/app/qgisapp.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4204,9 +4204,10 @@ void QgisApp::saveAsRasterFile()
42044204
fileWriter.setCreateOptions( d.createOptions() );
42054205

42064206
fileWriter.setBuildPyramidsFlag( d.buildPyramidsFlag() );
4207-
fileWriter.setPyramidsList( d.overviewList() );
4208-
fileWriter.setPyramidsResampling( d.pyramidsResampling() );
4207+
fileWriter.setPyramidsList( d.pyramidsList() );
4208+
fileWriter.setPyramidsResampling( d.pyramidsResamplingMethod() );
42094209
fileWriter.setPyramidsFormat( d.pyramidsFormat() );
4210+
fileWriter.setPyramidsConfigOptions( d.pyramidsConfigOptions() );
42104211

42114212
QgsRasterFileWriter::WriterError err = fileWriter.writeRaster( pipe, d.nColumns(), d.nRows(), d.outputRectangle(), d.outputCrs(), &pd );
42124213
if ( err != QgsRasterFileWriter::NoError )

‎src/core/qgis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ const double DEFAULT_LINE_WIDTH = 0.26;
336336
/** default snapping tolerance for segments (@note added in 1.8) */
337337
const double DEFAULT_SEGMENT_EPSILON = 1e-8;
338338

339+
typedef QMap<QString, QString> QgsStringMap;
340+
339341
// FIXME: also in qgisinterface.h
340342
#ifndef QGISEXTERN
341343
#ifdef WIN32

‎src/core/raster/qgsrasterdataprovider.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,63 @@ QString QgsRasterDataProvider::lastErrorFormat()
387387
return "text/plain";
388388
}
389389

390+
// pyramids resampling
391+
392+
// TODO move this to gdal provider
393+
// but we need some way to get a static instance of the provider
394+
// or use function pointers like in QgsRasterFormatSaveOptionsWidget::helpOptions()
395+
396+
// see http://www.gdal.org/gdaladdo.html
397+
// http://www.gdal.org/classGDALDataset.html#a2aa6f88b3bbc840a5696236af11dde15
398+
// http://www.gdal.org/classGDALRasterBand.html#afaea945b13ec9c86c2d783b883c68432
399+
400+
// from http://www.gdal.org/gdaladdo.html
401+
// average_mp is unsuitable for use thus not included
402+
403+
// from qgsgdalprovider.cpp (removed)
404+
// NOTE magphase is disabled in the gui since it tends
405+
// to create corrupted images. The images can be repaired
406+
// by running one of the other resampling strategies below.
407+
// see ticket #284
408+
QStringList QgsRasterDataProvider::mPyramidResamplingListGdal = QStringList();
409+
QgsStringMap QgsRasterDataProvider::mPyramidResamplingMapGdal = QgsStringMap();
410+
411+
void QgsRasterDataProvider::initPyramidResamplingDefs()
412+
{
413+
mPyramidResamplingListGdal.clear();
414+
mPyramidResamplingListGdal << tr( "Nearest Neighbour" ) << tr( "Average" ) << tr( "Gauss" ) << tr( "Cubic" ) << tr( "Mode" ) << tr( "None" ); // << tr( "Average magphase" )
415+
mPyramidResamplingMapGdal.clear();
416+
mPyramidResamplingMapGdal[ tr( "Nearest Neighbour" )] = "NEAREST";
417+
mPyramidResamplingMapGdal[ tr( "Average" )] = "AVERAGE";
418+
mPyramidResamplingMapGdal[ tr( "Gauss" )] = "GAUSS";
419+
mPyramidResamplingMapGdal[ tr( "Cubic" )] = "CUBIC";
420+
mPyramidResamplingMapGdal[ tr( "Mode" )] = "MODE";
421+
// mPyramidResamplingMapGdal[ tr( "Average magphase" ) ] = "average_magphase";
422+
mPyramidResamplingMapGdal[ tr( "None" )] = "NONE" ;
423+
}
424+
425+
QStringList QgsRasterDataProvider::pyramidResamplingMethods( QString providerKey )
426+
{
427+
if ( mPyramidResamplingListGdal.isEmpty() )
428+
initPyramidResamplingDefs();
429+
430+
return providerKey == "gdal" ? mPyramidResamplingListGdal : QStringList();
431+
}
432+
433+
QString QgsRasterDataProvider::pyramidResamplingArg( QString method, QString providerKey )
434+
{
435+
if ( providerKey != "gdal" )
436+
return QString();
437+
438+
if ( mPyramidResamplingListGdal.isEmpty() )
439+
initPyramidResamplingDefs();
440+
441+
if ( mPyramidResamplingMapGdal.contains( method ) )
442+
return mPyramidResamplingMapGdal.value( method );
443+
else
444+
return "NEAREST";
445+
}
446+
390447
bool QgsRasterDataProvider::hasPyramids()
391448
{
392449
QList<QgsRasterPyramid> myPyramidList = buildPyramidList();

‎src/core/raster/qgsrasterdataprovider.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,13 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
290290
}
291291

292292
/** \brief Create pyramid overviews */
293-
virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
294-
const QString & theResamplingMethod = "NEAREST",
295-
RasterPyramidsFormat theFormat = PyramidsGTiff )
293+
virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
294+
const QString & theResamplingMethod = "NEAREST",
295+
RasterPyramidsFormat theFormat = PyramidsGTiff,
296+
const QStringList & theConfigOptions = QStringList() )
296297
{
297-
Q_UNUSED( thePyramidList ); Q_UNUSED( theResamplingMethod ); Q_UNUSED( theFormat );
298+
Q_UNUSED( thePyramidList ); Q_UNUSED( theResamplingMethod );
299+
Q_UNUSED( theFormat ); Q_UNUSED( theConfigOptions );
298300
return "FAILED_NOT_SUPPORTED";
299301
};
300302

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

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

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

459+
/** Validates pyramid creation options for a specific dataset and destination format
460+
* @note used by GDAL provider only */
461+
virtual QString validatePyramidsConfigOptions( RasterPyramidsFormat pyramidsFormat,
462+
const QStringList & theConfigOptions, const QString & fileFormat )
463+
{ Q_UNUSED( pyramidsFormat ); Q_UNUSED( theConfigOptions ); Q_UNUSED( fileFormat ); return QString(); }
464+
458465
signals:
459466
/** Emit a signal to notify of the progress event.
460467
* Emited theProgress is in percents (0.0-100.0) */
@@ -496,5 +503,9 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
496503

497504
QgsRectangle mExtent;
498505

506+
static void initPyramidResamplingDefs();
507+
static QStringList mPyramidResamplingListGdal;
508+
static QgsStringMap mPyramidResamplingMapGdal;
509+
499510
};
500511
#endif

‎src/core/raster/qgsrasterfilewriter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,10 @@ void QgsRasterFileWriter::buildPyramids( const QString& filename )
717717
myPyramidList[myCounterInt].build = true;
718718
}
719719

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

725726
// TODO put this in provider or elsewhere

‎src/core/raster/qgsrasterfilewriter.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ class CORE_EXPORT QgsRasterFileWriter
8888
void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
8989
int maxTileHeight() const { return mMaxTileHeight; }
9090

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

94+
void setPyramidsConfigOptions( const QStringList& list ) { mPyramidsConfigOptions = list; }
95+
QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
96+
9597
private:
9698
QgsRasterFileWriter(); //forbidden
9799
//WriterError writeDataRaster( QgsRasterIterator* iter, int nCols, int nRows, const QgsRectangle& outputExtent,
@@ -157,6 +159,7 @@ class CORE_EXPORT QgsRasterFileWriter
157159
QString mPyramidsResampling;
158160
QgsRasterDataProvider::RasterBuildPyramids mBuildPyramidsFlag;
159161
QgsRasterDataProvider::RasterPyramidsFormat mPyramidsFormat;
162+
QStringList mPyramidsConfigOptions;
160163

161164
QDomDocument mVRTDocument;
162165
QList<QDomElement> mVRTBands;

‎src/core/symbology-ng/qgssymbolv2.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class QgsSymbolLayerV2;
3636
class QgsRenderContext;
3737
class QgsVectorLayer;
3838

39-
typedef QMap<QString, QString> QgsStringMap;
4039
typedef QList<QgsSymbolLayerV2*> QgsSymbolLayerV2List;
4140

4241
class CORE_EXPORT QgsSymbolV2

0 commit comments

Comments
 (0)
Please sign in to comment.