From 030f920169f19b5a4cafcd416b446df1742d5975 Mon Sep 17 00:00:00 2001 From: timlinux Date: Fri, 1 Aug 2008 19:13:47 +0000 Subject: [PATCH] Fix for #605 - make building pyramids internally optional. Also some ui cleanups to the pyramids part af raster props git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8968 c8812cc2-4d05-0410-92ff-de0c093fc19c --- python/core/qgsrasterlayer.sip | 10 ++++- src/app/qgsrasterlayerproperties.cpp | 10 +++-- src/core/raster/qgsrasterlayer.cpp | 39 ++++++++++++-------- src/core/raster/qgsrasterlayer.h | 10 ++++- src/ui/qgsrasterlayerpropertiesbase.ui | 51 +++++++++++++------------- 5 files changed, 73 insertions(+), 47 deletions(-) diff --git a/python/core/qgsrasterlayer.sip b/python/core/qgsrasterlayer.sip index 5983ba01f3a9..c96aa8cbc8ab 100644 --- a/python/core/qgsrasterlayer.sip +++ b/python/core/qgsrasterlayer.sip @@ -463,12 +463,18 @@ public slots: /** \brief Create gdal pyramid overviews for this layer. * This will speed up performance at the expense of hard drive space. - * Also, write access to the file is required. If no paramter is passed in + * Also, write access to the file is required for creating internal pyramids, + * and to the directory in which the files exists if external + * pyramids (.ovr) are to be created. If no paramter is passed in * it will default to nearest neighbor resampling. + * @param theTryInternalFlag - Try to make the pyramids internal to + * the raster file if supported (e.g. geotiff). If not supported it + * will revert to creating external .ovr file anyway. * \return null string on success, otherwise a string specifying error */ QString buildPyramids(const RasterPyramidList &, - const QString & theResamplingMethod="NEAREST"); + const QString & theResamplingMethod="NEAREST", + bool theTryInternalFlag=false); /** \brief Used at the moment by the above function but hopefully will later be useable by any operation that needs to notify the user of its progress. */ /* diff --git a/src/app/qgsrasterlayerproperties.cpp b/src/app/qgsrasterlayerproperties.cpp index ea749579efce..1229ad997701 100644 --- a/src/app/qgsrasterlayerproperties.cpp +++ b/src/app/qgsrasterlayerproperties.cpp @@ -334,8 +334,8 @@ QgsRasterLayerProperties::QgsRasterLayerProperties(QgsMapLayer *lyr, QWidget *pa QString pyramidSentence1 = tr("Large resolution raster layers can slow navigation in QGIS."); QString pyramidSentence2 = tr("By creating lower resolution copies of the data (pyramids) performance can be considerably improved as QGIS selects the most suitable resolution to use depending on the level of zoom."); QString pyramidSentence3 = tr("You must have write access in the directory where the original data is stored to build pyramids."); - QString pyramidSentence4 = tr("Please note that building pyramids may alter the original data file and once created they cannot be removed!"); - QString pyramidSentence5 = tr("Please note that building pyramids could corrupt your image - always make a backup of your data first!"); + QString pyramidSentence4 = tr("Please note that building internal pyramids may alter the original data file and once created they cannot be removed!"); + QString pyramidSentence5 = tr("Please note that building internal pyramids could corrupt your image - always make a backup of your data first!"); tePyramidDescription->setHtml(pyramidFormat.arg(pyramidHeader).arg(pyramidSentence1) .arg(pyramidSentence2).arg(pyramidSentence3) @@ -1591,7 +1591,11 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked() // let the user know we're going to possibly be taking a while QApplication::setOverrideCursor(Qt::WaitCursor); - QString res = mRasterLayer->buildPyramids(myPyramidList,cboResamplingMethod->currentText()); + bool myBuildInternalFlag = cbxInternalPyramids->isChecked(); + QString res = mRasterLayer->buildPyramids( + myPyramidList, + cboResamplingMethod->currentText(), + myBuildInternalFlag); QApplication::restoreOverrideCursor(); disconnect(mRasterLayer, SIGNAL(progressUpdate(int)), mPyramidProgress, SLOT(setValue(int))); if (!res.isNull()) diff --git a/src/core/raster/qgsrasterlayer.cpp b/src/core/raster/qgsrasterlayer.cpp index 77b736cb6732..4c3d31ee6291 100644 --- a/src/core/raster/qgsrasterlayer.cpp +++ b/src/core/raster/qgsrasterlayer.cpp @@ -3653,8 +3653,14 @@ QString QgsRasterLayer::getMetadata() } QString QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramidList, - QString const & theResamplingMethod) + QString const & theResamplingMethod, bool theTryInternalFlag) { + // + // Note: Make sure the raster is not opened in write mode + // in order to force overviews to be written to a separate file. + // + + emit drawingProgress(0,0); //first test if the file is writeable QFileInfo myQFile(mDataSource); @@ -3670,20 +3676,20 @@ QString QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramid return "ERROR_VIRTUAL"; } - registerGdalDrivers(); - - //close the gdal dataset and reopen it in read / write mode - GDALClose( mGdalDataset ); - mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_Update); - // if the dataset couldn't be opened in read / write mode, tell the user - if (!mGdalDataset) + if (theTryInternalFlag) { - emit drawingProgress(0,0); - mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_ReadOnly); - return "ERROR_WRITE_FORMAT"; - } + //close the gdal dataset and reopen it in read / write mode + GDALClose( mGdalDataset ); + mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_Update); + // if the dataset couldn't be opened in read / write mode, tell the user + if (!mGdalDataset) + { + mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_ReadOnly); + return "ERROR_WRITE_FORMAT"; + } + } // // Iterate through the Raster Layer Pyramid Vector, building any pyramid // marked as exists in eaxh RasterPyramid struct. @@ -3761,9 +3767,12 @@ QString QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramid } } QgsDebugMsg("Pyramid overviews built"); - //close the gdal dataset and reopen it in read only mode - GDALClose( mGdalDataset ); - mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_ReadOnly); + if (theTryInternalFlag) + { + //close the gdal dataset and reopen it in read only mode + GDALClose( mGdalDataset ); + mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_ReadOnly); + } emit drawingProgress(0,0); return NULL; // returning null on success } diff --git a/src/core/raster/qgsrasterlayer.h b/src/core/raster/qgsrasterlayer.h index 225289e5eaac..05ac2dc29fb2 100644 --- a/src/core/raster/qgsrasterlayer.h +++ b/src/core/raster/qgsrasterlayer.h @@ -839,12 +839,18 @@ public slots: /** \brief Create gdal pyramid overviews for this layer. * This will speed up performance at the expense of hard drive space. - * Also, write access to the file is required. If no paramter is passed in + * Also, write access to the file is required for creating internal pyramids, + * and to the directory in which the files exists if external + * pyramids (.ovr) are to be created. If no paramter is passed in * it will default to nearest neighbor resampling. + * @param theTryInternalFlag - Try to make the pyramids internal to + * the raster file if supported (e.g. geotiff). If not supported it + * will revert to creating external .ovr file anyway. * \return null string on success, otherwise a string specifying error */ QString buildPyramids(const RasterPyramidList &, - const QString & theResamplingMethod="NEAREST"); + const QString & theResamplingMethod="NEAREST", + bool theTryInternalFlag=false); /** \brief Used at the moment by the above function but hopefully will later be useable by any operation that needs to notify the user of its progress. */ /* diff --git a/src/ui/qgsrasterlayerpropertiesbase.ui b/src/ui/qgsrasterlayerpropertiesbase.ui index 2df095c84706..56dd4e91b203 100644 --- a/src/ui/qgsrasterlayerpropertiesbase.ui +++ b/src/ui/qgsrasterlayerpropertiesbase.ui @@ -729,19 +729,6 @@ - - - - Qt::Vertical - - - - 20 - 0 - - - - @@ -1786,7 +1773,21 @@ Pyramids - + + + + Notes + + + + + + + Pyramid resolutions + + + + @@ -1802,13 +1803,6 @@ p, li { white-space: pre-wrap; } - - - - Pyramid resolutions - - - @@ -1828,7 +1822,14 @@ p, li { white-space: pre-wrap; } - + + + + Build pyramids internally if possible + + + + Resampling method @@ -1838,7 +1839,7 @@ p, li { white-space: pre-wrap; } - + @@ -1852,14 +1853,14 @@ p, li { white-space: pre-wrap; } - + 0 - + Build pyramids