add support for raster creation options to raster calculator (fix #39082)

This commit is contained in:
Alexander Bruy 2025-03-20 14:22:15 +00:00
parent 17824ad647
commit 687e4e673a
4 changed files with 54 additions and 1 deletions

View File

@ -146,6 +146,24 @@ The optional ``feedback`` argument can be used for progress reporting and cancel
Returns a description of the last error encountered.
.. versionadded:: 3.4
%End
void setCreateOptions( const QStringList &list );
%Docstring
Sets a list of data source creation options to use when creating the output raster file.
.. seealso:: :py:func:`createOptions`
.. versionadded:: 3.44
%End
QStringList createOptions() const;
%Docstring
Returns the list of data source creation options which will be used when creating the output raster file.
.. seealso:: :py:func:`setCreateOptions`
.. versionadded:: 3.44
%End
};

View File

@ -146,6 +146,24 @@ The optional ``feedback`` argument can be used for progress reporting and cancel
Returns a description of the last error encountered.
.. versionadded:: 3.4
%End
void setCreateOptions( const QStringList &list );
%Docstring
Sets a list of data source creation options to use when creating the output raster file.
.. seealso:: :py:func:`createOptions`
.. versionadded:: 3.44
%End
QStringList createOptions() const;
%Docstring
Returns the list of data source creation options which will be used when creating the output raster file.
.. seealso:: :py:func:`setCreateOptions`
.. versionadded:: 3.44
%End
};

View File

@ -698,7 +698,7 @@ GDALDriverH QgsRasterCalculator::openOutputDriver()
gdal::dataset_unique_ptr QgsRasterCalculator::openOutputFile( GDALDriverH outputDriver )
{
//open output file
char **papszOptions = nullptr;
char **papszOptions = QgsGdalUtils::papszFromStringList( mCreateOptions );
gdal::dataset_unique_ptr outputDataset( GDALCreate( outputDriver, mOutputFile.toUtf8().constData(), mNumOutputColumns, mNumOutputRows, 1, GDT_Float32, papszOptions ) );
if ( !outputDataset )
{

View File

@ -160,6 +160,22 @@ class ANALYSIS_EXPORT QgsRasterCalculator
*/
QString lastError() const;
/**
* Sets a list of data source creation options to use when creating the output raster file.
*
* \see createOptions()
* \since QGIS 3.44
*/
void setCreateOptions( const QStringList &list ) { mCreateOptions = list; }
/**
* Returns the list of data source creation options which will be used when creating the output raster file.
*
* \see setCreateOptions()
* \since QGIS 3.44
*/
QStringList createOptions() const { return mCreateOptions; }
private:
//default constructor forbidden. We need formula, output file, output format and output raster resolution obligatory
QgsRasterCalculator() = delete;
@ -199,6 +215,7 @@ class ANALYSIS_EXPORT QgsRasterCalculator
int mNumOutputRows = 0;
QString mLastError;
QStringList mCreateOptions;
/***/
QVector<QgsRasterCalculatorEntry> mRasterEntries;