QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgsvectorlayerprofilegenerator.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectorlayerprofilegenerator.h
3 ---------------
4 begin : March 2022
5 copyright : (C) 2022 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#ifndef QGSVECTORLAYERPROFILEGENERATOR_H
18#define QGSVECTORLAYERPROFILEGENERATOR_H
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
26#include "qgsmarkersymbol.h"
27#include "qgsfillsymbol.h"
28#include "qgslinesymbol.h"
29#include "qgsfeatureid.h"
30
31#include <memory>
32
34class QgsCurve;
35class QgsVectorLayer;
38class QgsGeos;
39class QgsLineString;
40class QgsPolygon;
42
43#define SIP_NO_FILE
44
45
54{
55 public:
56
57 struct Feature
58 {
65 };
66
67 QHash< QgsFeatureId, QVector< Feature > > features;
68 QPointer< QgsVectorLayer > mLayer;
69
71 bool respectLayerSymbology = true;
72 std::unique_ptr< QgsMarkerSymbol > mMarkerSymbol;
73 bool mShowMarkerSymbolInSurfacePlots = false;
74
75 QString type() const override;
76 QVector< QgsGeometry > asGeometries() const override;
77 QVector< QgsAbstractProfileResults::Feature > asFeatures( Qgis::ProfileExportType type, QgsFeedback *feedback = nullptr ) const override;
78 QgsProfileSnapResult snapPoint( const QgsProfilePoint &point, const QgsProfileSnapContext &context ) override;
79 QVector<QgsProfileIdentifyResults> identify( const QgsProfilePoint &point, const QgsProfileIdentifyContext &context ) override;
80 QVector<QgsProfileIdentifyResults> identify( const QgsDoubleRange &distanceRange, const QgsDoubleRange &elevationRange, const QgsProfileIdentifyContext &context ) override;
81 void renderResults( QgsProfileRenderContext &context ) override;
82 void copyPropertiesFromGenerator( const QgsAbstractProfileGenerator *generator ) override;
83
84 private:
85 void renderResultsAsIndividualFeatures( QgsProfileRenderContext &context );
86 void renderMarkersOverContinuousSurfacePlot( QgsProfileRenderContext &context );
87 QVector< QgsAbstractProfileResults::Feature > asIndividualFeatures( Qgis::ProfileExportType type, QgsFeedback *feedback = nullptr ) const;
88 QgsProfileSnapResult snapPointToIndividualFeatures( const QgsProfilePoint &point, const QgsProfileSnapContext &context );
89
90 void visitFeaturesAtPoint( const QgsProfilePoint &point, double maximumPointDistanceDelta, double maximumPointElevationDelta, double maximumSurfaceElevationDelta,
91 const std::function< void( QgsFeatureId, double delta, double distance, double elevation ) > &visitor, bool visitWithin );
92 void visitFeaturesInRange( const QgsDoubleRange &distanceRange, const QgsDoubleRange &elevationRange,
93 const std::function<void ( QgsFeatureId )> &visitor );
94};
95
96
105{
106
107 public:
108
113
115
116 QString sourceId() const override;
117 bool generateProfile( const QgsProfileGenerationContext &context = QgsProfileGenerationContext() ) override;
118 QgsAbstractProfileResults *takeResults() override;
119 QgsFeedback *feedback() const override;
120
121 private:
122
123 bool generateProfileForPoints();
124 bool generateProfileForLines();
125 bool generateProfileForPolygons();
126
127 void processIntersectionPoint( const QgsPoint *intersectionPoint, const QgsFeature &feature );
128 void processIntersectionCurve( const QgsLineString *intersectionCurve, const QgsFeature &feature );
129
130 QgsPoint interpolatePointOnTriangle( const QgsPolygon *triangle, double x, double y ) const;
131 void processTriangleIntersectForPoint( const QgsPolygon *triangle, const QgsPoint *intersect, QVector< QgsGeometry > &transformedParts, QVector< QgsGeometry > &crossSectionParts );
132 void processTriangleIntersectForLine( const QgsPolygon *triangle, const QgsLineString *intersect, QVector< QgsGeometry > &transformedParts, QVector< QgsGeometry > &crossSectionParts );
133 void processTriangleIntersectForPolygon( const QgsPolygon *triangle, const QgsPolygon *intersectionPolygon, QVector< QgsGeometry > &transformedParts, QVector< QgsGeometry > &crossSectionParts );
134
135 double terrainHeight( double x, double y );
136 double featureZToHeight( double x, double y, double z, double offset );
137
138 void clampAltitudes( QgsLineString *lineString, const QgsPoint &centroid, double offset );
139 bool clampAltitudes( QgsPolygon *polygon, double offset );
140
141 QString mId;
142 std::unique_ptr<QgsFeedback> mFeedback = nullptr;
143
144 std::unique_ptr< QgsCurve > mProfileCurve;
145 std::unique_ptr< QgsGeos > mProfileCurveEngine;
146
147 std::unique_ptr<QgsAbstractGeometry> mProfileBufferedCurve;
148 std::unique_ptr< QgsGeos > mProfileBufferedCurveEngine;
149
150 std::unique_ptr< QgsAbstractTerrainProvider > mTerrainProvider;
151
152 std::unique_ptr< QgsCurve > mTransformedCurve;
153 double mTolerance = 0;
154
155
158 QgsCoordinateTransformContext mTransformContext;
159 QgsRectangle mExtent;
160
161 std::unique_ptr< QgsVectorLayerFeatureSource > mSource;
162
163 double mOffset = 0;
164 double mScale = 1;
168 bool mExtrusionEnabled = false;
169 double mExtrusionHeight = 0;
170
171 QgsExpressionContext mExpressionContext;
172 QgsFields mFields;
173 QgsPropertyCollection mDataDefinedProperties;
174
176 QgsCoordinateTransform mLayerToTargetTransform;
177 QgsCoordinateTransform mTargetToTerrainProviderTransform;
178
179 std::unique_ptr< QgsVectorLayerProfileResults > mResults;
180
181 bool mRespectLayerSymbology = true;
182 std::unique_ptr< QgsMarkerSymbol > mProfileMarkerSymbol;
183 bool mShowMarkerSymbolInSurfacePlots = false;
184
185 // NOT for use in the background thread!
186 QPointer< QgsVectorLayer > mLayer;
187
189
190};
191
192#endif // QGSVECTORLAYERPROFILEGENERATOR_H
AltitudeClamping
Altitude clamping.
Definition: qgis.h:3238
@ Terrain
Elevation is clamped to terrain (final elevation = terrain elevation)
AltitudeBinding
Altitude binding.
Definition: qgis.h:3251
@ Centroid
Clamp just centroid of feature.
VectorProfileType
Types of elevation profiles to generate for vector sources.
Definition: qgis.h:3448
@ IndividualFeatures
Treat each feature as an individual object (eg buildings)
ProfileExportType
Types of export for elevation profiles.
Definition: qgis.h:3475
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition: qgis.h:182
@ Unknown
Unknown.
Abstract base class for objects which generate elevation profiles.
Abstract base class for storage of 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...
Abstract base class for storage of elevation profiles which represent a continuous surface (e....
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.
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.
Abstract base class for terrain providers.
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Class for doing transforms between two map coordinate systems.
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
QgsRange which stores a range of double values.
Definition: qgsrange.h:231
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
Container of fields for a vector layer.
Definition: qgsfields.h:45
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:162
Does vector analysis using the geos library and handles import, export, exception handling*.
Definition: qgsgeos.h:98
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:45
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
Polygon geometry type.
Definition: qgspolygon.h:33
Encapsulates the context in which an elevation profile is to be generated.
Encapsulates the context of identifying profile results.
Encapsulates a point on a distance-elevation profile.
Abstract base class for storage of elevation profiles.
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
Encapsulates the context of snapping a profile point.
Encapsulates results of snapping a profile point.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Partial snapshot of vector layer's state (only the members necessary for access to features)
Implementation of QgsAbstractProfileGenerator for vector layers.
~QgsVectorLayerProfileGenerator() override
Implementation of QgsAbstractProfileResults for vector layers.
std::unique_ptr< QgsMarkerSymbol > mMarkerSymbol
QHash< QgsFeatureId, QVector< Feature > > features
Represents a vector layer which manages a vector based data sets.
CORE_EXPORT QgsMeshVertex centroid(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns the centroid of the face.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28
QgsGeometry crossSectionGeometry
Cross section distance vs height geometry for feature.
QgsGeometry geometry
Feature's geometry with any terrain height adjustment and extrusion applied.