Skip to content

Commit 030f920

Browse files
author
timlinux
committed
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
1 parent a877a1a commit 030f920

5 files changed

+73
-47
lines changed

python/core/qgsrasterlayer.sip

+8-2
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,18 @@ public slots:
463463

464464
/** \brief Create gdal pyramid overviews for this layer.
465465
* This will speed up performance at the expense of hard drive space.
466-
* Also, write access to the file is required. If no paramter is passed in
466+
* Also, write access to the file is required for creating internal pyramids,
467+
* and to the directory in which the files exists if external
468+
* pyramids (.ovr) are to be created. If no paramter is passed in
467469
* it will default to nearest neighbor resampling.
470+
* @param theTryInternalFlag - Try to make the pyramids internal to
471+
* the raster file if supported (e.g. geotiff). If not supported it
472+
* will revert to creating external .ovr file anyway.
468473
* \return null string on success, otherwise a string specifying error
469474
*/
470475
QString buildPyramids(const RasterPyramidList &,
471-
const QString & theResamplingMethod="NEAREST");
476+
const QString & theResamplingMethod="NEAREST",
477+
bool theTryInternalFlag=false);
472478
/** \brief Used at the moment by the above function but hopefully will later
473479
be useable by any operation that needs to notify the user of its progress. */
474480
/*

src/app/qgsrasterlayerproperties.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ QgsRasterLayerProperties::QgsRasterLayerProperties(QgsMapLayer *lyr, QWidget *pa
334334
QString pyramidSentence1 = tr("Large resolution raster layers can slow navigation in QGIS.");
335335
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.");
336336
QString pyramidSentence3 = tr("You must have write access in the directory where the original data is stored to build pyramids.");
337-
QString pyramidSentence4 = tr("Please note that building pyramids may alter the original data file and once created they cannot be removed!");
338-
QString pyramidSentence5 = tr("Please note that building pyramids could corrupt your image - always make a backup of your data first!");
337+
QString pyramidSentence4 = tr("Please note that building internal pyramids may alter the original data file and once created they cannot be removed!");
338+
QString pyramidSentence5 = tr("Please note that building internal pyramids could corrupt your image - always make a backup of your data first!");
339339

340340
tePyramidDescription->setHtml(pyramidFormat.arg(pyramidHeader).arg(pyramidSentence1)
341341
.arg(pyramidSentence2).arg(pyramidSentence3)
@@ -1591,7 +1591,11 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
15911591

15921592
// let the user know we're going to possibly be taking a while
15931593
QApplication::setOverrideCursor(Qt::WaitCursor);
1594-
QString res = mRasterLayer->buildPyramids(myPyramidList,cboResamplingMethod->currentText());
1594+
bool myBuildInternalFlag = cbxInternalPyramids->isChecked();
1595+
QString res = mRasterLayer->buildPyramids(
1596+
myPyramidList,
1597+
cboResamplingMethod->currentText(),
1598+
myBuildInternalFlag);
15951599
QApplication::restoreOverrideCursor();
15961600
disconnect(mRasterLayer, SIGNAL(progressUpdate(int)), mPyramidProgress, SLOT(setValue(int)));
15971601
if (!res.isNull())

src/core/raster/qgsrasterlayer.cpp

+24-15
Original file line numberDiff line numberDiff line change
@@ -3653,8 +3653,14 @@ QString QgsRasterLayer::getMetadata()
36533653
}
36543654

36553655
QString QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramidList,
3656-
QString const & theResamplingMethod)
3656+
QString const & theResamplingMethod, bool theTryInternalFlag)
36573657
{
3658+
//
3659+
// Note: Make sure the raster is not opened in write mode
3660+
// in order to force overviews to be written to a separate file.
3661+
//
3662+
3663+
36583664
emit drawingProgress(0,0);
36593665
//first test if the file is writeable
36603666
QFileInfo myQFile(mDataSource);
@@ -3670,20 +3676,20 @@ QString QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramid
36703676
return "ERROR_VIRTUAL";
36713677
}
36723678

3673-
registerGdalDrivers();
3674-
3675-
//close the gdal dataset and reopen it in read / write mode
3676-
GDALClose( mGdalDataset );
3677-
mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_Update);
36783679

3679-
// if the dataset couldn't be opened in read / write mode, tell the user
3680-
if (!mGdalDataset)
3680+
if (theTryInternalFlag)
36813681
{
3682-
emit drawingProgress(0,0);
3683-
mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_ReadOnly);
3684-
return "ERROR_WRITE_FORMAT";
3685-
}
3682+
//close the gdal dataset and reopen it in read / write mode
3683+
GDALClose( mGdalDataset );
3684+
mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_Update);
36863685

3686+
// if the dataset couldn't be opened in read / write mode, tell the user
3687+
if (!mGdalDataset)
3688+
{
3689+
mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_ReadOnly);
3690+
return "ERROR_WRITE_FORMAT";
3691+
}
3692+
}
36873693
//
36883694
// Iterate through the Raster Layer Pyramid Vector, building any pyramid
36893695
// marked as exists in eaxh RasterPyramid struct.
@@ -3761,9 +3767,12 @@ QString QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramid
37613767
}
37623768
}
37633769
QgsDebugMsg("Pyramid overviews built");
3764-
//close the gdal dataset and reopen it in read only mode
3765-
GDALClose( mGdalDataset );
3766-
mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_ReadOnly);
3770+
if (theTryInternalFlag)
3771+
{
3772+
//close the gdal dataset and reopen it in read only mode
3773+
GDALClose( mGdalDataset );
3774+
mGdalDataset = GDALOpen(QFile::encodeName(mDataSource).constData(), GA_ReadOnly);
3775+
}
37673776
emit drawingProgress(0,0);
37683777
return NULL; // returning null on success
37693778
}

src/core/raster/qgsrasterlayer.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -839,12 +839,18 @@ public slots:
839839

840840
/** \brief Create gdal pyramid overviews for this layer.
841841
* This will speed up performance at the expense of hard drive space.
842-
* Also, write access to the file is required. If no paramter is passed in
842+
* Also, write access to the file is required for creating internal pyramids,
843+
* and to the directory in which the files exists if external
844+
* pyramids (.ovr) are to be created. If no paramter is passed in
843845
* it will default to nearest neighbor resampling.
846+
* @param theTryInternalFlag - Try to make the pyramids internal to
847+
* the raster file if supported (e.g. geotiff). If not supported it
848+
* will revert to creating external .ovr file anyway.
844849
* \return null string on success, otherwise a string specifying error
845850
*/
846851
QString buildPyramids(const RasterPyramidList &,
847-
const QString & theResamplingMethod="NEAREST");
852+
const QString & theResamplingMethod="NEAREST",
853+
bool theTryInternalFlag=false);
848854
/** \brief Used at the moment by the above function but hopefully will later
849855
be useable by any operation that needs to notify the user of its progress. */
850856
/*

src/ui/qgsrasterlayerpropertiesbase.ui

+26-25
Original file line numberDiff line numberDiff line change
@@ -729,19 +729,6 @@
729729
</property>
730730
</widget>
731731
</item>
732-
<item row="3" column="0" >
733-
<spacer>
734-
<property name="orientation" >
735-
<enum>Qt::Vertical</enum>
736-
</property>
737-
<property name="sizeHint" >
738-
<size>
739-
<width>20</width>
740-
<height>0</height>
741-
</size>
742-
</property>
743-
</spacer>
744-
</item>
745732
<item row="4" column="0" colspan="2" >
746733
<widget class="Line" name="line" >
747734
<property name="orientation" >
@@ -1786,7 +1773,21 @@
17861773
<string>Pyramids</string>
17871774
</attribute>
17881775
<layout class="QGridLayout" >
1789-
<item rowspan="2" row="0" column="0" colspan="3" >
1776+
<item row="0" column="0" >
1777+
<widget class="QLabel" name="label_3" >
1778+
<property name="text" >
1779+
<string>Notes</string>
1780+
</property>
1781+
</widget>
1782+
</item>
1783+
<item row="0" column="3" colspan="2" >
1784+
<widget class="QLabel" name="textLabel5" >
1785+
<property name="text" >
1786+
<string>Pyramid resolutions</string>
1787+
</property>
1788+
</widget>
1789+
</item>
1790+
<item row="1" column="0" colspan="3" >
17901791
<widget class="QTextEdit" name="tePyramidDescription" >
17911792
<property name="sizePolicy" >
17921793
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
@@ -1802,13 +1803,6 @@ p, li { white-space: pre-wrap; }
18021803
</property>
18031804
</widget>
18041805
</item>
1805-
<item row="0" column="3" colspan="2" >
1806-
<widget class="QLabel" name="textLabel5" >
1807-
<property name="text" >
1808-
<string>Pyramid resolutions</string>
1809-
</property>
1810-
</widget>
1811-
</item>
18121806
<item row="1" column="3" colspan="2" >
18131807
<widget class="QListWidget" name="lbxPyramidResolutions" >
18141808
<property name="sizePolicy" >
@@ -1828,7 +1822,14 @@ p, li { white-space: pre-wrap; }
18281822
</property>
18291823
</widget>
18301824
</item>
1831-
<item row="2" column="0" >
1825+
<item row="2" column="0" colspan="5" >
1826+
<widget class="QCheckBox" name="cbxInternalPyramids" >
1827+
<property name="text" >
1828+
<string>Build pyramids internally if possible</string>
1829+
</property>
1830+
</widget>
1831+
</item>
1832+
<item row="3" column="0" >
18321833
<widget class="QLabel" name="textLabel4_2" >
18331834
<property name="text" >
18341835
<string>Resampling method</string>
@@ -1838,7 +1839,7 @@ p, li { white-space: pre-wrap; }
18381839
</property>
18391840
</widget>
18401841
</item>
1841-
<item row="2" column="1" >
1842+
<item row="3" column="1" >
18421843
<widget class="QComboBox" name="cboResamplingMethod" >
18431844
<item>
18441845
<property name="text" >
@@ -1852,14 +1853,14 @@ p, li { white-space: pre-wrap; }
18521853
</item>
18531854
</widget>
18541855
</item>
1855-
<item row="2" column="2" colspan="2" >
1856+
<item row="3" column="2" colspan="2" >
18561857
<widget class="QProgressBar" name="mPyramidProgress" >
18571858
<property name="value" >
18581859
<number>0</number>
18591860
</property>
18601861
</widget>
18611862
</item>
1862-
<item row="2" column="4" >
1863+
<item row="3" column="4" >
18631864
<widget class="QPushButton" name="buttonBuildPyramids" >
18641865
<property name="text" >
18651866
<string>Build pyramids</string>

0 commit comments

Comments
 (0)