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 committed Oct 20, 2023
1 parent 9f985ce commit eac6490
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
20 changes: 6 additions & 14 deletions src/core/elevation/qgsabstractprofilesurfacegenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,34 +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;
}

if ( currentLine.length() < 1 )
else
{
currentPartStartDistance = pointIt.key();
currentLine.append( context.worldTransform().map( QPointF( pointIt.key(), pointIt.value() ) ) );
prevDistance = pointIt.key();
}
currentLine.append( context.worldTransform().map( QPointF( pointIt.key(), pointIt.value() ) ) );
prevDistance = pointIt.key();
prevHeight = pointIt.value();
}

checkLine( currentLine, context, minZ, maxZ, prevDistance, currentPartStartDistance );
Expand Down
28 changes: 25 additions & 3 deletions tests/src/python/test_qgsvectorlayerprofilegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1741,8 +1741,31 @@ 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.tif'), 'DTM')
rl = QgsRasterLayer(os.path.join(unitTestDataPath(), '3d', 'dtm_with_holes.tif'), 'DTM')
self.assertTrue(rl.isValid())

rl.elevationProperties().setEnabled(True)
Expand All @@ -1753,8 +1776,7 @@ def testRenderProfileAsSurfaceFillBelowWithHoledDtm(self):
rl.elevationProperties().setProfileLineSymbol(line_symbol)

curve = QgsLineString()
curve.fromWkt(
'LineString (322900 129000, 320900 129000)')
curve.fromWkt('LineString (320900 129000, 322900 129000)')
req = QgsProfileRequest(curve)
req.setTransformContext(self.create_transform_context())

Expand Down
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 eac6490

Please sign in to comment.