27#include <QPainterPath>
52 QVector<QgsGeometry> res;
62 QVector< QgsAbstractProfileResults::Feature > res;
65 QVector< double > currentLineX;
66 QVector< double > currentLineY;
67 QVector< double > currentLineZ;
79 if ( std::isnan( pointIt.value() ) )
81 if ( currentLineX.length() > 1 )
85 f.
geometry =
QgsGeometry( std::make_unique< QgsLineString >( currentLineX, currentLineY, currentLineZ ) );
94 std::unique_ptr< QgsPoint > curvePoint(
mProfileCurve->interpolatePoint( pointIt.key() ) );
95 currentLineX << curvePoint->x();
96 currentLineY << curvePoint->y();
97 currentLineZ << pointIt.value();
100 if ( currentLineX.length() > 1 )
104 f.
geometry =
QgsGeometry( std::make_unique< QgsLineString >( currentLineX, currentLineY, currentLineZ ) );
117 if ( std::isnan( pointIt.value() ) )
119 if ( currentLineX.length() > 1 )
123 f.
geometry =
QgsGeometry( std::make_unique< QgsLineString >( currentLineX, currentLineY ) );
126 currentLineX.clear();
127 currentLineY.clear();
131 currentLineX << pointIt.key();
132 currentLineY << pointIt.value();
134 if ( currentLineX.length() > 1 )
138 f.
geometry =
QgsGeometry( std::make_unique< QgsLineString >( currentLineX, currentLineY ) );
156 { QStringLiteral(
"distance" ), pointIt.key() },
157 { QStringLiteral(
"elevation" ), pointIt.value() }
159 std::unique_ptr< QgsPoint> point(
mProfileCurve->interpolatePoint( pointIt.key() ) );
161 point->setZ( pointIt.value() );
163 point->addZValue( pointIt.value() );
179 double prevDistance = std::numeric_limits< double >::max();
180 double prevElevation = 0;
186 const double dx = it.key() - prevDistance;
187 const double dy = it.value() - prevElevation;
188 const double snappedZ = ( dy / dx ) * ( point.
distance() - prevDistance ) + prevElevation;
197 prevDistance = it.key();
198 prevElevation = it.value();
206 std::optional< QgsProfileIdentifyResults > result;
208 double prevDistance = std::numeric_limits< double >::max();
209 double prevElevation = 0;
215 const double dx = it.key() - prevDistance;
216 const double dy = it.value() - prevElevation;
217 const double snappedZ = ( dy / dx ) * ( point.
distance() - prevDistance ) + prevElevation;
226 {QStringLiteral(
"distance" ), point.
distance() },
227 {QStringLiteral(
"elevation" ), snappedZ }
233 prevDistance = it.key();
234 prevElevation = it.value();
236 if ( result.has_value() )
250 painter->setBrush( Qt::NoBrush );
251 painter->setPen( Qt::NoPen );
258 const QRectF visibleRegion( minDistance,
minZ, maxDistance - minDistance,
maxZ -
minZ );
259 QPainterPath clipPath;
260 clipPath.addPolygon( context.
worldTransform().map( visibleRegion ) );
261 painter->setClipPath( clipPath, Qt::ClipOperation::IntersectClip );
272 double dataLimit = std::numeric_limits< double >::max();
275 if ( !std::isnan( pointIt.value() ) )
277 dataLimit = std::min( pointIt.value(), dataLimit );
288 double dataLimit = std::numeric_limits< double >::lowest();
291 if ( !std::isnan( pointIt.value() ) )
293 dataLimit = std::max( pointIt.value(), dataLimit );
303 double prevDistance,
double currentPartStartDistance )
305 if ( currentLine.length() > 1 )
314 currentLine.append( context.
worldTransform().map( QPointF( currentPartStartDistance,
minZ ) ) );
315 currentLine.append( currentLine.at( 0 ) );
320 currentLine.append( context.
worldTransform().map( QPointF( currentPartStartDistance,
maxZ ) ) );
321 currentLine.append( currentLine.at( 0 ) );
328 QPolygonF currentLine;
329 double prevDistance = std::numeric_limits< double >::quiet_NaN();
330 double currentPartStartDistance = 0;
333 if ( currentLine.empty() )
335 if ( std::isnan( pointIt.value() ) )
337 currentPartStartDistance = pointIt.key();
340 if ( std::isnan( pointIt.value() ) )
342 checkLine( currentLine, context,
minZ,
maxZ, prevDistance, currentPartStartDistance );
347 currentLine.append( context.
worldTransform().map( QPointF( pointIt.key(), pointIt.value() ) ) );
348 prevDistance = pointIt.key();
352 checkLine( currentLine, context,
minZ,
maxZ, prevDistance, currentPartStartDistance );
384 :
mProfileCurve( request.profileCurve() ? request.profileCurve()->clone() : nullptr )
ProfileExportType
Types of export for elevation profiles.
@ Profile2D
Export profiles as 2D profile lines, with elevation stored in exported geometry Y dimension and dista...
@ Features3D
Export profiles as 3D features, with elevation values stored in exported geometry Z values.
@ DistanceVsElevationTable
Export profiles as a table of sampled distance vs elevation values.
ProfileSurfaceSymbology
Surface symbology type for elevation profile plots.
@ Line
The elevation surface will be rendered using a line symbol.
@ FillBelow
The elevation surface will be rendered using a fill symbol below the surface level.
@ FillAbove
The elevation surface will be rendered using a fill symbol above the surface level.
Abstract base class for objects which generate elevation profiles.
virtual QString type() const =0
Returns the unique string identifier for the results type.
Abstract base class for objects which generate elevation profiles which represent a continuous surfac...
std::unique_ptr< QgsCurve > mProfileCurve
QgsLineSymbol * lineSymbol() const
Returns the line symbol to be used for rendering the results.
std::unique_ptr< QgsLineSymbol > mLineSymbol
Qgis::ProfileSurfaceSymbology symbology() const
Returns the symbology type for rendering the results.
void setElevationLimit(double limit)
Sets the elevation limit, which is used when symbology() is Qgis::ProfileSurfaceSymbology::FillBelow ...
QgsAbstractProfileSurfaceGenerator(const QgsProfileRequest &request)
Constructor for QgsAbstractProfileSurfaceGenerator.
Qgis::ProfileSurfaceSymbology mSymbology
double elevationLimit() const
Returns the elevation limit, which is used when symbology() is Qgis::ProfileSurfaceSymbology::FillBel...
QgsFillSymbol * fillSymbol() const
Returns the fill symbol to be used for rendering the results.
std::unique_ptr< QgsFillSymbol > mFillSymbol
~QgsAbstractProfileSurfaceGenerator() override
std::unique_ptr< QgsFillSymbol > mFillSymbol
QgsPointSequence mRawPoints
QMap< double, double > mDistanceToHeightMap
std::unique_ptr< QgsLineSymbol > mLineSymbol
Qgis::ProfileSurfaceSymbology symbology
QgsPointSequence sampledPoints() const override
Returns a list of sampled points, with their calculated elevation as the point z value.
void renderResults(QgsProfileRenderContext &context) override
Renders the results to the specified context.
void copyPropertiesFromGenerator(const QgsAbstractProfileGenerator *generator) override
Copies properties from specified generator to the results object.
std::unique_ptr< QgsCurve > mProfileCurve
QVector< QgsAbstractProfileResults::Feature > asFeatures(Qgis::ProfileExportType type, QgsFeedback *feedback=nullptr) const override
Returns a list of features representing the calculated elevation results.
QVector< QgsGeometry > asGeometries() const override
Returns a list of geometries representing the calculated elevation results.
QVector< QgsProfileIdentifyResults > identify(const QgsProfilePoint &point, const QgsProfileIdentifyContext &context) override
Identify results visible at the specified profile point.
QgsProfileSnapResult snapPoint(const QgsProfilePoint &point, const QgsProfileSnapContext &context) override
Snaps a point to the generated elevation profile.
QgsDoubleRange zRange() const override
Returns the range of the retrieved elevation values.
QMap< double, double > distanceToHeightMap() const override
Returns the map of distance (chainage) to height.
~QgsAbstractProfileSurfaceResults() override
QgsRange which stores a range of double values.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
bool isCanceled() const
Tells whether the operation has been canceled already.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
QgsFillSymbol * clone() const override
Returns a deep copy of this symbol.
A geometry is the spatial representation of a feature.
A line symbol type, for rendering LineString and MultiLineString geometries.
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
Point geometry type, with support for z-dimension and m-values.
Encapsulates the context of identifying profile results.
double maximumSurfaceElevationDelta
Maximum allowed snapping delta for the elevation values when identifying a continuous elevation surfa...
Stores identify results generated by a QgsAbstractProfileResults object.
Encapsulates a point on a distance-elevation profile.
double elevation() const
Returns the elevation of the point.
double distance() const
Returns the distance of the point.
Abstract base class for storage of elevation profiles.
const QTransform & worldTransform() const
Returns the transform from world coordinates to painter coordinates.
QgsDoubleRange elevationRange() const
Returns the range of elevations to include in the render.
QgsDoubleRange distanceRange() const
Returns the range of distances to include in the render.
QgsRenderContext & renderContext()
Returns a reference to the component QgsRenderContext.
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
Encapsulates the context of snapping a profile point.
double maximumSurfaceElevationDelta
Maximum allowed snapping delta for the elevation values when snapping to a continuous elevation surfa...
Encapsulates results of snapping a profile point.
QgsProfilePoint snappedPoint
Snapped point.
T lower() const
Returns the lower bound of the range.
T upper() const
Returns the upper bound of the range.
QPainter * painter()
Returns the destination QPainter for the render operation.
Scoped object for saving and restoring a QPainter object's state.
QVector< QgsPoint > QgsPointSequence
Encapsulates information about a feature exported from the profile results.
QString layerIdentifier
Identifier for grouping output features.
QVariantMap attributes
Exported attributes.
QgsGeometry geometry
Exported geometry.