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@8968 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
timlinux 2008-08-01 19:13:47 +00:00
parent b2b3397441
commit 1a21e1856d
5 changed files with 73 additions and 47 deletions

View File

@ -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. */
/*

View File

@ -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())

View File

@ -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
}

View File

@ -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. */
/*

View File

@ -729,19 +729,6 @@
</property>
</widget>
</item>
<item row="3" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="2" >
<widget class="Line" name="line" >
<property name="orientation" >
@ -1786,7 +1773,21 @@
<string>Pyramids</string>
</attribute>
<layout class="QGridLayout" >
<item rowspan="2" row="0" column="0" colspan="3" >
<item row="0" column="0" >
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Notes</string>
</property>
</widget>
</item>
<item row="0" column="3" colspan="2" >
<widget class="QLabel" name="textLabel5" >
<property name="text" >
<string>Pyramid resolutions</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3" >
<widget class="QTextEdit" name="tePyramidDescription" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
@ -1802,13 +1803,6 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="0" column="3" colspan="2" >
<widget class="QLabel" name="textLabel5" >
<property name="text" >
<string>Pyramid resolutions</string>
</property>
</widget>
</item>
<item row="1" column="3" colspan="2" >
<widget class="QListWidget" name="lbxPyramidResolutions" >
<property name="sizePolicy" >
@ -1828,7 +1822,14 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="2" column="0" >
<item row="2" column="0" colspan="5" >
<widget class="QCheckBox" name="cbxInternalPyramids" >
<property name="text" >
<string>Build pyramids internally if possible</string>
</property>
</widget>
</item>
<item row="3" column="0" >
<widget class="QLabel" name="textLabel4_2" >
<property name="text" >
<string>Resampling method</string>
@ -1838,7 +1839,7 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="2" column="1" >
<item row="3" column="1" >
<widget class="QComboBox" name="cboResamplingMethod" >
<item>
<property name="text" >
@ -1852,14 +1853,14 @@ p, li { white-space: pre-wrap; }
</item>
</widget>
</item>
<item row="2" column="2" colspan="2" >
<item row="3" column="2" colspan="2" >
<widget class="QProgressBar" name="mPyramidProgress" >
<property name="value" >
<number>0</number>
</property>
</widget>
</item>
<item row="2" column="4" >
<item row="3" column="4" >
<widget class="QPushButton" name="buttonBuildPyramids" >
<property name="text" >
<string>Build pyramids</string>