QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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
30class QDomElement;
32class QDomDocument;
33
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 }
62#endif
63
64 public:
65
67
69
73 virtual bool equals( const QgsAbstractTerrainProvider *other ) const = 0;
74
78 virtual void resolveReferences( const QgsProject *project );
79
84 virtual bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) = 0;
85
90 virtual QDomElement writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const = 0;
91
95 virtual QString type() const = 0;
96
103
110 virtual void prepare() = 0 SIP_FACTORY;
111
116
122 virtual double heightAt( double x, double y ) const = 0;
123
130 double scale() const { return mScale; }
131
138 void setScale( double scale ) { mScale = scale; }
139
146 double offset() const { return mOffset; }
147
154 void setOffset( double offset ) { mOffset = offset; }
155
156 protected:
157
159
160#ifndef SIP_RUN
162#endif
163
167 void writeCommonProperties( QDomElement &element, const QgsReadWriteContext &context ) const;
168
172 void readCommonProperties( const QDomElement &element, const QgsReadWriteContext &context );
173
175 double mScale = 1.0;
176
178 double mOffset = 0.0;
179
180 private:
181
182#ifdef SIP_RUN
184#endif
185
186};
187
188
196{
197 public:
198
200
201 QString type() const override;
202 bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) override;
203 QDomElement writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const override;
204 QgsCoordinateReferenceSystem crs() const override;
205 double heightAt( double x, double y ) const override;
206 QgsFlatTerrainProvider *clone() const override SIP_FACTORY;
207 void prepare() override;
208 bool equals( const QgsAbstractTerrainProvider *other ) const override;
209};
210
218{
219 public:
220
222
223#ifndef SIP_RUN
225#endif
226
227 QString type() const override;
228 void resolveReferences( const QgsProject *project ) override;
229 bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) override;
230 QDomElement writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const override;
231 QgsCoordinateReferenceSystem crs() const override;
232 double heightAt( double x, double y ) const override;
233 QgsRasterDemTerrainProvider *clone() const override SIP_FACTORY;
234 bool equals( const QgsAbstractTerrainProvider *other ) const override;
235 void prepare() override;
236
242 void setLayer( QgsRasterLayer *layer );
243
249 QgsRasterLayer *layer() const;
250
251
252 private:
254
255 _LayerRef<QgsRasterLayer> mRasterLayer;
256 std::unique_ptr< QgsRasterDataProvider > mRasterProvider;
257
258};
259
260
268{
269 public:
270
272
273#ifndef SIP_RUN
275#endif
276
277 QString type() const override;
278 void resolveReferences( const QgsProject *project ) override;
279 bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) override;
280 QDomElement writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const override;
281 QgsCoordinateReferenceSystem crs() const override;
282 double heightAt( double x, double y ) const override;
283 QgsMeshTerrainProvider *clone() const override SIP_FACTORY;
284 bool equals( const QgsAbstractTerrainProvider *other ) const override;
285 void prepare() override;
286
292 void setLayer( QgsMeshLayer *layer );
293
299 QgsMeshLayer *layer() const;
300
301 private:
303
304 _LayerRef<QgsMeshLayer> mMeshLayer;
305 QgsTriangularMesh mTriangularMesh;
306};
307
308#endif // QGSTERRAINPROVIDER_H
Abstract base class for terrain providers.
QgsAbstractTerrainProvider & operator=(const QgsAbstractTerrainProvider &other)=delete
virtual bool equals(const QgsAbstractTerrainProvider *other) const =0
Returns true if the provider is equal to other.
virtual QString type() const =0
Returns the unique type ID string for the provider.
virtual double heightAt(double x, double y) const =0
Returns the height at the point (x,y) in the terrain provider's native crs().
virtual bool readXml(const QDomElement &element, const QgsReadWriteContext &context)=0
Reads the terrain provider state from a DOM element.
virtual ~QgsAbstractTerrainProvider()
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the native coordinate reference system of the terrain provider.
virtual void prepare()=0
Called on the main thread prior to accessing the provider from a background thread.
double offset() const
Returns the vertical offset value, used for adjusting the heights from the terrain provider.
double scale() const
Returns the vertical scale factor, which can be used to exaggerate vertical heights.
virtual QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const =0
Returns a DOM element representing the state of the terrain provider.
QgsAbstractTerrainProvider()=default
void setOffset(double offset)
Returns the vertical offset value, used for adjusting the heights from the terrain provider.
void setScale(double scale)
Sets the vertical scale factor, which can be used to exaggerate vertical heights.
virtual QgsAbstractTerrainProvider * clone() const =0
Creates a clone of the provider and returns the new object.
This class represents a coordinate reference system (CRS).
A terrain provider where the terrain is a simple flat surface.
QgsFlatTerrainProvider()=default
Represents a mesh layer supporting display of data on structured or unstructured meshes.
A terrain provider that uses the Z values of a mesh layer to build a terrain surface.
QgsMeshTerrainProvider()=default
const QgsMeshTerrainProvider * operator=(const QgsMeshTerrainProvider &other)=delete
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
Base class for raster data providers.
A terrain provider where the terrain source is a raster DEM layer.
const QgsRasterDemTerrainProvider * operator=(const QgsRasterDemTerrainProvider &other)=delete
Represents a raster layer.
The class is used as a container of context for various read/write operations on other objects.
Triangular/Derived Mesh is mesh with vertices in map coordinates.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_END
Definition qgis_sip.h:208
const QgsCoordinateReferenceSystem & crs
Internal structure to keep weak pointer to QgsMapLayer or layerId if the layer is not available yet.