Skip to content

Commit eda71f5

Browse files
committedAug 26, 2012
implement pyramids in raster save dialog ; improve pyramids creation ; remove pyramid-related stuff from qgsrasterlayer
1 parent 4cfc365 commit eda71f5

19 files changed

+805
-270
lines changed
 

‎python/core/qgsrasterlayer.sip

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class QgsRasterLayer : QgsMapLayer
77
{
88
%TypeHeaderCode
9-
#include <qgsrasterpyramid.h>
9+
// #include <qgsrasterpyramid.h>
1010
#include <qgsrasterlayer.h>
1111
#include <qgscontrastenhancement.h>
1212
#include <qgsrastertransparency.h>
@@ -91,7 +91,7 @@ public:
9191
* to be added to the list. Each time a RasterPyramid is created
9292
* we will check to see if a pyramid matching these dimensions already exists
9393
* in the raster layer, and if so mark the exists flag as true */
94-
typedef QList<QgsRasterPyramid> RasterPyramidList;
94+
// typedef QList<QgsRasterPyramid> RasterPyramidList;
9595

9696
/** \brief A list containing one RasterBandStats struct per raster band in this raster layer.
9797
* Note that while every RasterBandStats element will have the name and number of its associated
@@ -151,7 +151,7 @@ public:
151151
//QString greenBandName() const; //removed with raster redesign
152152

153153
/** \brief Accessor for mHasPyramids (READ ONLY) */
154-
bool hasPyramids();
154+
// bool hasPyramids();
155155

156156
/** \brief Accessor for mUserDefinedGrayMinimumMaximum */
157157
bool hasUserDefinedGrayMinimumMaximum() const;
@@ -248,7 +248,7 @@ public:
248248
* ACTUALLY exists you need to look at the existsFlag member in each struct stored in the
249249
* list.
250250
*/
251-
RasterPyramidList buildPyramidList();
251+
// RasterPyramidList buildPyramidList();
252252

253253
/** \brief Accessor for color shader algorithm */
254254
QString colorShadingAlgorithmAsString() const;
@@ -470,9 +470,9 @@ public:
470470

471471
public slots:
472472
/** \brief Create GDAL pyramid overviews */
473-
QString buildPyramids( const RasterPyramidList &,
474-
const QString & theResamplingMethod = "NEAREST",
475-
bool theTryInternalFlag = false );
473+
// QString buildPyramids( const RasterPyramidList &,
474+
// const QString & theResamplingMethod = "NEAREST",
475+
// bool theTryInternalFlag = false );
476476

477477
void showStatusMessage( const QString & theMessage );
478478

‎src/app/qgisapp.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3997,6 +3997,11 @@ void QgisApp::saveAsRasterFile()
39973997
}
39983998
fileWriter.setCreateOptions( d.createOptions() );
39993999

4000+
fileWriter.setBuildPyramidsFlag( d.buildPyramidsFlag() );
4001+
fileWriter.setPyramidsList( d.overviewList() );
4002+
fileWriter.setPyramidsResampling( d.pyramidsResampling() );
4003+
fileWriter.setPyramidsFormat( d.pyramidsFormat() );
4004+
40004005
fileWriter.writeRaster( pipe, d.nColumns(), d.nRows(), d.outputRectangle(), d.outputCrs(), &pd );
40014006
delete pipe;
40024007
}

‎src/app/qgsrasterlayerproperties.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,20 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
117117
{
118118
return;
119119
}
120+
120121
QgsRasterDataProvider* provider = mRasterLayer->dataProvider();
121122

