Skip to content

Commit

Permalink
fix(profileGenerator): refix qgis#54422 and simplify algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitdm-oslandia authored and ptitjano committed Jan 26, 2024
1 parent a00586c commit 745f404
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/core/elevation/qgsabstractprofilesurfacegenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
48 changes: 48 additions & 0 deletions tests/src/python/test_qgsvectorlayerprofilegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Binary file added tests/testdata/3d/dtm_with_holes.tif
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 745f404

Please sign in to comment.