24#include <QPainterPath>
50 QVector<QgsGeometry> res;
60 QVector< QgsAbstractProfileResults::Feature > res;
63 QVector< double > currentLineX;
64 QVector< double > currentLineY;
65 QVector< double > currentLineZ;
77 if ( std::isnan( pointIt.value() ) )
79 if ( currentLineX.length() > 1 )
83 f.
geometry =
QgsGeometry( std::make_unique< QgsLineString >( currentLineX, currentLineY, currentLineZ ) );
92 std::unique_ptr< QgsPoint > curvePoint(
mProfileCurve->interpolatePoint( pointIt.key() ) );
93 currentLineX << curvePoint->x();
94 currentLineY << curvePoint->y();
95 currentLineZ << pointIt.value();
98 if ( currentLineX.length() > 1 )
102 f.
geometry =
QgsGeometry( std::make_unique< QgsLineString >( currentLineX, currentLineY, currentLineZ ) );
115 if ( std::isnan( pointIt.value() ) )
117 if ( currentLineX.length() > 1 )
121 f.
geometry =
QgsGeometry( std::make_unique< QgsLineString >( currentLineX, currentLineY ) );
124 currentLineX.clear();
125 currentLineY.clear();
129 currentLineX << pointIt.key();
130 currentLineY << pointIt.value();
132 if ( currentLineX.length() > 1 )
136 f.
geometry =
QgsGeometry( std::make_unique< QgsLineString >( currentLineX, currentLineY ) );
154 { QStringLiteral(
"distance" ), pointIt.key() },
155 { QStringLiteral(
"elevation" ), pointIt.value() }
157 std::unique_ptr< QgsPoint> point(
mProfileCurve->interpolatePoint( pointIt.key() ) );
159 point->setZ( pointIt.value() );
161 point->addZValue( pointIt.value() );
177 double prevDistance = std::numeric_limits< double >::max();
178 double prevElevation = 0;
184 const double dx = it.key() - prevDistance;
185 const double dy = it.value() - prevElevation;
186 const double snappedZ = ( dy / dx ) * ( point.
distance() - prevDistance ) + prevElevation;
195 prevDistance = it.key();
196 prevElevation = it.value();
204 std::optional< QgsProfileIdentifyResults > result;
206 double prevDistance = std::numeric_limits< double >::max();
207 double prevElevation = 0;
213 const double dx = it.key() - prevDistance;
214 const double dy = it.value() - prevElevation;
215 const double snappedZ = ( dy / dx ) * ( point.
distance() - prevDistance ) + prevElevation;
224 {QStringLiteral(
"distance" ), point.
distance() },
225 {QStringLiteral(
"elevation" ), snappedZ }
231 prevDistance = it.key();
232 prevElevation = it.value();
234 if ( result.has_value() )
235 return {result.value()};
248 painter->setBrush( Qt::NoBrush );
249 painter->setPen( Qt::NoPen );
256 const QRectF visibleRegion( minDistance,
minZ, maxDistance - minDistance,
maxZ -
minZ );
257 QPainterPath clipPath;
258 clipPath.addPolygon( context.
worldTransform().map( visibleRegion ) );
259 painter->setClipPath( clipPath, Qt::ClipOperation::IntersectClip );
270 double dataLimit = std::numeric_limits< double >::max();
273 if ( !std::isnan( pointIt.value() ) )
275 dataLimit = std::min( pointIt.value(), dataLimit );
286 double dataLimit = std::numeric_limits< double >::lowest();
289 if ( !std::isnan( pointIt.value() ) )
291 dataLimit = std::max( pointIt.value(), dataLimit );
301 double prevDistance,
double currentPartStartDistance )
303 if ( currentLine.length() > 1 )
312 currentLine.append( context.
worldTransform().map( QPointF( currentPartStartDistance,
minZ ) ) );
313 currentLine.append( currentLine.at( 0 ) );
318 currentLine.append( context.
worldTransform().map( QPointF( currentPartStartDistance,
maxZ ) ) );
319 currentLine.append( currentLine.at( 0 ) );
326 QPolygonF currentLine;
327 double prevDistance = std::numeric_limits< double >::quiet_NaN();
328 double currentPartStartDistance = 0;
331 if ( currentLine.empty() )
333 if ( std::isnan( pointIt.value() ) )
335 currentPartStartDistance = pointIt.key();
338 if ( std::isnan( pointIt.value() ) )
340 checkLine( currentLine, context,
minZ,
maxZ, prevDistance, currentPartStartDistance );
345 currentLine.append( context.
worldTransform().map( QPointF( pointIt.key(), pointIt.value() ) ) );
346 prevDistance = pointIt.key();
350 checkLine( currentLine, context,
minZ,
maxZ, prevDistance, currentPartStartDistance );
382 : 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.