@@ -542,6 +542,7 @@ bool QgsRasterLayer::readFile( QString const & fileName )
542
542
{
543
543
rasterLayerType = MULTIBAND;
544
544
}
545
+ // TODO hasBand is really obsolete and only used in the Palette instance, change to new function hasPalette(int)
545
546
else if ( hasBand ( " Palette" ) ) // dont tr() this its a gdal word!
546
547
{
547
548
rasterLayerType = PALETTE;
@@ -3433,6 +3434,9 @@ QString QgsRasterLayer::getMetadata()
3433
3434
QString QgsRasterLayer::buildPyramids ( RasterPyramidList const & theRasterPyramidList,
3434
3435
QString const & theResamplingMethod, bool theTryInternalFlag )
3435
3436
{
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
+
3436
3440
//
3437
3441
// Note: Make sure the raster is not opened in write mode
3438
3442
// in order to force overviews to be written to a separate file.
@@ -3456,20 +3460,22 @@ QString QgsRasterLayer::buildPyramids( RasterPyramidList const & theRasterPyrami
3456
3460
return " ERROR_VIRTUAL" ;
3457
3461
}
3458
3462
3459
-
3460
3463
if ( theTryInternalFlag )
3461
3464
{
3462
3465
// close the gdal dataset and reopen it in read / write mode
3463
3466
GDALClose ( mGdalDataset );
3464
- mGdalDataset = GDALOpen ( QFile::encodeName ( mDataSource ).constData (), GA_Update );
3467
+ mGdalBaseDataset = GDALOpen ( QFile::encodeName ( mDataSource ).constData (), GA_Update );
3465
3468
3466
3469
// if the dataset couldn't be opened in read / write mode, tell the user
3467
- if ( !mGdalDataset )
3470
+ if ( !mGdalBaseDataset )
3468
3471
{
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 ;
3470
3475
return " ERROR_WRITE_FORMAT" ;
3471
3476
}
3472
3477
}
3478
+
3473
3479
//
3474
3480
// Iterate through the Raster Layer Pyramid Vector, building any pyramid
3475
3481
// marked as exists in eaxh RasterPyramid struct.
@@ -3486,9 +3492,9 @@ QString QgsRasterLayer::buildPyramids( RasterPyramidList const & theRasterPyrami
3486
3492
QgsLogger::debug ( " Build pyramids:: Level" , ( *myRasterPyramidIterator ).level , 1 , __FILE__, __FUNCTION__, __LINE__ );
3487
3493
QgsLogger::debug ( " x" , ( *myRasterPyramidIterator ).xDim , 1 , __FILE__, __FUNCTION__, __LINE__ );
3488
3494
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__ );
3490
3496
#endif
3491
- if (( *myRasterPyramidIterator ).existsFlag )
3497
+ if (( *myRasterPyramidIterator ).build )
3492
3498
{
3493
3499
QgsDebugMsg ( " Building....." );
3494
3500
emit drawingProgress ( myCount, myTotal );
@@ -3513,46 +3519,58 @@ QString QgsRasterLayer::buildPyramids( RasterPyramidList const & theRasterPyrami
3513
3519
// see ticket #284
3514
3520
if ( theResamplingMethod == tr ( " Average Magphase" ) )
3515
3521
{
3516
- myError = GDALBuildOverviews ( mGdalDataset , " MODE" , 1 , myOverviewLevelsArray, 0 , NULL ,
3522
+ myError = GDALBuildOverviews ( mGdalBaseDataset , " MODE" , 1 , myOverviewLevelsArray, 0 , NULL ,
3517
3523
progressCallback, this ); // this is the arg for the gdal progress callback
3518
3524
}
3519
3525
else if ( theResamplingMethod == tr ( " Average" ) )
3520
3526
3521
3527
{
3522
- myError = GDALBuildOverviews ( mGdalDataset , " AVERAGE" , 1 , myOverviewLevelsArray, 0 , NULL ,
3528
+ myError = GDALBuildOverviews ( mGdalBaseDataset , " AVERAGE" , 1 , myOverviewLevelsArray, 0 , NULL ,
3523
3529
progressCallback, this ); // this is the arg for the gdal progress callback
3524
3530
}
3525
3531
else // fall back to nearest neighbor
3526
3532
{
3527
- myError = GDALBuildOverviews ( mGdalDataset , " NEAREST" , 1 , myOverviewLevelsArray, 0 , NULL ,
3533
+ myError = GDALBuildOverviews ( mGdalBaseDataset , " NEAREST" , 1 , myOverviewLevelsArray, 0 , NULL ,
3528
3534
progressCallback, this ); // this is the arg for the gdal progress callback
3529
3535
}
3536
+
3530
3537
if ( myError == CE_Failure || CPLGetLastErrorNo () == CPLE_NotSupported )
3531
3538
{
3532
3539
// something bad happenend
3533
3540
// 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
+
3536
3546
emit drawingProgress ( 0 , 0 );
3537
3547
return " FAILED_NOT_SUPPORTED" ;
3538
3548
}
3549
+ else
3550
+ {
3551
+ // make sure the raster knows it has pyramids
3552
+ hasPyramidsFlag = true ;
3553
+ }
3539
3554
myCount++;
3540
- // make sure the raster knows it has pyramids
3541
- hasPyramidsFlag = true ;
3555
+
3542
3556
}
3543
3557
catch ( CPLErr )
3544
3558
{
3545
3559
QgsLogger::warning ( " Pyramid overview building failed!" );
3546
3560
}
3547
3561
}
3548
3562
}
3563
+
3549
3564
QgsDebugMsg ( " Pyramid overviews built" );
3550
3565
if ( theTryInternalFlag )
3551
3566
{
3552
3567
// 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 ;
3555
3572
}
3573
+
3556
3574
emit drawingProgress ( 0 , 0 );
3557
3575
return NULL ; // returning null on success
3558
3576
}
@@ -3576,16 +3594,13 @@ QgsRasterLayer::RasterPyramidList QgsRasterLayer::buildRasterPyramidList()
3576
3594
myRasterPyramid.level = myDivisor;
3577
3595
myRasterPyramid.xDim = ( int )( 0.5 + ( myWidth / ( double )myDivisor ) );
3578
3596
myRasterPyramid.yDim = ( int )( 0.5 + ( myHeight / ( double )myDivisor ) );
3579
- myRasterPyramid.existsFlag = false ;
3597
+ myRasterPyramid.exists = false ;
3580
3598
#ifdef QGISDEBUG
3581
3599
QgsLogger::debug ( " Pyramid" , myRasterPyramid.level , 1 , __FILE__, __FUNCTION__, __LINE__ );
3582
3600
QgsLogger::debug ( " xDim" , myRasterPyramid.xDim , 1 , __FILE__, __FUNCTION__, __LINE__ );
3583
3601
QgsLogger::debug ( " yDim" , myRasterPyramid.yDim , 1 , __FILE__, __FUNCTION__, __LINE__ );
3584
3602
#endif
3585
3603
3586
-
3587
-
3588
-
3589
3604
//
3590
3605
// Now we check if it actually exists in the raster layer
3591
3606
// and also adjust the dimensions if the dimensions calculated
@@ -3620,7 +3635,7 @@ QgsRasterLayer::RasterPyramidList QgsRasterLayer::buildRasterPyramidList()
3620
3635
// right we have a match so adjust the a / y before they get added to the list
3621
3636
myRasterPyramid.xDim = myOverviewXDim;
3622
3637
myRasterPyramid.yDim = myOverviewYDim;
3623
- myRasterPyramid.existsFlag = true ;
3638
+ myRasterPyramid.exists = true ;
3624
3639
QgsDebugMsg ( " .....YES!" );
3625
3640
}
3626
3641
else
0 commit comments