diff --git a/tests/src/python/test_analysis_interpolation.py b/tests/src/python/test_analysis_interpolation.py index 155765471859b..2b5a451038e9b 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 0000000000000..4f46319640b89 --- /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 0000000000000..5fbc831e74334 --- /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"]]