From 3fcdf17c2982b60376281ac273f264e0a43cfc7a Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Mon, 27 Jan 2025 12:26:10 +0000 Subject: [PATCH 1/5] add test for QgsIdwInterpolator --- tests/src/python/CMakeLists.txt | 1 + .../src/python/test_analysis_interpolation.py | 98 +++++++++++++++++++ tests/testdata/analysis/idw_interpolation.asc | 12 +++ tests/testdata/analysis/idw_interpolation.prj | 1 + 4 files changed, 112 insertions(+) create mode 100644 tests/src/python/test_analysis_interpolation.py create mode 100644 tests/testdata/analysis/idw_interpolation.asc create mode 100644 tests/testdata/analysis/idw_interpolation.prj diff --git a/tests/src/python/CMakeLists.txt b/tests/src/python/CMakeLists.txt index cad5816969a5..62364f8ba884 100644 --- a/tests/src/python/CMakeLists.txt +++ b/tests/src/python/CMakeLists.txt @@ -403,6 +403,7 @@ ADD_PYTHON_TEST(PyQgsAttributeEditorAction test_qgsattributeeditoraction.py) ADD_PYTHON_TEST(PyQgsVectorTile test_qgsvectortile.py) ADD_PYTHON_TEST(PyQgsVtpk test_qgsvtpk.py) ADD_PYTHON_TEST(PyQgsProcessingAlgsGdalGdalUtils test_processing_algs_gdal_gdalutils.py) +ADD_PYTHON_TEST(PyQgsInterpolation test_analysis_interpolation.py) if (NOT WIN32) ADD_PYTHON_TEST(PyQgsLogger test_qgslogger.py) diff --git a/tests/src/python/test_analysis_interpolation.py b/tests/src/python/test_analysis_interpolation.py new file mode 100644 index 000000000000..155765471859 --- /dev/null +++ b/tests/src/python/test_analysis_interpolation.py @@ -0,0 +1,98 @@ +""" +*************************************************************************** + test_analysis_interpolation.py + --------------------- + Date : January 2025 + Copyright : (C) 2025 by Alexander Bruy + Email : alexander dot bruy at gmail.com +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = "Alexander Bruy" +__date__ = "January 2025" +__copyright__ = "(C) 2025, Alexander Bruy" + +import os +import math +import tempfile + +from qgis.core import ( + Qgis, + QgsCoordinateTransformContext, + QgsVectorLayer, + QgsRasterChecker, +) +from qgis.analysis import ( + QgsInterpolator, + QgsIDWInterpolator, + QgsGridFileWriter, +) + +import unittest +from qgis.testing import QgisTestCase + +from utilities import unitTestDataPath, start_app + +TEST_DATA_DIR = unitTestDataPath() +start_app() + + +class TestInterpolation(QgisTestCase): + + def __init__(self, methodName): + QgisTestCase.__init__(self, methodName) + self.report = "

Python Raster Analysis Interpolation Tests

\n" + + def test_idw_interpolator(self): + layer = QgsVectorLayer( + os.path.join(TEST_DATA_DIR, "points.shp"), "points", "ogr" + ) + self.assertTrue(layer.isValid()) + + pixel_size = 5 + extent = layer.extent() + context = QgsCoordinateTransformContext() + + cols = max(math.ceil(extent.width() / pixel_size), 1) + rows = max(math.ceil(extent.height() / pixel_size), 1) + + data = QgsInterpolator.LayerData() + data.source = layer + data.sourceType = QgsInterpolator.SourceType.SourcePoints + data.transformContext = context + data.valueSource = QgsInterpolator.ValueSource.ValueAttribute + data.interpolationAttribute = 3 + + interpolator = QgsIDWInterpolator([data]) + interpolator.setDistanceCoefficient(2.0) + + output_file = os.path.join(tempfile.gettempdir(), "idw_interpolation.asc") + + 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.asc"), + ) + self.report += checker.report() + + report_file = os.path.join(tempfile.gettempdir(), "idw_interpolation_test.html") + with open(report_file, "w", encoding="utf-8") as f: + f.write(self.report) + + self.assertTrue(ok) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/testdata/analysis/idw_interpolation.asc b/tests/testdata/analysis/idw_interpolation.asc new file mode 100644 index 000000000000..36bf9e4b9f82 --- /dev/null +++ b/tests/testdata/analysis/idw_interpolation.asc @@ -0,0 +1,12 @@ +NCOLS 8 +NROWS 5 +XLLCORNER -118.88889 +YLLCORNER 22.800207 +DX 4.4444444 +DY 4.8143547 +NODATA_VALUE -9999 +2.0121718 2.0665639 2.1247411 2.3766166 2.215217 2.2060108 2.3460969 2.4281324 +1.9794705 2.9664047 1.9469473 2.5244787 2.0403568 2.6551881 2.47681 2.9540972 +1.7556216 1.2623123 1.3645298 1.6318147 1.1678245 1.6944965 1.4976418 2.3077948 +1.6575363 1.3857927 1.7369403 1.6948927 1.6519006 1.7477886 1.7252076 2.0989999 +1.747618 1.7597898 2.017072 2.0723577 1.9158142 1.8779713 1.9250969 2.0499401 diff --git a/tests/testdata/analysis/idw_interpolation.prj b/tests/testdata/analysis/idw_interpolation.prj new file mode 100644 index 000000000000..5fbc831e7433 --- /dev/null +++ b/tests/testdata/analysis/idw_interpolation.prj @@ -0,0 +1 @@ +GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]] From 96802a078a0c841469507e7cb664aabef9ba362f Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Mon, 27 Jan 2025 12:54:47 +0000 Subject: [PATCH 2/5] add test for QgsTinInterpolator --- .../src/python/test_analysis_interpolation.py | 45 +++++++++++++++++++ tests/testdata/analysis/tin_interpolation.asc | 12 +++++ tests/testdata/analysis/tin_interpolation.prj | 1 + 3 files changed, 58 insertions(+) create mode 100644 tests/testdata/analysis/tin_interpolation.asc create mode 100644 tests/testdata/analysis/tin_interpolation.prj diff --git a/tests/src/python/test_analysis_interpolation.py b/tests/src/python/test_analysis_interpolation.py index 155765471859..2b5a451038e9 100644 --- a/tests/src/python/test_analysis_interpolation.py +++ b/tests/src/python/test_analysis_interpolation.py @@ -32,6 +32,7 @@ from qgis.analysis import ( QgsInterpolator, QgsIDWInterpolator, + QgsTinInterpolator, QgsGridFileWriter, ) @@ -93,6 +94,50 @@ def test_idw_interpolator(self): self.assertTrue(ok) + def test_tin_interpolator(self): + layer = QgsVectorLayer( + os.path.join(TEST_DATA_DIR, "points.shp"), "points", "ogr" + ) + self.assertTrue(layer.isValid()) + + pixel_size = 5 + extent = layer.extent() + context = QgsCoordinateTransformContext() + + cols = max(math.ceil(extent.width() / pixel_size), 1) + rows = max(math.ceil(extent.height() / pixel_size), 1) + + data = QgsInterpolator.LayerData() + data.source = layer + data.sourceType = QgsInterpolator.SourceType.SourcePoints + data.transformContext = context + data.valueSource = QgsInterpolator.ValueSource.ValueAttribute + data.interpolationAttribute = 3 + + interpolator = QgsTinInterpolator( + [data], QgsTinInterpolator.TinInterpolation.Linear + ) + + output_file = os.path.join(tempfile.gettempdir(), "tin_interpolation.asc") + + 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", "tin_interpolation.asc"), + ) + self.report += checker.report() + + report_file = os.path.join(tempfile.gettempdir(), "tin_interpolation_test.html") + with open(report_file, "w", encoding="utf-8") as f: + f.write(self.report) + + self.assertTrue(ok) + if __name__ == "__main__": unittest.main() diff --git a/tests/testdata/analysis/tin_interpolation.asc b/tests/testdata/analysis/tin_interpolation.asc new file mode 100644 index 000000000000..4f46319640b8 --- /dev/null +++ b/tests/testdata/analysis/tin_interpolation.asc @@ -0,0 +1,12 @@ +NCOLS 8 +NROWS 5 +XLLCORNER -118.88889 +YLLCORNER 22.800207 +DX 4.4444444 +DY 4.8143547 +NODATA_VALUE -9999 +-9999 -9999 -9999 2.0980652 2.3606286 2.2927486 -9999 -9999 +-9999 2.9180237 2.725426 2.5698732 1.8980129 2.5750412 2.8987709 -9999 +-9999 1 1.0520833 1.60625 1.1508401 1.122037 1.2837485 2.2915296 +-9999 -9999 1.8246582 1.4968504 1.3897458 1.3489822 -9999 -9999 +-9999 -9999 -9999 1.8401575 -9999 -9999 -9999 -9999 diff --git a/tests/testdata/analysis/tin_interpolation.prj b/tests/testdata/analysis/tin_interpolation.prj new file mode 100644 index 000000000000..5fbc831e7433 --- /dev/null +++ b/tests/testdata/analysis/tin_interpolation.prj @@ -0,0 +1 @@ +GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]] From 7d45dc77793f42a44718bff73d880f1e9a37990e Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Mon, 27 Jan 2025 14:18:11 +0000 Subject: [PATCH 3/5] use QGIS API to write raster files in QgsGridFileWriter (fix #56653) --- .../interpolation/qgsgridfilewriter.cpp | 96 +++++++----------- .../interpolation/qgsgridfilewriter.h | 2 - .../src/python/test_analysis_interpolation.py | 8 +- tests/testdata/analysis/idw_interpolation.asc | 12 --- tests/testdata/analysis/idw_interpolation.prj | 1 - tests/testdata/analysis/idw_interpolation.tif | Bin 0 -> 902 bytes tests/testdata/analysis/tin_interpolation.asc | 12 --- tests/testdata/analysis/tin_interpolation.prj | 1 - tests/testdata/analysis/tin_interpolation.tif | Bin 0 -> 902 bytes 9 files changed, 39 insertions(+), 93 deletions(-) delete mode 100644 tests/testdata/analysis/idw_interpolation.asc delete mode 100644 tests/testdata/analysis/idw_interpolation.prj create mode 100644 tests/testdata/analysis/idw_interpolation.tif delete mode 100644 tests/testdata/analysis/tin_interpolation.asc delete mode 100644 tests/testdata/analysis/tin_interpolation.prj create mode 100644 tests/testdata/analysis/tin_interpolation.tif diff --git a/src/analysis/interpolation/qgsgridfilewriter.cpp b/src/analysis/interpolation/qgsgridfilewriter.cpp index 838505c80c86..abd92e9f7be3 100644 --- a/src/analysis/interpolation/qgsgridfilewriter.cpp +++ b/src/analysis/interpolation/qgsgridfilewriter.cpp @@ -19,7 +19,9 @@ #include "qgsinterpolator.h" #include "qgsvectorlayer.h" #include "qgsfeedback.h" -#include +#include "qgsrasterfilewriter.h" +#include "qgsrasterdataprovider.h" +#include "qgsrasterblock.h" #include QgsGridFileWriter::QgsGridFileWriter( QgsInterpolator *i, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows ) @@ -34,95 +36,67 @@ QgsGridFileWriter::QgsGridFileWriter( QgsInterpolator *i, const QString &outputP int QgsGridFileWriter::writeFile( QgsFeedback *feedback ) { - QFile outputFile( mOutputFilePath ); + const QFileInfo fi( mOutputFilePath ); + const QString outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() ); + + QgsInterpolator::LayerData ld = mInterpolator->layerData().at( 0 ); + const QgsCoordinateReferenceSystem crs = ld.source->sourceCrs(); - if ( !outputFile.open( QFile::WriteOnly | QIODevice::Truncate ) ) + std::unique_ptr writer = std::make_unique( mOutputFilePath ); + writer->setOutputProviderKey( QStringLiteral( "gdal" ) ); + writer->setOutputFormat( outputFormat ); + + std::unique_ptr provider( writer->createOneBandRaster( Qgis::DataType::Float32, mNumColumns, mNumRows, mInterpolationExtent, crs ) ); + if ( !provider ) { + QgsDebugMsgLevel( QStringLiteral( "Could not create raster output: %1" ).arg( mOutputFilePath ), 2 ); return 1; } - - if ( !mInterpolator ) + if ( !provider->isValid() ) { - outputFile.remove(); + QgsDebugMsgLevel( QStringLiteral( "Could not create raster output: %1: %2" ).arg( mOutputFilePath, provider->error().message( QgsErrorMessage::Text ) ), 2 ); return 2; } - QTextStream outStream( &outputFile ); -#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) - outStream.setCodec( "UTF-8" ); -#endif - outStream.setRealNumberPrecision( 8 ); - writeHeader( outStream ); + provider->setNoDataValue( 1, -9999 ); double currentYValue = mInterpolationExtent.yMaximum() - mCellSizeY / 2.0; //calculate value in the center of the cell double currentXValue; double interpolatedValue; - for ( int i = 0; i < mNumRows; ++i ) + const double step = mNumRows > 0 ? 100.0 / mNumRows : 1; + for ( int row = 0; row < mNumRows; row++ ) { + if ( feedback && feedback->isCanceled() ) + { + break; + } + currentXValue = mInterpolationExtent.xMinimum() + mCellSizeX / 2.0; //calculate value in the center of the cell - for ( int j = 0; j < mNumColumns; ++j ) + + QgsRasterBlock block( Qgis::DataType::Float32, mNumColumns, 1 ); + + std::vector float32Row( mNumColumns ); + for ( int col = 0; col < mNumColumns; col++ ) { if ( mInterpolator->interpolatePoint( currentXValue, currentYValue, interpolatedValue, feedback ) == 0 ) { - outStream << interpolatedValue << ' '; + float32Row[col] = interpolatedValue; } else { - outStream << "-9999 "; + float32Row[col] = -9999; } currentXValue += mCellSizeX; } - - outStream << Qt::endl; + block.setData( QByteArray( reinterpret_cast( float32Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::Float32 ) * mNumColumns ) ); + provider->writeBlock( &block, 1, 0, row ); currentYValue -= mCellSizeY; - if ( feedback ) { - if ( feedback->isCanceled() ) - { - outputFile.remove(); - return 3; - } - feedback->setProgress( 100.0 * i / static_cast( mNumRows ) ); + feedback->setProgress( row * step ); } } - // create prj file - QgsInterpolator::LayerData ld; - ld = mInterpolator->layerData().at( 0 ); - QgsFeatureSource *source = ld.source; - const QString crs = source->sourceCrs().toWkt(); - const QFileInfo fi( mOutputFilePath ); - const QString fileName = fi.absolutePath() + '/' + fi.completeBaseName() + ".prj"; - QFile prjFile( fileName ); - if ( !prjFile.open( QFile::WriteOnly | QIODevice::Truncate ) ) - { - return 1; - } - QTextStream prjStream( &prjFile ); - prjStream << crs; - prjStream << Qt::endl; - prjFile.close(); - - return 0; -} - -int QgsGridFileWriter::writeHeader( QTextStream &outStream ) -{ - outStream << "NCOLS " << mNumColumns << Qt::endl; - outStream << "NROWS " << mNumRows << Qt::endl; - outStream << "XLLCORNER " << mInterpolationExtent.xMinimum() << Qt::endl; - outStream << "YLLCORNER " << mInterpolationExtent.yMinimum() << Qt::endl; - if ( mCellSizeX == mCellSizeY ) //standard way - { - outStream << "CELLSIZE " << mCellSizeX << Qt::endl; - } - else //this is supported by GDAL but probably not by other products - { - outStream << "DX " << mCellSizeX << Qt::endl; - outStream << "DY " << mCellSizeY << Qt::endl; - } - outStream << "NODATA_VALUE -9999" << Qt::endl; return 0; } diff --git a/src/analysis/interpolation/qgsgridfilewriter.h b/src/analysis/interpolation/qgsgridfilewriter.h index 8f408c0a7c23..58c41e8e552c 100644 --- a/src/analysis/interpolation/qgsgridfilewriter.h +++ b/src/analysis/interpolation/qgsgridfilewriter.h @@ -56,8 +56,6 @@ class ANALYSIS_EXPORT QgsGridFileWriter private: QgsGridFileWriter() = delete; - int writeHeader( QTextStream &outStream ); - QgsInterpolator *mInterpolator = nullptr; QString mOutputFilePath; QgsRectangle mInterpolationExtent; diff --git a/tests/src/python/test_analysis_interpolation.py b/tests/src/python/test_analysis_interpolation.py index 2b5a451038e9..bf0bcfbd5407 100644 --- a/tests/src/python/test_analysis_interpolation.py +++ b/tests/src/python/test_analysis_interpolation.py @@ -74,7 +74,7 @@ def test_idw_interpolator(self): interpolator = QgsIDWInterpolator([data]) interpolator.setDistanceCoefficient(2.0) - output_file = os.path.join(tempfile.gettempdir(), "idw_interpolation.asc") + output_file = os.path.join(tempfile.gettempdir(), "idw_interpolation.tif") writer = QgsGridFileWriter(interpolator, output_file, extent, cols, rows) writer.writeFile() @@ -84,7 +84,7 @@ def test_idw_interpolator(self): "gdal", output_file, "gdal", - os.path.join(TEST_DATA_DIR, "analysis", "idw_interpolation.asc"), + os.path.join(TEST_DATA_DIR, "analysis", "idw_interpolation.tif"), ) self.report += checker.report() @@ -118,7 +118,7 @@ def test_tin_interpolator(self): [data], QgsTinInterpolator.TinInterpolation.Linear ) - output_file = os.path.join(tempfile.gettempdir(), "tin_interpolation.asc") + output_file = os.path.join(tempfile.gettempdir(), "tin_interpolation.tif") writer = QgsGridFileWriter(interpolator, output_file, extent, cols, rows) writer.writeFile() @@ -128,7 +128,7 @@ def test_tin_interpolator(self): "gdal", output_file, "gdal", - os.path.join(TEST_DATA_DIR, "analysis", "tin_interpolation.asc"), + os.path.join(TEST_DATA_DIR, "analysis", "tin_interpolation.tif"), ) self.report += checker.report() diff --git a/tests/testdata/analysis/idw_interpolation.asc b/tests/testdata/analysis/idw_interpolation.asc deleted file mode 100644 index 36bf9e4b9f82..000000000000 --- a/tests/testdata/analysis/idw_interpolation.asc +++ /dev/null @@ -1,12 +0,0 @@ -NCOLS 8 -NROWS 5 -XLLCORNER -118.88889 -YLLCORNER 22.800207 -DX 4.4444444 -DY 4.8143547 -NODATA_VALUE -9999 -2.0121718 2.0665639 2.1247411 2.3766166 2.215217 2.2060108 2.3460969 2.4281324 -1.9794705 2.9664047 1.9469473 2.5244787 2.0403568 2.6551881 2.47681 2.9540972 -1.7556216 1.2623123 1.3645298 1.6318147 1.1678245 1.6944965 1.4976418 2.3077948 -1.6575363 1.3857927 1.7369403 1.6948927 1.6519006 1.7477886 1.7252076 2.0989999 -1.747618 1.7597898 2.017072 2.0723577 1.9158142 1.8779713 1.9250969 2.0499401 diff --git a/tests/testdata/analysis/idw_interpolation.prj b/tests/testdata/analysis/idw_interpolation.prj deleted file mode 100644 index 5fbc831e7433..000000000000 --- a/tests/testdata/analysis/idw_interpolation.prj +++ /dev/null @@ -1 +0,0 @@ -GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]] diff --git a/tests/testdata/analysis/idw_interpolation.tif b/tests/testdata/analysis/idw_interpolation.tif new file mode 100644 index 0000000000000000000000000000000000000000..d961111262f46b84e2428e7c331aaa27301158aa GIT binary patch literal 902 zcmebD)MDUcVqg$pU|?isU}Rum-~eJqD4P|?W`eR6fNW+c8>Eg6i7m*;0@e!@W)MXZ z7lX1v=7=MykwH=u3}rI|)$ld*Fo5WDK-|>A!@vflp8@guc4h_zAT0*8ctbl61JJ;M+TL$p1%=zF{)_Q1}Q!UA*i-QnsP z!MK-hY~e0ht@P{2e0_Q z_LFbgI!rSCY0p1V(ZO^olf$fcnhty|at`nKZ5>Q^Jg_gGywLvTigosW_b=GHRZq2d zetN@x*QWjUFEEg6i7m*;0@e!@W)MXZ z7lX1v=7=MykwH=u3}rI|)$ld*Fo5WDK-|>A!@vflp8@guc4h_zAT0*8ctbl61JJ;M+TL$p1%=zF{)_Q1}Q!UA*i-QnsP z!MFxbc(gW=6?Yz|!_;tr{MgdAXEAo|$>D~H5fJ%_UuDh^_w zKG|2DRdFb9wM3|4Xs}YL*dAT4F~kLd-lIGfreI-~lk2VX5E;kPS-(8o(q1O9dG~ dHY^oX0NIU8n82x~0hEk@V6dkMT}vQf008e{h~oeN literal 0 HcmV?d00001 From e9e02711b02e2b501ea06dbf405621696166a592 Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Tue, 28 Jan 2025 13:39:45 +0000 Subject: [PATCH 4/5] update expected raster hashes --- .../tests/testdata/qgis_algorithm_tests2.yaml | 42 ++++++------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/python/plugins/processing/tests/testdata/qgis_algorithm_tests2.yaml b/python/plugins/processing/tests/testdata/qgis_algorithm_tests2.yaml index 7a4d24eed45b..dd65231793fe 100644 --- a/python/plugins/processing/tests/testdata/qgis_algorithm_tests2.yaml +++ b/python/plugins/processing/tests/testdata/qgis_algorithm_tests2.yaml @@ -14,9 +14,7 @@ tests: results: OUTPUT: hash: - - bfb3616a73065c0cb41eb1c5c1e9e8812fe1c63019a6177adb1dfe3e - - 19bbd79d15b0ba7dbde05665d559e9806fdb1cd579df9222f9cc4d92 - - 3dfa1e041f33a72abf72d2d706c03e11fa5274f152dec1db1661b8e0 + - e277a6774c489ee965421fe102780275163229b9407d5e33d3e268e5 type: rasterhash - algorithm: qgis:tininterpolation @@ -31,9 +29,7 @@ tests: results: OUTPUT: hash: - - bfb3616a73065c0cb41eb1c5c1e9e8812fe1c63019a6177adb1dfe3e - - 19bbd79d15b0ba7dbde05665d559e9806fdb1cd579df9222f9cc4d92 - - 3dfa1e041f33a72abf72d2d706c03e11fa5274f152dec1db1661b8e0 + - e277a6774c489ee965421fe102780275163229b9407d5e33d3e268e5 type: rasterhash - algorithm: qgis:tininterpolation @@ -48,9 +44,7 @@ tests: results: OUTPUT: hash: - - b8e49813c507b73cb39a5ad904b2d302ccb25c591a2e577b6405f982 - - 19bbd79d15b0ba7dbde05665d559e9806fdb1cd579df9222f9cc4d92 - - 3dfa1e041f33a72abf72d2d706c03e11fa5274f152dec1db1661b8e0 + - e277a6774c489ee965421fe102780275163229b9407d5e33d3e268e5 type: rasterhash - algorithm: qgis:tininterpolation @@ -66,9 +60,7 @@ tests: results: OUTPUT: hash: - - bfb3616a73065c0cb41eb1c5c1e9e8812fe1c63019a6177adb1dfe3e - - 19bbd79d15b0ba7dbde05665d559e9806fdb1cd579df9222f9cc4d92 - - 3dfa1e041f33a72abf72d2d706c03e11fa5274f152dec1db1661b8e0 + - e277a6774c489ee965421fe102780275163229b9407d5e33d3e268e5 type: rasterhash - algorithm: qgis:tininterpolation @@ -84,9 +76,7 @@ tests: results: OUTPUT: hash: - - bfb3616a73065c0cb41eb1c5c1e9e8812fe1c63019a6177adb1dfe3e - - 19bbd79d15b0ba7dbde05665d559e9806fdb1cd579df9222f9cc4d92 - - 3dfa1e041f33a72abf72d2d706c03e11fa5274f152dec1db1661b8e0 + - e277a6774c489ee965421fe102780275163229b9407d5e33d3e268e5 type: rasterhash - algorithm: qgis:tininterpolation @@ -102,9 +92,7 @@ tests: results: OUTPUT: hash: - - b8e49813c507b73cb39a5ad904b2d302ccb25c591a2e577b6405f982 - - 19bbd79d15b0ba7dbde05665d559e9806fdb1cd579df9222f9cc4d92 - - 3dfa1e041f33a72abf72d2d706c03e11fa5274f152dec1db1661b8e0 + - e277a6774c489ee965421fe102780275163229b9407d5e33d3e268e5 type: rasterhash - algorithm: qgis:idwinterpolation @@ -119,8 +107,7 @@ tests: results: OUTPUT: hash: - - 55dfd0e0e5ea300d2314785ab6aa1f4d941a4506e63d0d9e2b84e959 - - b5fc06549f1b0ce3261f9fb8868bb6d082edcbfe409c89a82e2b7e7a + - 7836f01a89afbfdd865aaae9b57c602c96d629184adf1b6ea66ca127 type: rasterhash - algorithm: qgis:idwinterpolation @@ -135,8 +122,7 @@ tests: results: OUTPUT: hash: - - 55dfd0e0e5ea300d2314785ab6aa1f4d941a4506e63d0d9e2b84e959 - - b5fc06549f1b0ce3261f9fb8868bb6d082edcbfe409c89a82e2b7e7a + - 7836f01a89afbfdd865aaae9b57c602c96d629184adf1b6ea66ca127 type: rasterhash - algorithm: qgis:idwinterpolation @@ -151,8 +137,7 @@ tests: results: OUTPUT: hash: - - d53cd7327d53bd4b8fb2de8b206e5aa0a1366963f2b63f58c2b7926e - - b5fc06549f1b0ce3261f9fb8868bb6d082edcbfe409c89a82e2b7e7a + - 7836f01a89afbfdd865aaae9b57c602c96d629184adf1b6ea66ca127 type: rasterhash - algorithm: qgis:idwinterpolation @@ -168,8 +153,7 @@ tests: results: OUTPUT: hash: - - 55dfd0e0e5ea300d2314785ab6aa1f4d941a4506e63d0d9e2b84e959 - - b5fc06549f1b0ce3261f9fb8868bb6d082edcbfe409c89a82e2b7e7a + - 7836f01a89afbfdd865aaae9b57c602c96d629184adf1b6ea66ca127 type: rasterhash - algorithm: qgis:idwinterpolation @@ -185,8 +169,7 @@ tests: results: OUTPUT: hash: - - 55dfd0e0e5ea300d2314785ab6aa1f4d941a4506e63d0d9e2b84e959 - - b5fc06549f1b0ce3261f9fb8868bb6d082edcbfe409c89a82e2b7e7a + - 7836f01a89afbfdd865aaae9b57c602c96d629184adf1b6ea66ca127 type: rasterhash - algorithm: qgis:idwinterpolation @@ -202,8 +185,7 @@ tests: results: OUTPUT: hash: - - d53cd7327d53bd4b8fb2de8b206e5aa0a1366963f2b63f58c2b7926e - - b5fc06549f1b0ce3261f9fb8868bb6d082edcbfe409c89a82e2b7e7a + - 7836f01a89afbfdd865aaae9b57c602c96d629184adf1b6ea66ca127 type: rasterhash - algorithm: native:removenullgeometries From 610c7f96440fdfa854297746a822266f8be3dd37 Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Wed, 29 Jan 2025 08:31:01 +0000 Subject: [PATCH 5/5] move vector declaration outside of the loop --- src/analysis/interpolation/qgsgridfilewriter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/analysis/interpolation/qgsgridfilewriter.cpp b/src/analysis/interpolation/qgsgridfilewriter.cpp index abd92e9f7be3..38bc26b429a2 100644 --- a/src/analysis/interpolation/qgsgridfilewriter.cpp +++ b/src/analysis/interpolation/qgsgridfilewriter.cpp @@ -64,6 +64,7 @@ int QgsGridFileWriter::writeFile( QgsFeedback *feedback ) double currentXValue; double interpolatedValue; + std::vector float32Row( mNumColumns ); const double step = mNumRows > 0 ? 100.0 / mNumRows : 1; for ( int row = 0; row < mNumRows; row++ ) { @@ -73,10 +74,8 @@ int QgsGridFileWriter::writeFile( QgsFeedback *feedback ) } currentXValue = mInterpolationExtent.xMinimum() + mCellSizeX / 2.0; //calculate value in the center of the cell - QgsRasterBlock block( Qgis::DataType::Float32, mNumColumns, 1 ); - std::vector float32Row( mNumColumns ); for ( int col = 0; col < mNumColumns; col++ ) { if ( mInterpolator->interpolatePoint( currentXValue, currentYValue, interpolatedValue, feedback ) == 0 )