diff --git a/python/PyQt6/analysis/auto_generated/interpolation/qgsgridfilewriter.sip.in b/python/PyQt6/analysis/auto_generated/interpolation/qgsgridfilewriter.sip.in index 25d7e280117..b0383c402a7 100644 --- a/python/PyQt6/analysis/auto_generated/interpolation/qgsgridfilewriter.sip.in +++ b/python/PyQt6/analysis/auto_generated/interpolation/qgsgridfilewriter.sip.in @@ -37,6 +37,24 @@ Writes the grid file. An optional ``feedback`` object can be set for progress reports and cancellation support :return: 0 in case of success +%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 }; diff --git a/python/analysis/auto_generated/interpolation/qgsgridfilewriter.sip.in b/python/analysis/auto_generated/interpolation/qgsgridfilewriter.sip.in index 25d7e280117..b0383c402a7 100644 --- a/python/analysis/auto_generated/interpolation/qgsgridfilewriter.sip.in +++ b/python/analysis/auto_generated/interpolation/qgsgridfilewriter.sip.in @@ -37,6 +37,24 @@ Writes the grid file. An optional ``feedback`` object can be set for progress reports and cancellation support :return: 0 in case of success +%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 }; diff --git a/src/analysis/interpolation/qgsgridfilewriter.cpp b/src/analysis/interpolation/qgsgridfilewriter.cpp index c72cf0e7556..b8c02a20520 100644 --- a/src/analysis/interpolation/qgsgridfilewriter.cpp +++ b/src/analysis/interpolation/qgsgridfilewriter.cpp @@ -45,6 +45,7 @@ int QgsGridFileWriter::writeFile( QgsFeedback *feedback ) auto writer = std::make_unique( mOutputFilePath ); writer->setOutputProviderKey( QStringLiteral( "gdal" ) ); writer->setOutputFormat( outputFormat ); + writer->setCreateOptions( mCreateOptions ); std::unique_ptr provider( writer->createOneBandRaster( Qgis::DataType::Float32, mNumColumns, mNumRows, mInterpolationExtent, crs ) ); if ( !provider ) diff --git a/src/analysis/interpolation/qgsgridfilewriter.h b/src/analysis/interpolation/qgsgridfilewriter.h index 58c41e8e552..6af26f0eb82 100644 --- a/src/analysis/interpolation/qgsgridfilewriter.h +++ b/src/analysis/interpolation/qgsgridfilewriter.h @@ -53,6 +53,22 @@ class ANALYSIS_EXPORT QgsGridFileWriter */ int writeFile( QgsFeedback *feedback = nullptr ); + /** + * Sets a list of data source creation options to use when creating the output raster file. + * + * \see createOptions() + * \since QGIS 3.44t + */ + 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: QgsGridFileWriter() = delete; @@ -64,6 +80,8 @@ class ANALYSIS_EXPORT QgsGridFileWriter double mCellSizeX = 0; double mCellSizeY = 0; + + QStringList mCreateOptions; }; #endif diff --git a/tests/src/python/test_analysis_interpolation.py b/tests/src/python/test_analysis_interpolation.py index bf0bcfbd540..4adab308b3f 100644 --- a/tests/src/python/test_analysis_interpolation.py +++ b/tests/src/python/test_analysis_interpolation.py @@ -79,6 +79,23 @@ class TestInterpolation(QgisTestCase): writer = QgsGridFileWriter(interpolator, output_file, extent, cols, rows) writer.writeFile() + checker = QgsRasterChecker() + ok = checker.runTest( + "gdal", + output_file, + "gdal", + os.path.join(TEST_DATA_DIR, "analysis", "idw_interpolation.tif"), + ) + self.report += checker.report() + self.assertTrue(ok) + + tfw_file = os.path.join(tempfile.gettempdir(), "idw_interpolation.tfw") + self.assertFalse(os.path.exists(tfw_file)) + + # with raster creation options + writer.setCreateOptions(["TFW=yes"]) + writer.writeFile() + checker = QgsRasterChecker() ok = checker.runTest( "gdal", @@ -93,6 +110,7 @@ class TestInterpolation(QgisTestCase): f.write(self.report) self.assertTrue(ok) + self.assertTrue(os.path.exists(tfw_file)) def test_tin_interpolator(self): layer = QgsVectorLayer( @@ -124,6 +142,22 @@ class TestInterpolation(QgisTestCase): writer.writeFile() checker = QgsRasterChecker() + ok = checker.runTest( + "gdal", + output_file, + "gdal", + os.path.join(TEST_DATA_DIR, "analysis", "tin_interpolation.tif"), + ) + self.report += checker.report() + self.assertTrue(ok) + + tfw_file = os.path.join(tempfile.gettempdir(), "tin_interpolation.tfw") + self.assertFalse(os.path.exists(tfw_file)) + + # with raster creation options + writer.setCreateOptions(["TFW=yes"]) + writer.writeFile() + ok = checker.runTest( "gdal", output_file, @@ -137,6 +171,7 @@ class TestInterpolation(QgisTestCase): f.write(self.report) self.assertTrue(ok) + self.assertTrue(os.path.exists(tfw_file)) if __name__ == "__main__":