28#include <QPainterPath>
31using namespace Qt::StringLiterals;
56 QVector<QgsGeometry> res;
66 QVector< QgsAbstractProfileResults::Feature > res;
69 QVector< double > currentLineX;
70 QVector< double > currentLineY;
71 QVector< double > currentLineZ;
83 if ( std::isnan( pointIt.value() ) )
85 if ( currentLineX.length() > 1 )
89 f.
geometry =
QgsGeometry( std::make_unique< QgsLineString >( currentLineX, currentLineY, currentLineZ ) );
98 std::unique_ptr< QgsPoint > curvePoint(
mProfileCurve->interpolatePoint( pointIt.key() ) );
99 currentLineX << curvePoint->x();
100 currentLineY << curvePoint->y();
101 currentLineZ << pointIt.value();
104 if ( currentLineX.length() > 1 )
108 f.
geometry =
QgsGeometry( std::make_unique< QgsLineString >( currentLineX, currentLineY, currentLineZ ) );
121 if ( std::isnan( pointIt.value() ) )
123 if ( currentLineX.length() > 1 )
127 f.
geometry =
QgsGeometry( std::make_unique< QgsLineString >( currentLineX, currentLineY ) );
130 currentLineX.clear();
131 currentLineY.clear();
135 currentLineX << pointIt.key();
136 currentLineY << pointIt.value();
138 if ( currentLineX.length() > 1 )
142 f.
geometry =
QgsGeometry( std::make_unique< QgsLineString >( currentLineX, currentLineY ) );
158 f.
attributes = { { u
"distance"_s, pointIt.key() }, { u
"elevation"_s, 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 prevDistance = it.key();
227 prevElevation = it.value();
229 if ( result.has_value() )
243 painter->setBrush( Qt::NoBrush );
244 painter->setPen( Qt::NoPen );
251 const QRectF visibleRegion( minDistance,
minZ, maxDistance - minDistance,
maxZ -
minZ );
252 QPainterPath clipPath;
253 clipPath.addPolygon( context.
worldTransform().map( visibleRegion ) );
254 painter->setClipPath( clipPath, Qt::ClipOperation::IntersectClip );
265 double dataLimit = std::numeric_limits< double >::max();
268 if ( !std::isnan( pointIt.value() ) )
270 dataLimit = std::min( pointIt.value(), dataLimit );
281 double dataLimit = std::numeric_limits< double >::lowest();
284 if ( !std::isnan( pointIt.value() ) )
286 dataLimit = std::max( pointIt.value(), dataLimit );
295 auto checkLine = [
this]( QPolygonF ¤tLine,
QgsProfileRenderContext &context,
double minZ,
double maxZ,
double prevDistance,
double currentPartStartDistance ) {
296 if ( currentLine.length() > 1 )
305 currentLine.append( context.
worldTransform().map( QPointF( currentPartStartDistance,
minZ ) ) );
306 currentLine.append( currentLine.at( 0 ) );
311 currentLine.append( context.
worldTransform().map( QPointF( currentPartStartDistance,
maxZ ) ) );
312 currentLine.append( currentLine.at( 0 ) );
319 QPolygonF currentLine;
320 double prevDistance = std::numeric_limits< double >::quiet_NaN();
321 double currentPartStartDistance = 0;
324 if ( currentLine.empty() )
326 if ( std::isnan( pointIt.value() ) )
328 currentPartStartDistance = pointIt.key();
331 if ( std::isnan( pointIt.value() ) )
333 checkLine( currentLine, context,
minZ,
maxZ, prevDistance, currentPartStartDistance );
338 currentLine.append( context.
worldTransform().map( QPointF( pointIt.key(), pointIt.value() ) ) );
339 prevDistance = pointIt.key();
343 checkLine( currentLine, context,
minZ,
maxZ, prevDistance, currentPartStartDistance );
375 :
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.