diff --git a/src/core/elevation/qgsabstractprofilesurfacegenerator.cpp b/src/core/elevation/qgsabstractprofilesurfacegenerator.cpp index ef921bcba7eb6..9ec3a9f9b0b49 100644 --- a/src/core/elevation/qgsabstractprofilesurfacegenerator.cpp +++ b/src/core/elevation/qgsabstractprofilesurfacegenerator.cpp @@ -325,30 +325,26 @@ void QgsAbstractProfileSurfaceResults::renderResults( QgsProfileRenderContext &c QPolygonF currentLine; double prevDistance = std::numeric_limits< double >::quiet_NaN(); - double prevHeight = std::numeric_limits< double >::quiet_NaN(); double currentPartStartDistance = 0; for ( auto pointIt = mDistanceToHeightMap.constBegin(); pointIt != mDistanceToHeightMap.constEnd(); ++pointIt ) { - if ( std::isnan( prevDistance ) ) + if ( currentLine.empty() ) // new part { + if ( std::isnan( pointIt.value() ) ) // skip emptiness + continue; currentPartStartDistance = pointIt.key(); } - else if ( currentLine.empty() ) - { - currentPartStartDistance = prevDistance; - currentLine.append( context.worldTransform().map( QPointF( prevDistance, prevHeight ) ) ); - } if ( std::isnan( pointIt.value() ) ) { checkLine( currentLine, context, minZ, maxZ, prevDistance, currentPartStartDistance ); currentLine.clear(); - continue; } - - currentLine.append( context.worldTransform().map( QPointF( pointIt.key(), pointIt.value() ) ) ); - prevDistance = pointIt.key(); - prevHeight = pointIt.value(); + else + { + currentLine.append( context.worldTransform().map( QPointF( pointIt.key(), pointIt.value() ) ) ); + prevDistance = pointIt.key(); + } } checkLine( currentLine, context, minZ, maxZ, prevDistance, currentPartStartDistance ); diff --git a/tests/src/python/test_qgsvectorlayerprofilegenerator.py b/tests/src/python/test_qgsvectorlayerprofilegenerator.py index 339965de320dc..5b7de047d851c 100644 --- a/tests/src/python/test_qgsvectorlayerprofilegenerator.py +++ b/tests/src/python/test_qgsvectorlayerprofilegenerator.py @@ -1783,6 +1783,54 @@ def testRenderProfileAsSurfaceLinesWithMarkers(self): res = plot_renderer.renderToImage(400, 400, 0, curve.length(), 0, 14) self.assertTrue(self.image_check('vector_lines_as_surface_with_markers', 'vector_lines_as_surface_with_markers', res)) + def testRenderProfileAsLineWithHoledDtm(self): + rl = QgsRasterLayer(os.path.join(unitTestDataPath(), '3d', 'dtm_with_holes.tif'), 'DTM') + self.assertTrue(rl.isValid()) + + rl.elevationProperties().setEnabled(True) + rl.elevationProperties().setProfileSymbology(Qgis.ProfileSurfaceSymbology.Line) + line_symbol = QgsLineSymbol.createSimple({'color': '#ff00ff', 'width': '0.8'}) + rl.elevationProperties().setProfileLineSymbol(line_symbol) + + curve = QgsLineString() + curve.fromWkt('LineString (320900 129000, 322900 129000)') + req = QgsProfileRequest(curve) + req.setTransformContext(self.create_transform_context()) + + req.setCrs(QgsCoordinateReferenceSystem()) + + plot_renderer = QgsProfilePlotRenderer([rl], req) + plot_renderer.startGeneration() + plot_renderer.waitForFinished() + + res = plot_renderer.renderToImage(1600, 800, 0, curve.length(), 0, 90) + self.assertTrue(self.image_check('vector_lines_as_line_with_holed_dtm', 'vector_lines_as_line_with_holed_dtm', res)) + + def testRenderProfileAsSurfaceFillBelowWithHoledDtm(self): + rl = QgsRasterLayer(os.path.join(unitTestDataPath(), '3d', 'dtm_with_holes.tif'), 'DTM') + self.assertTrue(rl.isValid()) + + rl.elevationProperties().setEnabled(True) + rl.elevationProperties().setProfileSymbology(Qgis.ProfileSurfaceSymbology.FillBelow) + fill_symbol = QgsFillSymbol.createSimple({'color': '#ff00ff', 'outline_style': 'no'}) + rl.elevationProperties().setProfileFillSymbol(fill_symbol) + line_symbol = QgsLineSymbol.createSimple({'color': '#ff00ff', 'width': '0.8'}) + rl.elevationProperties().setProfileLineSymbol(line_symbol) + + curve = QgsLineString() + curve.fromWkt('LineString (320900 129000, 322900 129000)') + req = QgsProfileRequest(curve) + req.setTransformContext(self.create_transform_context()) + + req.setCrs(QgsCoordinateReferenceSystem()) + + plot_renderer = QgsProfilePlotRenderer([rl], req) + plot_renderer.startGeneration() + plot_renderer.waitForFinished() + + res = plot_renderer.renderToImage(1600, 800, 0, curve.length(), 0, 90) + self.assertTrue(self.image_check('vector_lines_as_fill_below_surface_with_holed_dtm', 'vector_lines_as_fill_below_surface_with_holed_dtm', res)) + def testRenderProfileAsSurfaceFillBelow(self): vl = QgsVectorLayer('LineStringZ?crs=EPSG:27700', 'lines', 'memory') vl.setCrs(QgsCoordinateReferenceSystem()) diff --git a/tests/testdata/3d/dtm_with_holes.tif b/tests/testdata/3d/dtm_with_holes.tif new file mode 100644 index 0000000000000..fe501eb6a3d0c Binary files /dev/null and b/tests/testdata/3d/dtm_with_holes.tif differ diff --git a/tests/testdata/control_images/profile_chart/expected_vector_lines_as_fill_above_surface_limit_tolerance/expected_vector_lines_as_fill_above_surface_limit_tolerance.png b/tests/testdata/control_images/profile_chart/expected_vector_lines_as_fill_above_surface_limit_tolerance/expected_vector_lines_as_fill_above_surface_limit_tolerance.png index 77cd2db92a447..0d29c7456d9d5 100644 Binary files a/tests/testdata/control_images/profile_chart/expected_vector_lines_as_fill_above_surface_limit_tolerance/expected_vector_lines_as_fill_above_surface_limit_tolerance.png and b/tests/testdata/control_images/profile_chart/expected_vector_lines_as_fill_above_surface_limit_tolerance/expected_vector_lines_as_fill_above_surface_limit_tolerance.png differ diff --git a/tests/testdata/control_images/profile_chart/expected_vector_lines_as_fill_below_surface_with_holed_dtm/expected_vector_lines_as_fill_below_surface_with_holed_dtm.png b/tests/testdata/control_images/profile_chart/expected_vector_lines_as_fill_below_surface_with_holed_dtm/expected_vector_lines_as_fill_below_surface_with_holed_dtm.png new file mode 100644 index 0000000000000..9c825d3dbb260 Binary files /dev/null and b/tests/testdata/control_images/profile_chart/expected_vector_lines_as_fill_below_surface_with_holed_dtm/expected_vector_lines_as_fill_below_surface_with_holed_dtm.png differ diff --git a/tests/testdata/control_images/profile_chart/expected_vector_lines_as_line_with_holed_dtm/expected_vector_lines_as_line_with_holed_dtm.png b/tests/testdata/control_images/profile_chart/expected_vector_lines_as_line_with_holed_dtm/expected_vector_lines_as_line_with_holed_dtm.png new file mode 100644 index 0000000000000..73ef660b49424 Binary files /dev/null and b/tests/testdata/control_images/profile_chart/expected_vector_lines_as_line_with_holed_dtm/expected_vector_lines_as_line_with_holed_dtm.png differ