Skip to content

Commit b356365

Browse files
author
ersts
committed
-Patch for building pyramids
-Closes ticket #1264 git-svn-id: http://svn.osgeo.org/qgis/trunk@9306 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 2106fc5 commit b356365

File tree

5 files changed

+70
-28
lines changed

5 files changed

+70
-28
lines changed

python/core/qgsrasterpyramid.sip

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class QgsRasterPyramid
1313
/** \brief YDimension for this pyramid layer */
1414
int yDim;
1515
/** \brief Whether the pyramid layer has been built yet */
16-
bool existsFlag;
16+
bool exists;
17+
/** \brief Whether the pyramid should be built */
18+
bool build;
1719

20+
QgsRasterPyramid()
1821
};

src/app/qgsrasterlayerproperties.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QWidget *p
276276
myRasterPyramidIterator != myPyramidList.end();
277277
++myRasterPyramidIterator )
278278
{
279-
if (( *myRasterPyramidIterator ).existsFlag == true )
279+
if (( *myRasterPyramidIterator ).exists == true )
280280
{
281281
lbxPyramidResolutions->addItem( new QListWidgetItem( myPyramidPixmap,
282282
QString::number(( *myRasterPyramidIterator ).xDim ) + QString( " x " ) +
@@ -1546,10 +1546,14 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
15461546
for ( int myCounterInt = 0; myCounterInt < lbxPyramidResolutions->count(); myCounterInt++ )
15471547
{
15481548
QListWidgetItem *myItem = lbxPyramidResolutions->item( myCounterInt );
1549-
if ( myItem->isSelected() )
1549+
if ( myItem->isSelected() || myPyramidList[myCounterInt].exists )
15501550
{
15511551
//mark to be pyramided
1552-
myPyramidList[myCounterInt].existsFlag = true;
1552+
myPyramidList[myCounterInt].build = true;
1553+
}
1554+
else
1555+
{
1556+
myPyramidList[myCounterInt].build = false;
15531557
}
15541558
}
15551559
//
@@ -1583,13 +1587,22 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
15831587
QMessageBox::warning( this, tr( "Building pyramids failed." ),
15841588
tr( "Building pyramid overviews is not supported on this type of raster." ) );
15851589
}
1590+
else if ( res == "ERROR_VIRTUAL" )
1591+
{
1592+
QMessageBox::warning( this, tr( "Building pyramids failed." ),
1593+
tr( "Building pyramid overviews is not supported on this type of raster." ) );
1594+
//TODO: should really read -- Building pyramid overviews is not supported for 'warped virtual dataset'. -- But in feature freeze, and translation requests have already gone out PJE20080912
1595+
}
1596+
15861597
}
15871598

15881599

15891600
//
15901601
// repopulate the pyramids list
15911602
//
15921603
lbxPyramidResolutions->clear();
1604+
// Need to rebuild list as some or all pyramids may have failed to build
1605+
myPyramidList = mRasterLayer->buildRasterPyramidList();
15931606
QIcon myPyramidPixmap( QgisApp::getThemeIcon( "/mIconPyramid.png" ) );
15941607
QIcon myNoPyramidPixmap( QgisApp::getThemeIcon( "/mIconNoPyramid.png" ) );
15951608

@@ -1598,7 +1611,7 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
15981611
myRasterPyramidIterator != myPyramidList.end();
15991612
++myRasterPyramidIterator )
16001613
{
1601-
if (( *myRasterPyramidIterator ).existsFlag == true )
1614+
if (( *myRasterPyramidIterator ).exists == true )
16021615
{
16031616
lbxPyramidResolutions->addItem( new QListWidgetItem( myPyramidPixmap,
16041617
QString::number(( *myRasterPyramidIterator ).xDim ) + QString( " x " ) +

src/core/raster/qgsrasterlayer.cpp

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ bool QgsRasterLayer::readFile( QString const & fileName )
542542
{
543543
rasterLayerType = MULTIBAND;
544544
}
545+
//TODO hasBand is really obsolete and only used in the Palette instance, change to new function hasPalette(int)
545546
else if ( hasBand( "Palette" ) ) //dont tr() this its a gdal word!
546547
{
547548
rasterLayerType = PALETTE;
@@ -3433,6 +3434,9 @@ QString QgsRasterLayer::getMetadata()
34333434
QString QgsRasterLayer::buildPyramids( RasterPyramidList const & theRasterPyramidList,
34343435
QString const & theResamplingMethod, bool theTryInternalFlag )
34353436
{
3437+
//TODO: Consider making theRasterPyramidList modifyable by this method to indicate if the pyramid exists after build attempt
3438+
//without requiring the user to rebuild the pyramid list to get the updated infomation
3439+
34363440
//
34373441
// Note: Make sure the raster is not opened in write mode
34383442
// in order to force overviews to be written to a separate file.
@@ -3456,20 +3460,22 @@ QString QgsRasterLayer::buildPyramids( RasterPyramidList const & theRasterPyrami
34563460
return "ERROR_VIRTUAL";
34573461
}
34583462

3459-
34603463
if ( theTryInternalFlag )
34613464
{
34623465
//close the gdal dataset and reopen it in read / write mode
34633466
GDALClose( mGdalDataset );
3464-
mGdalDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_Update );
3467+
mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_Update );
34653468

34663469
// if the dataset couldn't be opened in read / write mode, tell the user
3467-
if ( !mGdalDataset )
3470+
if ( !mGdalBaseDataset )
34683471
{
3469-
mGdalDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
3472+
mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
3473+
//Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
3474+
mGdalDataset = mGdalBaseDataset;
34703475
return "ERROR_WRITE_FORMAT";
34713476
}
34723477
}
3478+
34733479
//
34743480
// Iterate through the Raster Layer Pyramid Vector, building any pyramid
34753481
// marked as exists in eaxh RasterPyramid struct.
@@ -3486,9 +3492,9 @@ QString QgsRasterLayer::buildPyramids( RasterPyramidList const & theRasterPyrami
34863492
QgsLogger::debug( "Build pyramids:: Level", ( *myRasterPyramidIterator ).level, 1, __FILE__, __FUNCTION__, __LINE__ );
34873493
QgsLogger::debug( "x", ( *myRasterPyramidIterator ).xDim, 1, __FILE__, __FUNCTION__, __LINE__ );
34883494
QgsLogger::debug( "y", ( *myRasterPyramidIterator ).yDim, 1, __FILE__, __FUNCTION__, __LINE__ );
3489-
QgsLogger::debug( "exists :", ( *myRasterPyramidIterator ).existsFlag, 1, __FILE__, __FUNCTION__, __LINE__ );
3495+
QgsLogger::debug( "exists :", ( *myRasterPyramidIterator ).exists, 1, __FILE__, __FUNCTION__, __LINE__ );
34903496
#endif
3491-
if (( *myRasterPyramidIterator ).existsFlag )
3497+
if (( *myRasterPyramidIterator ).build )
34923498
{
34933499
QgsDebugMsg( "Building....." );
34943500
emit drawingProgress( myCount, myTotal );
@@ -3513,46 +3519,58 @@ QString QgsRasterLayer::buildPyramids( RasterPyramidList const & theRasterPyrami
35133519
//see ticket #284
35143520
if ( theResamplingMethod == tr( "Average Magphase" ) )
35153521
{
3516-
myError = GDALBuildOverviews( mGdalDataset, "MODE", 1, myOverviewLevelsArray, 0, NULL,
3522+
myError = GDALBuildOverviews( mGdalBaseDataset, "MODE", 1, myOverviewLevelsArray, 0, NULL,
35173523
progressCallback, this ); //this is the arg for the gdal progress callback
35183524
}
35193525
else if ( theResamplingMethod == tr( "Average" ) )
35203526

35213527
{
3522-
myError = GDALBuildOverviews( mGdalDataset, "AVERAGE", 1, myOverviewLevelsArray, 0, NULL,
3528+
myError = GDALBuildOverviews( mGdalBaseDataset, "AVERAGE", 1, myOverviewLevelsArray, 0, NULL,
35233529
progressCallback, this ); //this is the arg for the gdal progress callback
35243530
}
35253531
else // fall back to nearest neighbor
35263532
{
3527-
myError = GDALBuildOverviews( mGdalDataset, "NEAREST", 1, myOverviewLevelsArray, 0, NULL,
3533+
myError = GDALBuildOverviews( mGdalBaseDataset, "NEAREST", 1, myOverviewLevelsArray, 0, NULL,
35283534
progressCallback, this ); //this is the arg for the gdal progress callback
35293535
}
3536+
35303537
if ( myError == CE_Failure || CPLGetLastErrorNo() == CPLE_NotSupported )
35313538
{
35323539
//something bad happenend
35333540
//QString myString = QString (CPLGetLastError());
3534-
GDALClose( mGdalDataset );
3535-
mGdalDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
3541+
GDALClose( mGdalBaseDataset );
3542+
mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
3543+
//Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
3544+
mGdalDataset = mGdalBaseDataset;
3545+
35363546
emit drawingProgress( 0, 0 );
35373547
return "FAILED_NOT_SUPPORTED";
35383548
}
3549+
else
3550+
{
3551+
//make sure the raster knows it has pyramids
3552+
hasPyramidsFlag = true;
3553+
}
35393554
myCount++;
3540-
//make sure the raster knows it has pyramids
3541-
hasPyramidsFlag = true;
3555+
35423556
}
35433557
catch ( CPLErr )
35443558
{
35453559
QgsLogger::warning( "Pyramid overview building failed!" );
35463560
}
35473561
}
35483562
}
3563+
35493564
QgsDebugMsg( "Pyramid overviews built" );
35503565
if ( theTryInternalFlag )
35513566
{
35523567
//close the gdal dataset and reopen it in read only mode
3553-
GDALClose( mGdalDataset );
3554-
mGdalDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
3568+
GDALClose( mGdalBaseDataset );
3569+
mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
3570+
//Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
3571+
mGdalDataset = mGdalBaseDataset;
35553572
}
3573+
35563574
emit drawingProgress( 0, 0 );
35573575
return NULL; // returning null on success
35583576
}
@@ -3576,16 +3594,13 @@ QgsRasterLayer::RasterPyramidList QgsRasterLayer::buildRasterPyramidList()
35763594
myRasterPyramid.level = myDivisor;
35773595
myRasterPyramid.xDim = ( int )( 0.5 + ( myWidth / ( double )myDivisor ) );
35783596
myRasterPyramid.yDim = ( int )( 0.5 + ( myHeight / ( double )myDivisor ) );
3579-
myRasterPyramid.existsFlag = false;
3597+
myRasterPyramid.exists = false;
35803598
#ifdef QGISDEBUG
35813599
QgsLogger::debug( "Pyramid", myRasterPyramid.level, 1, __FILE__, __FUNCTION__, __LINE__ );
35823600
QgsLogger::debug( "xDim", myRasterPyramid.xDim, 1, __FILE__, __FUNCTION__, __LINE__ );
35833601
QgsLogger::debug( "yDim", myRasterPyramid.yDim, 1, __FILE__, __FUNCTION__, __LINE__ );
35843602
#endif
35853603

3586-
3587-
3588-
35893604
//
35903605
// Now we check if it actually exists in the raster layer
35913606
// and also adjust the dimensions if the dimensions calculated
@@ -3620,7 +3635,7 @@ QgsRasterLayer::RasterPyramidList QgsRasterLayer::buildRasterPyramidList()
36203635
//right we have a match so adjust the a / y before they get added to the list
36213636
myRasterPyramid.xDim = myOverviewXDim;
36223637
myRasterPyramid.yDim = myOverviewYDim;
3623-
myRasterPyramid.existsFlag = true;
3638+
myRasterPyramid.exists = true;
36243639
QgsDebugMsg( ".....YES!" );
36253640
}
36263641
else

src/core/raster/qgsrasterpyramid.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,18 @@ class CORE_EXPORT QgsRasterPyramid
3030
/** \brief YDimension for this pyramid layer */
3131
int yDim;
3232
/** \brief Whether the pyramid layer has been built yet */
33-
bool existsFlag;
33+
bool exists;
34+
/** \brief Whether the pyramid should be built */
35+
bool build;
36+
37+
QgsRasterPyramid()
38+
{
39+
level = 0;
40+
xDim = 0;
41+
yDim = 0;
42+
exists = false;
43+
build = false;
44+
}
3445

3546
};
3647
#endif

tests/src/core/testqgsrasterlayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void TestQgsRasterLayer::buildExternalOverviews()
178178
for ( int myCounterInt = 0; myCounterInt < myPyramidList.count(); myCounterInt++ )
179179
{
180180
//mark to be pyramided
181-
myPyramidList[myCounterInt].existsFlag = true;
181+
myPyramidList[myCounterInt].build = true;
182182
}
183183
//now actually make the pyramids
184184
QString myResult = mypLayer->buildPyramids(
@@ -194,7 +194,7 @@ void TestQgsRasterLayer::buildExternalOverviews()
194194
for ( int myCounterInt = 0; myCounterInt < myPyramidList.count(); myCounterInt++ )
195195
{
196196
//mark to be pyramided
197-
QVERIFY( myPyramidList.at( myCounterInt ).existsFlag );
197+
QVERIFY( myPyramidList.at( myCounterInt ).exists );
198198
}
199199

200200
//

0 commit comments

Comments
 (0)