122123
// Only do pyramids if dealing directly with GDAL.
123124
if ( provider->capabilities() & QgsRasterDataProvider::BuildPyramids )
124125
{
125-
QgsRasterLayer::RasterPyramidList myPyramidList = mRasterLayer->buildPyramidList();
126-
QgsRasterLayer::RasterPyramidList::iterator myRasterPyramidIterator;
126+
// initialize resampling methods
127+
cboResamplingMethod->clear();
128+
foreach ( QString method, QgsRasterDataProvider::pyramidResamplingMethods( mRasterLayer->providerType() ) )
129+
cboResamplingMethod->addItem( method );
130+
131+
// build pyramid list
132+
QList< QgsRasterPyramid > myPyramidList = provider->buildPyramidList();
133+
QList< QgsRasterPyramid >::iterator myRasterPyramidIterator;
127134

128135
for ( myRasterPyramidIterator = myPyramidList.begin();
129136
myRasterPyramidIterator != myPyramidList.end();
@@ -762,13 +769,14 @@ void QgsRasterLayerProperties::apply()
762769

763770
void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
764771
{
772+
QgsRasterDataProvider* provider = mRasterLayer->dataProvider();
765773

766-
connect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mPyramidProgress, SLOT( setValue( int ) ) );
774+
connect( provider, SIGNAL( progressUpdate( int ) ), mPyramidProgress, SLOT( setValue( int ) ) );
767775
//
768776
// Go through the list marking any files that are selected in the listview
769777
// as true so that we can generate pyramids for them.
770778
//
771-
QgsRasterLayer::RasterPyramidList myPyramidList = mRasterLayer->buildPyramidList();
779+
QList< QgsRasterPyramid> myPyramidList = provider->buildPyramidList();
772780
for ( int myCounterInt = 0; myCounterInt < lbxPyramidResolutions->count(); myCounterInt++ )
773781
{
774782
QListWidgetItem *myItem = lbxPyramidResolutions->item( myCounterInt );
@@ -781,15 +789,14 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
781789

782790
// let the user know we're going to possibly be taking a while
783791
QApplication::setOverrideCursor( Qt::WaitCursor );
784-
bool myBuildInternalFlag = cbxInternalPyramids->isChecked();
785-
QString res = mRasterLayer->buildPyramids(
792+
QString res = provider->buildPyramids(
786793
myPyramidList,
787794
cboResamplingMethod->currentText(),
788-
myBuildInternalFlag );
795+
( QgsRasterDataProvider::RasterPyramidsFormat ) cbxPyramidsFormat->currentIndex() );
789796
QApplication::restoreOverrideCursor();
790797
mPyramidProgress->setValue( 0 );
791798
buttonBuildPyramids->setEnabled( false );
792-
disconnect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mPyramidProgress, SLOT( setValue( int ) ) );
799+
disconnect( provider, SIGNAL( progressUpdate( int ) ), mPyramidProgress, SLOT( setValue( int ) ) );
793800
if ( !res.isNull() )
794801
{
795802
if ( res == "ERROR_WRITE_ACCESS" )
@@ -821,17 +828,16 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
821828

822829
}
823830

824-
825831
//
826832
// repopulate the pyramids list
827833
//
828834
lbxPyramidResolutions->clear();
829835
// Need to rebuild list as some or all pyramids may have failed to build
830-
myPyramidList = mRasterLayer->buildPyramidList();
836+
myPyramidList = provider->buildPyramidList();
831837
QIcon myPyramidPixmap( QgsApplication::getThemeIcon( "/mIconPyramid.png" ) );
832838
QIcon myNoPyramidPixmap( QgsApplication::getThemeIcon( "/mIconNoPyramid.png" ) );
833839

834-
QgsRasterLayer::RasterPyramidList::iterator myRasterPyramidIterator;
840+
QList< QgsRasterPyramid >::iterator myRasterPyramidIterator;
835841
for ( myRasterPyramidIterator = myPyramidList.begin();
836842
myRasterPyramidIterator != myPyramidList.end();
837843
++myRasterPyramidIterator )

‎src/core/qgsrasterdataprovider.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,26 @@ QByteArray QgsRasterDataProvider::noValueBytes( int theBandNo )
272272
return ba;
273273
}
274274

275+
bool QgsRasterDataProvider::hasPyramids()
276+
{
277+
QList<QgsRasterPyramid> myPyramidList = buildPyramidList();
278+
279+
if ( myPyramidList.isEmpty() )
280+
return false;
281+
282+
QList<QgsRasterPyramid>::iterator myRasterPyramidIterator;
283+
for ( myRasterPyramidIterator = myPyramidList.begin();
284+
myRasterPyramidIterator != myPyramidList.end();
285+
++myRasterPyramidIterator )
286+
{
287+
if ( myRasterPyramidIterator->exists )
288+
{
289+
return true;
290+
}
291+
}
292+
return false;
293+
}
294+
275295
#if 0
276296
QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo )
277297
{

‎src/core/qgsrasterdataprovider.h

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
102102
ProgressStatistics = 2
103103
};
104104

