QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgsonlineterraingenerator.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsonlineterraingenerator.cpp
3 --------------------------------------
4 Date : March 2019
5 Copyright : (C) 2019 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "moc_qgsonlineterraingenerator.cpp"
18
20
21
23
25
26QgsChunkLoader *QgsOnlineTerrainGenerator::createChunkLoader( QgsChunkNode *node ) const
27{
28 return new QgsDemTerrainTileLoader( mTerrain, node, const_cast<QgsOnlineTerrainGenerator *>( this ) );
29}
30
32{
34 cloned->setTerrain( mTerrain );
35 cloned->mCrs = mCrs;
36 cloned->mExtent = mExtent;
37 cloned->mResolution = mResolution;
38 cloned->mSkirtHeight = mSkirtHeight;
39 cloned->updateGenerator();
40 return cloned;
41}
42
47
52
53float QgsOnlineTerrainGenerator::heightAt( double x, double y, const Qgs3DRenderContext &context ) const
54{
55 Q_UNUSED( context )
56 if ( mHeightMapGenerator )
57 return mHeightMapGenerator->heightAt( x, y );
58 else
59 return 0;
60}
61
62void QgsOnlineTerrainGenerator::writeXml( QDomElement &elem ) const
63{
64 const QgsRectangle r = mExtent;
65 QDomElement elemExtent = elem.ownerDocument().createElement( QStringLiteral( "extent" ) );
66 elemExtent.setAttribute( QStringLiteral( "xmin" ), QString::number( r.xMinimum() ) );
67 elemExtent.setAttribute( QStringLiteral( "xmax" ), QString::number( r.xMaximum() ) );
68 elemExtent.setAttribute( QStringLiteral( "ymin" ), QString::number( r.yMinimum() ) );
69 elemExtent.setAttribute( QStringLiteral( "ymax" ), QString::number( r.yMaximum() ) );
70 elem.appendChild( elemExtent );
71
72 elem.setAttribute( QStringLiteral( "resolution" ), mResolution );
73 elem.setAttribute( QStringLiteral( "skirt-height" ), mSkirtHeight );
74
75 // crs is not read/written - it should be the same as destination crs of the map
76}
77
78void QgsOnlineTerrainGenerator::readXml( const QDomElement &elem )
79{
80 mResolution = elem.attribute( QStringLiteral( "resolution" ) ).toInt();
81 mSkirtHeight = elem.attribute( QStringLiteral( "skirt-height" ) ).toFloat();
82
83 const QDomElement elemExtent = elem.firstChildElement( QStringLiteral( "extent" ) );
84 const double xmin = elemExtent.attribute( QStringLiteral( "xmin" ) ).toDouble();
85 const double xmax = elemExtent.attribute( QStringLiteral( "xmax" ) ).toDouble();
86 const double ymin = elemExtent.attribute( QStringLiteral( "ymin" ) ).toDouble();
87 const double ymax = elemExtent.attribute( QStringLiteral( "ymax" ) ).toDouble();
88
89 setExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
90
91 // crs is not read/written - it should be the same as destination crs of the map
92}
93
95{
96 mCrs = crs;
97 mTransformContext = context;
98 updateGenerator();
99}
100
102{
103 if ( mExtent == extent )
104 return;
105
106 mExtent = extent;
107 updateGenerator();
108}
109
110void QgsOnlineTerrainGenerator::updateGenerator()
111{
112 if ( mExtent.isNull() )
113 {
115 }
116 else
117 {
118 // the real extent will be a square where the given extent fully fits
120 }
121
122 mHeightMapGenerator.reset( new QgsDemHeightMapGenerator( nullptr, mTerrainTilingScheme, mResolution, mTransformContext ) );
123}
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
void setExtent(const QgsRectangle &extent) override
sets the extent of the terrain in terrain's CRS
void setCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets CRS of the terrain.
float heightAt(double x, double y, const Qgs3DRenderContext &context) const override
Returns height at (x,y) in map's CRS.
QgsTerrainGenerator * clone() const override SIP_FACTORY
Makes a copy of the current instance.
~QgsOnlineTerrainGenerator() override
void writeXml(QDomElement &elem) const override
Write terrain generator's configuration to XML.
QgsCoordinateReferenceSystem crs() const override
Returns CRS of the terrain.
QgsRectangle rootChunkExtent() const override
extent of the terrain's root chunk in terrain's CRS
Type type() const override
What texture generator implementation is this.
void readXml(const QDomElement &elem) override
Read terrain generator's configuration from XML.
QgsChunkLoader * createChunkLoader(QgsChunkNode *node) const override SIP_FACTORY
A rectangle specified with double values.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
bool isNull() const
Test if the rectangle is null (holding no spatial information).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Type
Enumeration of the available terrain generators.
@ Online
Terrain is built from downloaded tiles with digital elevation model.
QgsTilingScheme mTerrainTilingScheme
Tiling scheme of the terrain.
virtual QgsRectangle extent() const
extent of the terrain in terrain's CRS, might be non-square and smaller than rootChunkExtent()
QgsTerrainEntity * mTerrain
virtual void setTerrain(QgsTerrainEntity *t)
Sets terrain entity for the generator (does not transfer ownership)
QgsRectangle tileToExtent(int x, int y, int z) const
Returns map coordinates of the extent of a tile.
const QgsCoordinateReferenceSystem & crs