QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
19 
20 
22 
24 
25 QgsChunkLoader *QgsOnlineTerrainGenerator::createChunkLoader( QgsChunkNode *node ) const
26 {
27  return new QgsDemTerrainTileLoader( mTerrain, node );
28 }
29 
31 {
33  cloned->mCrs = mCrs;
34  cloned->mExtent = mExtent;
35  cloned->mResolution = mResolution;
36  cloned->mSkirtHeight = mSkirtHeight;
37  cloned->updateGenerator();
38  return cloned;
39 }
40 
42 {
44 }
45 
47 {
48  return mTerrainTilingScheme.tileToExtent( 0, 0, 0 );
49 }
50 
51 float QgsOnlineTerrainGenerator::heightAt( double x, double y, const Qgs3DMapSettings &map ) const
52 {
53  Q_UNUSED( map )
54  if ( mHeightMapGenerator )
55  return mHeightMapGenerator->heightAt( x, y );
56  else
57  return 0;
58 }
59 
60 void QgsOnlineTerrainGenerator::writeXml( QDomElement &elem ) const
61 {
62  QgsRectangle r = mExtent;
63  QDomElement elemExtent = elem.ownerDocument().createElement( QStringLiteral( "extent" ) );
64  elemExtent.setAttribute( QStringLiteral( "xmin" ), QString::number( r.xMinimum() ) );
65  elemExtent.setAttribute( QStringLiteral( "xmax" ), QString::number( r.xMaximum() ) );
66  elemExtent.setAttribute( QStringLiteral( "ymin" ), QString::number( r.yMinimum() ) );
67  elemExtent.setAttribute( QStringLiteral( "ymax" ), QString::number( r.yMaximum() ) );
68 
69  elem.setAttribute( QStringLiteral( "resolution" ), mResolution );
70  elem.setAttribute( QStringLiteral( "skirt-height" ), mSkirtHeight );
71 
72  // crs is not read/written - it should be the same as destination crs of the map
73 }
74 
75 void QgsOnlineTerrainGenerator::readXml( const QDomElement &elem )
76 {
77  QDomElement elemExtent = elem.firstChildElement( QStringLiteral( "extent" ) );
78  double xmin = elemExtent.attribute( QStringLiteral( "xmin" ) ).toDouble();
79  double xmax = elemExtent.attribute( QStringLiteral( "xmax" ) ).toDouble();
80  double ymin = elemExtent.attribute( QStringLiteral( "ymin" ) ).toDouble();
81  double ymax = elemExtent.attribute( QStringLiteral( "ymax" ) ).toDouble();
82 
83  setExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
84 
85  mResolution = elem.attribute( QStringLiteral( "resolution" ) ).toInt();
86  mSkirtHeight = elem.attribute( QStringLiteral( "skirt-height" ) ).toFloat();
87 
88  // crs is not read/written - it should be the same as destination crs of the map
89 }
90 
92 {
93  mCrs = crs;
94  mTransformContext = context;
95  updateGenerator();
96 }
97 
99 {
100  mExtent = extent;
101  updateGenerator();
102 }
103 
104 void QgsOnlineTerrainGenerator::updateGenerator()
105 {
106  if ( mExtent.isNull() )
107  {
109  }
110  else
111  {
112  // the real extent will be a square where the given extent fully fits
113  mTerrainTilingScheme = QgsTilingScheme( mExtent, mCrs );
114  }
115 
116  mHeightMapGenerator.reset( new QgsDemHeightMapGenerator( nullptr, mTerrainTilingScheme, mResolution, mTransformContext ) );
117 }
QgsCoordinateTransformContext
Definition: qgscoordinatetransformcontext.h:57
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsRectangle::xMaximum
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:162
QgsOnlineTerrainGenerator::clone
QgsTerrainGenerator * clone() const override
Makes a copy of the current instance.
Definition: qgsonlineterraingenerator.cpp:30
QgsRectangle
Definition: qgsrectangle.h:41
QgsOnlineTerrainGenerator::setExtent
void setExtent(const QgsRectangle &extent)
Sets extent of the terrain.
Definition: qgsonlineterraingenerator.cpp:98
QgsOnlineTerrainGenerator::createChunkLoader
QgsChunkLoader * createChunkLoader(QgsChunkNode *node) const override
Definition: qgsonlineterraingenerator.cpp:25
QgsOnlineTerrainGenerator::crs
QgsCoordinateReferenceSystem crs() const
Returns CRS of the terrain.
Definition: qgsonlineterraingenerator.h:50
QgsTerrainGenerator::mTerrain
QgsTerrainEntity * mTerrain
Definition: qgsterraingenerator.h:107
QgsTerrainGenerator::mTerrainTilingScheme
QgsTilingScheme mTerrainTilingScheme
Tiling scheme of the terrain.
Definition: qgsterraingenerator.h:106
qgsonlineterraingenerator.h
QgsTerrainGenerator
Definition: qgsterraingenerator.h:47
QgsOnlineTerrainGenerator::type
Type type() const override
What texture generator implementation is this.
Definition: qgsonlineterraingenerator.cpp:41
QgsOnlineTerrainGenerator::readXml
void readXml(const QDomElement &elem) override
Read terrain generator's configuration from XML.
Definition: qgsonlineterraingenerator.cpp:75
QgsOnlineTerrainGenerator::setCrs
void setCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets CRS of the terrain.
Definition: qgsonlineterraingenerator.cpp:91
qgsdemterraintileloader_p.h
QgsTerrainGenerator::Type
Type
Enumeration of the available terrain generators.
Definition: qgsterraingenerator.h:52
Qgs3DMapSettings
Definition: qgs3dmapsettings.h:51
QgsOnlineTerrainGenerator::~QgsOnlineTerrainGenerator
~QgsOnlineTerrainGenerator() override
QgsTilingScheme::tileToExtent
QgsRectangle tileToExtent(int x, int y, int z) const
Returns map coordinates of the extent of a tile.
Definition: qgstilingscheme.cpp:42
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
QgsRectangle::yMaximum
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:172
QgsOnlineTerrainGenerator::writeXml
void writeXml(QDomElement &elem) const override
Write terrain generator's configuration to XML.
Definition: qgsonlineterraingenerator.cpp:60
QgsTerrainGenerator::Online
@ Online
Terrain is built from downloaded tiles with digital elevation model.
Definition: qgsterraingenerator.h:56
QgsOnlineTerrainGenerator
Definition: qgsonlineterraingenerator.h:37
QgsRectangle::yMinimum
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
QgsTilingScheme
Definition: qgstilingscheme.h:35
QgsOnlineTerrainGenerator::QgsOnlineTerrainGenerator
QgsOnlineTerrainGenerator()
Constructor for QgsOnlineTerrainGenerator.
QgsOnlineTerrainGenerator::heightAt
float heightAt(double x, double y, const Qgs3DMapSettings &map) const override
Returns height at (x,y) in terrain's CRS.
Definition: qgsonlineterraingenerator.cpp:51
QgsOnlineTerrainGenerator::extent
QgsRectangle extent() const override
extent of the terrain in terrain's CRS
Definition: qgsonlineterraingenerator.cpp:46
QgsRectangle::isNull
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Definition: qgsrectangle.h:447
QgsRectangle::xMinimum
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167