105+
enum RasterBuildPyramids
106+
{
107+
PyramidsFlagNo = 0,
108+
PyramidsFlagYes = 1,
109+
CopyExisting = 2
110+
};
111+
112+
enum RasterPyramidsFormat
113+
{
114+
PyramidsGTiff = 0,
115+
PyramidsInternal = 1,
116+
PyramidsErdas = 2
117+
};
118+
105119
QgsRasterDataProvider();
106120

107121
QgsRasterDataProvider( QString const & uri );
@@ -345,15 +359,24 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
345359
/** \brief Create pyramid overviews */
346360
virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
347361
const QString & theResamplingMethod = "NEAREST",
348-
bool theTryInternalFlag = false )
349-
{ Q_UNUSED( thePyramidList ); Q_UNUSED( theResamplingMethod ); Q_UNUSED( theTryInternalFlag ); return "FAILED_NOT_SUPPORTED"; };
362+
RasterPyramidsFormat theFormat = PyramidsGTiff )
363+
{
364+
Q_UNUSED( thePyramidList ); Q_UNUSED( theResamplingMethod ); Q_UNUSED( theFormat );
365+
return "FAILED_NOT_SUPPORTED";
366+
};
350367

351-
/** \brief Accessor for ths raster layers pyramid list. A pyramid list defines the
368+
/** \brief Accessor for ths raster layers pyramid list.
369+
* @param overviewList used to construct the pyramid list (optional), when empty the list is defined by the provider.
370+
* A pyramid list defines the
352371
* POTENTIAL pyramids that can be in a raster. To know which of the pyramid layers
353372
* ACTUALLY exists you need to look at the existsFlag member in each struct stored in the
354373
* list.
355374
*/
356-
virtual QList<QgsRasterPyramid> buildPyramidList() { return QList<QgsRasterPyramid>(); };
375+
virtual QList<QgsRasterPyramid> buildPyramidList( QList<int> overviewList = QList<int>() )
376+
{ Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); };
377+
378+
/** \brief Returns true if raster has at least one populated histogram. */
379+
bool hasPyramids();
357380

358381
/** If the provider supports it, return band stats for the
359382
given band. Default behaviour is to blockwise read the data
@@ -537,13 +560,21 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
537560
/** Remove dataset*/
538561
virtual bool remove() { return false; }
539562

563+
static QStringList pyramidResamplingMethods( QString providerKey )
564+
{
565+
return providerKey == "gdal" ?
566+
QStringList() << tr( "Average" ) << tr( "Nearest Neighbour" ) << tr( "Gauss" ) <<
567+
tr( "Cubic" ) << tr( "Mode" ) << tr( "None" ) : QStringList();
568+
}
569+
540570
signals:
541571
/** Emit a signal to notify of the progress event.
542572
* Emited theProgress is in percents (0.0-100.0) */
543573
void progress( int theType, double theProgress, QString theMessage );
574+
void progressUpdate( int theProgress );
544575

545576
protected:
546-
/**Dots per intch. Extended WMS (e.g. QGIS mapserver) support DPI dependent output and therefore
577+
/**Dots per inch. Extended WMS (e.g. QGIS mapserver) support DPI dependent output and therefore
547578
are suited for printing. A value of -1 means it has not been set
548579
@note: this member has been added in version 1.2*/
549580
int mDpi;

0 commit comments

Comments
 (0)
Please sign in to comment.