[QGIS Commit] r9306 - in trunk/qgis: python/core src/app src/core/raster tests/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Sep 12 14:40:41 EDT 2008


Author: ersts
Date: 2008-09-12 14:40:41 -0400 (Fri, 12 Sep 2008)
New Revision: 9306

Modified:
   trunk/qgis/python/core/qgsrasterpyramid.sip
   trunk/qgis/src/app/qgsrasterlayerproperties.cpp
   trunk/qgis/src/core/raster/qgsrasterlayer.cpp
   trunk/qgis/src/core/raster/qgsrasterpyramid.h
   trunk/qgis/tests/src/core/testqgsrasterlayer.cpp
Log:
-Patch for building pyramids
-Closes ticket #1264

Modified: trunk/qgis/python/core/qgsrasterpyramid.sip
===================================================================
--- trunk/qgis/python/core/qgsrasterpyramid.sip	2008-09-12 17:02:40 UTC (rev 9305)
+++ trunk/qgis/python/core/qgsrasterpyramid.sip	2008-09-12 18:40:41 UTC (rev 9306)
@@ -13,6 +13,9 @@
   /** \brief YDimension for this pyramid layer */
   int yDim;
   /** \brief Whether the pyramid layer has been built yet */
-  bool existsFlag;
+  bool exists;
+  /** \brief Whether the pyramid should be built */
+  bool build;
 
+  QgsRasterPyramid()
 };

