QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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"
25 #include "qgscoordinatetransform.h"
26 #include "qgsmarkersymbol.h"
27 #include "qgsfillsymbol.h"
28 #include "qgslinesymbol.h"
29 #include "qgsfeatureid.h"
30 
31 #include <memory>
32 
33 class QgsProfileRequest;
34 class QgsCurve;
35 class QgsVectorLayer;
38 class QgsGeos;
39 class QgsLineString;
40 class 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  QgsProfileSnapResult snapPoint( const QgsProfilePoint &point, const QgsProfileSnapContext &context ) override;
78  QVector<QgsProfileIdentifyResults> identify( const QgsProfilePoint &point, const QgsProfileIdentifyContext &context ) override;
79  QVector<QgsProfileIdentifyResults> identify( const QgsDoubleRange &distanceRange, const QgsDoubleRange &elevationRange, const QgsProfileIdentifyContext &context ) override;
80  void renderResults( QgsProfileRenderContext &context ) override;
81  void copyPropertiesFromGenerator( const QgsAbstractProfileGenerator *generator ) override;
82 
83  private:
84  void renderResultsAsIndividualFeatures( QgsProfileRenderContext &context );
85  void renderMarkersOverContinuousSurfacePlot( QgsProfileRenderContext &context );
86  QgsProfileSnapResult snapPointToIndividualFeatures( const QgsProfilePoint &point, const QgsProfileSnapContext &context );
87 
88  void visitFeaturesAtPoint( const QgsProfilePoint &point, double maximumPointDistanceDelta, double maximumPointElevationDelta, double maximumSurfaceElevationDelta,
89  const std::function< void( QgsFeatureId, double delta, double distance, double elevation ) > &visitor, bool visitWithin );
90  void visitFeaturesInRange( const QgsDoubleRange &distanceRange, const QgsDoubleRange &elevationRange,
91  const std::function<void ( QgsFeatureId )> &visitor );
92 };
93 
94 
103 {
104 
105  public:
106 
111 
112  ~QgsVectorLayerProfileGenerator() override;
113 
114  QString sourceId() const override;
115  bool generateProfile( const QgsProfileGenerationContext &context = QgsProfileGenerationContext() ) override;
117  QgsFeedback *feedback() const override;
118 
119  private:
120 
121  bool generateProfileForPoints();
122  bool generateProfileForLines();
123  bool generateProfileForPolygons();
124 
125  double terrainHeight( double x, double y );
126  double featureZToHeight( double x, double y, double z, double offset );
127 
128  void clampAltitudes( QgsLineString *lineString, const QgsPoint &centroid, double offset );
129  bool clampAltitudes( QgsPolygon *polygon, double offset );
130 
131  QString mId;
132  std::unique_ptr<QgsFeedback> mFeedback = nullptr;
133 
134  std::unique_ptr< QgsCurve > mProfileCurve;
135  std::unique_ptr< QgsGeos > mProfileCurveEngine;
136 
137  std::unique_ptr< QgsAbstractTerrainProvider > mTerrainProvider;
138 
139  std::unique_ptr< QgsCurve > mTransformedCurve;
140  double mTolerance = 0;
141 
142 
143  QgsCoordinateReferenceSystem mSourceCrs;
144  QgsCoordinateReferenceSystem mTargetCrs;
145  QgsCoordinateTransformContext mTransformContext;
146  QgsRectangle mExtent;
147 
148  std::unique_ptr< QgsVectorLayerFeatureSource > mSource;
149 
150  double mOffset = 0;
151  double mScale = 1;
155  bool mExtrusionEnabled = false;
156  double mExtrusionHeight = 0;
157 
158  QgsExpressionContext mExpressionContext;
159  QgsFields mFields;
160  QgsPropertyCollection mDataDefinedProperties;
161 
163  QgsCoordinateTransform mLayerToTargetTransform;
164  QgsCoordinateTransform mTargetToTerrainProviderTransform;
165 
166  std::unique_ptr< QgsVectorLayerProfileResults > mResults;
167 
168  bool mRespectLayerSymbology = true;
169  std::unique_ptr< QgsMarkerSymbol > mProfileMarkerSymbol;
170  bool mShowMarkerSymbolInSurfacePlots = false;
171 
172  // NOT for use in the background thread!
173  QPointer< QgsVectorLayer > mLayer;
174 
176 
177 };
178 
179 #endif // QGSVECTORLAYERPROFILEGENERATOR_H
QgsProfileIdentifyContext
Encapsulates the context of identifying profile results.
Definition: qgsabstractprofilegenerator.h:125
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
Qgis::AltitudeClamping::Terrain
@ Terrain
Elevation is clamped to terrain (final elevation = terrain elevation)
QgsAbstractProfileSurfaceResults::copyPropertiesFromGenerator
void copyPropertiesFromGenerator(const QgsAbstractProfileGenerator *generator) override
Copies properties from specified generator to the results object.
Definition: qgsabstractprofilesurfacegenerator.cpp:217
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
QgsPolygon
Polygon geometry type.
Definition: qgspolygon.h:33
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:48
Qgis::AltitudeBinding::Centroid
@ Centroid
Clamp just centroid of feature.
QgsAbstractProfileSurfaceResults::renderResults
void renderResults(QgsProfileRenderContext &context) override
Renders the results to the specified context.
Definition: qgsabstractprofilesurfacegenerator.cpp:124
QgsVectorLayerProfileResults::mLayer
QPointer< QgsVectorLayer > mLayer
Definition: qgsvectorlayerprofilegenerator.h:68
QgsMeshUtils::centroid
CORE_EXPORT QgsMeshVertex centroid(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns the centroid of the face.
Definition: qgstriangularmesh.cpp:955
QgsProfileSnapResult
Encapsulates results of snapping a profile point.
Definition: qgsprofilesnapping.h:56
qgscoordinatetransformcontext.h
qgsabstractprofilesurfacegenerator.h
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
QgsAbstractProfileGenerator
Abstract base class for objects which generate elevation profiles.
Definition: qgsabstractprofilegenerator.h:392
QgsProfileRenderContext
Abstract base class for storage of elevation profiles.
Definition: qgsabstractprofilegenerator.h:40
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
qgsfeatureid.h
QgsVectorLayerProfileResults::mMarkerSymbol
std::unique_ptr< QgsMarkerSymbol > mMarkerSymbol
Definition: qgsvectorlayerprofilegenerator.h:72
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
QgsProfileSnapContext
Encapsulates the context of snapping a profile point.
Definition: qgsprofilesnapping.h:30
QgsVectorLayerProfileResults::Feature::geometry
QgsGeometry geometry
Feature's geometry with any terrain height adjustment and extrusion applied.
Definition: qgsvectorlayerprofilegenerator.h:62
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsProfilePoint
Encapsulates a point on a distance-elevation profile.
Definition: qgsprofilepoint.h:30
QgsProfileGenerationContext
Encapsulates the context in which an elevation profile is to be generated.
Definition: qgsabstractprofilegenerator.h:262
QgsVectorLayerProfileResults::Feature
Definition: qgsvectorlayerprofilegenerator.h:57
QgsAbstractProfileSurfaceResults::asGeometries
QVector< QgsGeometry > asGeometries() const override
Returns a list of geometries representing the calculated elevation results.
Definition: qgsabstractprofilesurfacegenerator.cpp:46
QgsAbstractProfileSurfaceResults
Abstract base class for storage of elevation profiles which represent a continuous surface (e....
Definition: qgsabstractprofilesurfacegenerator.h:37
Qgis::AltitudeBinding
AltitudeBinding
Altitude binding.
Definition: qgis.h:1770
QgsVectorLayerProfileResults
Implementation of QgsAbstractProfileResults for vector layers.
Definition: qgsvectorlayerprofilegenerator.h:53
QgsAbstractProfileSurfaceResults::snapPoint
QgsProfileSnapResult snapPoint(const QgsProfilePoint &point, const QgsProfileSnapContext &context) override
Snaps a point to the generated elevation profile.
Definition: qgsabstractprofilesurfacegenerator.cpp:56
QgsWkbTypes::Unknown
@ Unknown
Definition: qgswkbtypes.h:71
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsAbstractProfileGenerator::feedback
virtual QgsFeedback * feedback() const =0
Access to feedback object of the generator (may be nullptr)
QgsGeos
Does vector analysis using the geos library and handles import, export, exception handling*.
Definition: qgsgeos.h:103
Qgis::VectorProfileType::IndividualFeatures
@ IndividualFeatures
Treat each feature as an individual object (eg buildings)
qgis_sip.h
Qgis::VectorProfileType
VectorProfileType
Types of elevation profiles to generate for vector sources.
Definition: qgis.h:1861
QgsProfileRequest
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
Definition: qgsprofilerequest.h:37
qgscoordinatetransform.h
QgsAbstractProfileSurfaceResults::identify
QVector< QgsProfileIdentifyResults > identify(const QgsProfilePoint &point, const QgsProfileIdentifyContext &context) override
Identify results visible at the specified profile point.
Definition: qgsabstractprofilesurfacegenerator.cpp:85
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsAbstractProfileSurfaceGenerator
Abstract base class for objects which generate elevation profiles which represent a continuous surfac...
Definition: qgsabstractprofilesurfacegenerator.h:69
QgsVectorLayerProfileResults::Feature::crossSectionGeometry
QgsGeometry crossSectionGeometry
Cross section distance vs height geometry for feature.
Definition: qgsvectorlayerprofilegenerator.h:64
QgsVectorLayerProfileGenerator
Implementation of QgsAbstractProfileGenerator for vector layers.
Definition: qgsvectorlayerprofilegenerator.h:102
QgsVectorLayerProfileResults::Feature::featureId
QgsFeatureId featureId
Original feature ID.
Definition: qgsvectorlayerprofilegenerator.h:60
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsDoubleRange
QgsRange which stores a range of double values.
Definition: qgsrange.h:202
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
qgsmarkersymbol.h
QgsVectorLayerFeatureSource
Partial snapshot of vector layer's state (only the members necessary for access to features)
Definition: qgsvectorlayerfeatureiterator.h:52
QgsVectorLayerProfileResults::features
QHash< QgsFeatureId, QVector< Feature > > features
Definition: qgsvectorlayerprofilegenerator.h:67
QgsAbstractProfileResults::type
virtual QString type() const =0
Returns the unique string identifier for the results type.
QgsAbstractProfileResults
Abstract base class for storage of elevation profiles.
Definition: qgsabstractprofilegenerator.h:193
QgsAbstractTerrainProvider
Abstract base class for terrain providers.
Definition: qgsterrainprovider.h:40
QgsAbstractProfileGenerator::takeResults
virtual QgsAbstractProfileResults * takeResults()=0
Takes results from the generator.
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:57
Qgis::AltitudeClamping
AltitudeClamping
Altitude clamping.
Definition: qgis.h:1757
QgsAbstractProfileGenerator::sourceId
virtual QString sourceId() const =0
Returns a unique identifier representing the source of the profile.
qgsfillsymbol.h
qgscoordinatereferencesystem.h
qgslinesymbol.h
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28
QgsAbstractProfileGenerator::generateProfile
virtual bool generateProfile(const QgsProfileGenerationContext &context=QgsProfileGenerationContext())=0
Generate the profile (based on data stored in the class).