QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsterrainprovider.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsterrainprovider.h
3  ---------------
4  begin : February 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 QGSTERRAINPROVIDER_H
18 #define QGSTERRAINPROVIDER_H
19 
20 #include "qgis_core.h"
21 #include "qgsrange.h"
22 #include "qgsunittypes.h"
23 #include "qgsmaplayerref.h"
24 #include "qgsrasterlayer.h"
25 #include "qgsmeshlayer.h"
26 #include "qgstriangularmesh.h"
27 
28 #include <QObject>
29 
30 class QDomElement;
32 class QDomDocument;
33 
40 class CORE_EXPORT QgsAbstractTerrainProvider
41 {
42 
43 #ifdef SIP_RUN
45  if ( sipCpp->type().compare( QLatin1String( "flat" ) ) == 0 )
46  {
47  sipType = sipType_QgsFlatTerrainProvider;
48  }
49  else if ( sipCpp->type().compare( QLatin1String( "raster" ) ) == 0 )
50  {
51  sipType = sipType_QgsRasterDemTerrainProvider;
52  }
53  else if ( sipCpp->type().compare( QLatin1String( "mesh" ) ) == 0 )
54  {
55  sipType = sipType_QgsMeshTerrainProvider;
56  }
57  else
58  {
59  sipType = 0;
60  }
61  SIP_END
62 #endif
63 
64  public:
65 
66  virtual ~QgsAbstractTerrainProvider();
67 
71  QgsAbstractTerrainProvider &operator=( const QgsAbstractTerrainProvider &other ) = delete;
72 
76  virtual bool equals( const QgsAbstractTerrainProvider *other ) const = 0;
77 
81  virtual void resolveReferences( const QgsProject *project );
82 
87  virtual bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) = 0;
88 
93  virtual QDomElement writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const = 0;
94 
98  virtual QString type() const = 0;
99 
105  virtual QgsAbstractTerrainProvider *clone() const = 0 SIP_FACTORY;
106 
113  virtual void prepare() = 0 SIP_FACTORY;
114 
118  virtual QgsCoordinateReferenceSystem crs() const = 0;
119 
125  virtual double heightAt( double x, double y ) const = 0;
126 
133  double scale() const { return mScale; }
134 
141  void setScale( double scale ) { mScale = scale; }
142 
149  double offset() const { return mOffset; }
150 
157  void setOffset( double offset ) { mOffset = offset; }
158 
159  protected:
160 
164  QgsAbstractTerrainProvider() = default;
165 
166 #ifndef SIP_RUN
167 
172 #endif
173 
177  void writeCommonProperties( QDomElement &element, const QgsReadWriteContext &context ) const;
178 
182  void readCommonProperties( const QDomElement &element, const QgsReadWriteContext &context );
183 
185  double mScale = 1.0;
186 
188  double mOffset = 0.0;
189 
190  private:
191 
192 #ifdef SIP_RUN
194 #endif
195 
196 };
197 
198 
206 {
207  public:
208 
212  QgsFlatTerrainProvider() = default;
213 
214  QString type() const override;
215  bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) override;
216  QDomElement writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const override;
217  QgsCoordinateReferenceSystem crs() const override;
218  double heightAt( double x, double y ) const override;
219  QgsFlatTerrainProvider *clone() const override SIP_FACTORY;
220  void prepare() override;
221  bool equals( const QgsAbstractTerrainProvider *other ) const override;
222 };
223 
231 {
232  public:
233 
237  QgsRasterDemTerrainProvider() = default;
238 
239 #ifndef SIP_RUN
240  const QgsRasterDemTerrainProvider *operator=( const QgsRasterDemTerrainProvider &other ) = delete;
242 #endif
243 
244  QString type() const override;
245  void resolveReferences( const QgsProject *project ) override;
246  bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) override;
247  QDomElement writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const override;
248  QgsCoordinateReferenceSystem crs() const override;
249  double heightAt( double x, double y ) const override;
251  bool equals( const QgsAbstractTerrainProvider *other ) const override;
252  void prepare() override;
253 
259  void setLayer( QgsRasterLayer *layer );
260 
266  QgsRasterLayer *layer() const;
267 
268 
269  private:
271 
272  _LayerRef<QgsRasterLayer> mRasterLayer;
273  std::unique_ptr< QgsRasterDataProvider > mRasterProvider;
274 
275 };
276 
277 
285 {
286  public:
287 
291  QgsMeshTerrainProvider() = default;
292 
293 #ifndef SIP_RUN
294  const QgsMeshTerrainProvider *operator=( const QgsMeshTerrainProvider &other ) = delete;
296 #endif
297 
298  QString type() const override;
299  void resolveReferences( const QgsProject *project ) override;
300  bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) override;
301  QDomElement writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const override;
302  QgsCoordinateReferenceSystem crs() const override;
303  double heightAt( double x, double y ) const override;
304  QgsMeshTerrainProvider *clone() const override SIP_FACTORY;
305  bool equals( const QgsAbstractTerrainProvider *other ) const override;
306  void prepare() override;
307 
313  void setLayer( QgsMeshLayer *layer );
314 
320  QgsMeshLayer *layer() const;
321 
322  private:
324 
325  _LayerRef<QgsMeshLayer> mMeshLayer;
326  QgsTriangularMesh mTriangularMesh;
327 };
328 
329 #endif // QGSTERRAINPROVIDER_H
QgsAbstractTerrainProvider::setScale
void setScale(double scale)
Sets the vertical scale factor, which can be used to exaggerate vertical heights.
Definition: qgsterrainprovider.h:141
qgsrasterlayer.h
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsAbstractTerrainProvider::clone
virtual QgsAbstractTerrainProvider * clone() const =0
Creates a clone of the provider and returns the new object.
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
qgsunittypes.h
qgsrange.h
QgsAbstractTerrainProvider::readXml
virtual bool readXml(const QDomElement &element, const QgsReadWriteContext &context)=0
Reads the terrain provider state from a DOM element.
QgsMeshTerrainProvider
A terrain provider that uses the Z values of a mesh layer to build a terrain surface.
Definition: qgsterrainprovider.h:284
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
qgstriangularmesh.h
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
QgsAbstractTerrainProvider::type
virtual QString type() const =0
Returns the unique type ID string for the provider.
QgsAbstractTerrainProvider::prepare
virtual void prepare()=0
Called on the main thread prior to accessing the provider from a background thread.
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:98
QgsAbstractTerrainProvider::operator=
QgsAbstractTerrainProvider & operator=(const QgsAbstractTerrainProvider &other)=delete
QgsAbstractTerrainProvider cannot be assigned.
QgsAbstractTerrainProvider::crs
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the native coordinate reference system of the terrain provider.
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:76
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsAbstractTerrainProvider::setOffset
void setOffset(double offset)
Returns the vertical offset value, used for adjusting the heights from the terrain provider.
Definition: qgsterrainprovider.h:157
qgsmeshlayer.h
QgsAbstractTerrainProvider::heightAt
virtual double heightAt(double x, double y) const =0
Returns the height at the point (x,y) in the terrain provider's native crs().
QgsRasterDemTerrainProvider
A terrain provider where the terrain source is a raster DEM layer.
Definition: qgsterrainprovider.h:230
QgsAbstractTerrainProvider::writeXml
virtual QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const =0
Returns a DOM element representing the state of the terrain provider.
qgsmaplayerref.h
QgsTriangularMesh
Triangular/Derived Mesh is mesh with vertices in map coordinates.
Definition: qgstriangularmesh.h:51
_LayerRef< QgsRasterLayer >
QgsAbstractTerrainProvider
Abstract base class for terrain providers.
Definition: qgsterrainprovider.h:40
QgsAbstractTerrainProvider::resolveReferences
virtual void resolveReferences(const QgsProject *project)
Resolves reference to layers from stored layer ID (if it has not been resolved already)
Definition: qgsterrainprovider.cpp:23
SIP_END
#define SIP_END
Definition: qgis_sip.h:203
QgsAbstractTerrainProvider::equals
virtual bool equals(const QgsAbstractTerrainProvider *other) const =0
Returns true if the provider is equal to other.
QgsAbstractTerrainProvider::scale
double scale() const
Returns the vertical scale factor, which can be used to exaggerate vertical heights.
Definition: qgsterrainprovider.h:133
QgsAbstractTerrainProvider::offset
double offset() const
Returns the vertical offset value, used for adjusting the heights from the terrain provider.
Definition: qgsterrainprovider.h:149
QgsFlatTerrainProvider
A terrain provider where the terrain is a simple flat surface.
Definition: qgsterrainprovider.h:205