Modified: trunk/qgis/src/app/qgsrasterlayerproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsrasterlayerproperties.cpp	2008-09-12 17:02:40 UTC (rev 9305)
+++ trunk/qgis/src/app/qgsrasterlayerproperties.cpp	2008-09-12 18:40:41 UTC (rev 9306)
@@ -276,7 +276,7 @@
           myRasterPyramidIterator != myPyramidList.end();
           ++myRasterPyramidIterator )
     {
-      if (( *myRasterPyramidIterator ).existsFlag == true )
+      if (( *myRasterPyramidIterator ).exists == true )
       {
         lbxPyramidResolutions->addItem( new QListWidgetItem( myPyramidPixmap,
                                         QString::number(( *myRasterPyramidIterator ).xDim ) + QString( " x " ) +
@@ -1546,11 +1546,15 @@
   for ( int myCounterInt = 0; myCounterInt < lbxPyramidResolutions->count(); myCounterInt++ )
   {
     QListWidgetItem *myItem = lbxPyramidResolutions->item( myCounterInt );
-    if ( myItem->isSelected() )
+    if ( myItem->isSelected() || myPyramidList[myCounterInt].exists )
     {
       //mark to be pyramided
-      myPyramidList[myCounterInt].existsFlag = true;
+      myPyramidList[myCounterInt].build = true;
     }
+    else
+    {
+      myPyramidList[myCounterInt].build = false;
+    }
   }
   //
   // Ask raster layer to build the pyramids
@@ -1583,6 +1587,13 @@
       QMessageBox::warning( this, tr( "Building pyramids failed." ),
                             tr( "Building pyramid overviews is not supported on this type of raster." ) );
     }
+    else if ( res == "ERROR_VIRTUAL" )
+    {
+      QMessageBox::warning( this, tr( "Building pyramids failed." ),
+                            tr( "Building pyramid overviews is not supported on this type of raster." ) );
+                            //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
+    }
+    
   }
 
 
@@ -1590,6 +1601,8 @@
   // repopulate the pyramids list
   //
   lbxPyramidResolutions->clear();
+  // Need to rebuild list as some or all pyramids may have failed to build
+  myPyramidList = mRasterLayer->buildRasterPyramidList();
   QIcon myPyramidPixmap( QgisApp::getThemeIcon( "/mIconPyramid.png" ) );
   QIcon myNoPyramidPixmap( QgisApp::getThemeIcon( "/mIconNoPyramid.png" ) );
 
@@ -1598,7 +1611,7 @@
         myRasterPyramidIterator != myPyramidList.end();
         ++myRasterPyramidIterator )
   {
-    if (( *myRasterPyramidIterator ).existsFlag == true )
+    if (( *myRasterPyramidIterator ).exists == true )
     {
       lbxPyramidResolutions->addItem( new QListWidgetItem( myPyramidPixmap,
                                       QString::number(( *myRasterPyramidIterator ).xDim ) + QString( " x " ) +

Modified: trunk/qgis/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2008-09-12 17:02:40 UTC (rev 9305)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2008-09-12 18:40:41 UTC (rev 9306)
@@ -542,6 +542,7 @@
   {
     rasterLayerType = MULTIBAND;
   }
+  //TODO hasBand is really obsolete and only used in the Palette instance, change to new function hasPalette(int)
   else if ( hasBand( "Palette" ) ) //dont tr() this its a gdal word!
   {
     rasterLayerType = PALETTE;
@@ -3433,6 +3434,9 @@
 QString QgsRasterLayer::buildPyramids( RasterPyramidList const & theRasterPyramidList,
                                        QString const & theResamplingMethod, bool theTryInternalFlag )
 {
+  //TODO: Consider making theRasterPyramidList modifyable by this method to indicate if the pyramid exists after build attempt
+  //without requiring the user to rebuild the pyramid list to get the updated infomation
+  
   //
   // Note: Make sure the raster is not opened in write mode
   // in order to force overviews to be written to a separate file.
@@ -3456,20 +3460,22 @@
     return "ERROR_VIRTUAL";
   }
 
-
   if ( theTryInternalFlag )
   {
     //close the gdal dataset and reopen it in read / write mode
     GDALClose( mGdalDataset );
-    mGdalDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_Update );
+    mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_Update );
 
     // if the dataset couldn't be opened in read / write mode, tell the user
-    if ( !mGdalDataset )
+    if ( !mGdalBaseDataset )
     {
-      mGdalDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
+      mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
+      //Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
+      mGdalDataset = mGdalBaseDataset;
       return "ERROR_WRITE_FORMAT";
     }
   }
+  
   //
   // Iterate through the Raster Layer Pyramid Vector, building any pyramid
   // marked as exists in eaxh RasterPyramid struct.
@@ -3486,9 +3492,9 @@
     QgsLogger::debug( "Build pyramids:: Level", ( *myRasterPyramidIterator ).level, 1, __FILE__, __FUNCTION__, __LINE__ );
     QgsLogger::debug( "x", ( *myRasterPyramidIterator ).xDim, 1, __FILE__, __FUNCTION__, __LINE__ );
     QgsLogger::debug( "y", ( *myRasterPyramidIterator ).yDim, 1, __FILE__, __FUNCTION__, __LINE__ );
-    QgsLogger::debug( "exists :", ( *myRasterPyramidIterator ).existsFlag,  1, __FILE__, __FUNCTION__, __LINE__ );
+    QgsLogger::debug( "exists :", ( *myRasterPyramidIterator ).exists,  1, __FILE__, __FUNCTION__, __LINE__ );
 #endif
-    if (( *myRasterPyramidIterator ).existsFlag )
+    if (( *myRasterPyramidIterator ).build )
     {
       QgsDebugMsg( "Building....." );
       emit drawingProgress( myCount, myTotal );
@@ -3513,32 +3519,40 @@
         //see ticket #284
         if ( theResamplingMethod == tr( "Average Magphase" ) )
         {
-          myError = GDALBuildOverviews( mGdalDataset, "MODE", 1, myOverviewLevelsArray, 0, NULL,
+          myError = GDALBuildOverviews( mGdalBaseDataset, "MODE", 1, myOverviewLevelsArray, 0, NULL,
                                         progressCallback, this ); //this is the arg for the gdal progress callback
         }
         else if ( theResamplingMethod == tr( "Average" ) )
 
         {
-          myError = GDALBuildOverviews( mGdalDataset, "AVERAGE", 1, myOverviewLevelsArray, 0, NULL,
+          myError = GDALBuildOverviews( mGdalBaseDataset, "AVERAGE", 1, myOverviewLevelsArray, 0, NULL,
                                         progressCallback, this ); //this is the arg for the gdal progress callback
         }
         else // fall back to nearest neighbor
         {
-          myError = GDALBuildOverviews( mGdalDataset, "NEAREST", 1, myOverviewLevelsArray, 0, NULL,
+          myError = GDALBuildOverviews( mGdalBaseDataset, "NEAREST", 1, myOverviewLevelsArray, 0, NULL,
                                         progressCallback, this ); //this is the arg for the gdal progress callback
         }
+        
         if ( myError == CE_Failure || CPLGetLastErrorNo() == CPLE_NotSupported )
         {
           //something bad happenend
           //QString myString = QString (CPLGetLastError());
-          GDALClose( mGdalDataset );
-          mGdalDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
+          GDALClose( mGdalBaseDataset );
+          mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
+          //Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
+          mGdalDataset = mGdalBaseDataset;
+          
           emit drawingProgress( 0, 0 );
           return "FAILED_NOT_SUPPORTED";
         }
+        else
+        {
+          //make sure the raster knows it has pyramids
+          hasPyramidsFlag = true;
+        }
         myCount++;
-        //make sure the raster knows it has pyramids
-        hasPyramidsFlag = true;
+        
       }
       catch ( CPLErr )
       {
@@ -3546,13 +3560,17 @@
       }
     }
   }
+  
   QgsDebugMsg( "Pyramid overviews built" );
   if ( theTryInternalFlag )
   {
     //close the gdal dataset and reopen it in read only mode
-    GDALClose( mGdalDataset );
-    mGdalDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
+    GDALClose( mGdalBaseDataset );
+    mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
+    //Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
+    mGdalDataset = mGdalBaseDataset;
   }
+  
   emit drawingProgress( 0, 0 );
   return NULL; // returning null on success
 }
@@ -3576,16 +3594,13 @@
     myRasterPyramid.level = myDivisor;
     myRasterPyramid.xDim = ( int )( 0.5 + ( myWidth / ( double )myDivisor ) );
     myRasterPyramid.yDim = ( int )( 0.5 + ( myHeight / ( double )myDivisor ) );
-    myRasterPyramid.existsFlag = false;
+    myRasterPyramid.exists = false;
 #ifdef QGISDEBUG
     QgsLogger::debug( "Pyramid", myRasterPyramid.level, 1, __FILE__, __FUNCTION__, __LINE__ );
     QgsLogger::debug( "xDim", myRasterPyramid.xDim, 1, __FILE__, __FUNCTION__, __LINE__ );
     QgsLogger::debug( "yDim", myRasterPyramid.yDim, 1, __FILE__, __FUNCTION__, __LINE__ );
 #endif
 
-
-
-
     //
     // Now we check if it actually exists in the raster layer
     // and also adjust the dimensions if the dimensions calculated
@@ -3620,7 +3635,7 @@
           //right we have a match so adjust the a / y before they get added to the list
           myRasterPyramid.xDim = myOverviewXDim;
           myRasterPyramid.yDim = myOverviewYDim;
-          myRasterPyramid.existsFlag = true;
+          myRasterPyramid.exists = true;
           QgsDebugMsg( ".....YES!" );
         }
         else

Modified: trunk/qgis/src/core/raster/qgsrasterpyramid.h
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterpyramid.h	2008-09-12 17:02:40 UTC (rev 9305)
+++ trunk/qgis/src/core/raster/qgsrasterpyramid.h	2008-09-12 18:40:41 UTC (rev 9306)
@@ -30,7 +30,18 @@
     /** \brief YDimension for this pyramid layer */
     int yDim;
     /** \brief Whether the pyramid layer has been built yet */
-    bool existsFlag;
+    bool exists;
+    /** \brief Whether the pyramid should be built */
+    bool build;
+    
+    QgsRasterPyramid()
+    {
+      level = 0;
+      xDim = 0;
+      yDim = 0;
+      exists = false;
+      build = false;
+    }
 
 };
 #endif

Modified: trunk/qgis/tests/src/core/testqgsrasterlayer.cpp
===================================================================
--- trunk/qgis/tests/src/core/testqgsrasterlayer.cpp	2008-09-12 17:02:40 UTC (rev 9305)
+++ trunk/qgis/tests/src/core/testqgsrasterlayer.cpp	2008-09-12 18:40:41 UTC (rev 9306)
@@ -178,7 +178,7 @@
   for ( int myCounterInt = 0; myCounterInt < myPyramidList.count(); myCounterInt++ )
   {
     //mark to be pyramided
-    myPyramidList[myCounterInt].existsFlag = true;
+    myPyramidList[myCounterInt].build = true;
   }
   //now actually make the pyramids
   QString myResult = mypLayer->buildPyramids(
@@ -194,7 +194,7 @@
   for ( int myCounterInt = 0; myCounterInt < myPyramidList.count(); myCounterInt++ )
   {
     //mark to be pyramided
-    QVERIFY( myPyramidList.at( myCounterInt ).existsFlag );
+    QVERIFY( myPyramidList.at( myCounterInt ).exists );
   }
 
   //



More information about the QGIS-commit mailing list