QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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, const_cast<QgsOnlineTerrainGenerator *>( this ) );
28 }
29 
31 {
33  cloned->setTerrain( mTerrain );
34  cloned->mCrs = mCrs;
35  cloned->mExtent = mExtent;
36  cloned->mResolution = mResolution;
37  cloned->mSkirtHeight = mSkirtHeight;
38  cloned->updateGenerator();
39  return cloned;
40 }
41 
43 {
45 }
46 
48 {
49  return mTerrainTilingScheme.tileToExtent( 0, 0, 0 );
50 }
51 
52 float QgsOnlineTerrainGenerator::heightAt( double x, double y, const Qgs3DMapSettings &map ) const
53 {
54  Q_UNUSED( map )
55  if ( mHeightMapGenerator )
56  return mHeightMapGenerator->heightAt( x, y );
57  else
58  return 0;
59 }
60 
61 void QgsOnlineTerrainGenerator::writeXml( QDomElement &elem ) const
62 {
63  const QgsRectangle r = mExtent;
64  QDomElement elemExtent = elem.ownerDocument().createElement( QStringLiteral( "extent" ) );
65  elemExtent.setAttribute( QStringLiteral( "xmin" ), QString::number( r.xMinimum() ) );
66  elemExtent.setAttribute( QStringLiteral( "xmax" ), QString::number( r.xMaximum() ) );
67  elemExtent.setAttribute( QStringLiteral( "ymin" ), QString::number( r.yMinimum() ) );
68  elemExtent.setAttribute( QStringLiteral( "ymax" ), QString::number( r.yMaximum() ) );
69  elem.appendChild( elemExtent );
70 
71  elem.setAttribute( QStringLiteral( "resolution" ), mResolution );
72  elem.setAttribute( QStringLiteral( "skirt-height" ), mSkirtHeight );
73 
74  // crs is not read/written - it should be the same as destination crs of the map
75 }
76 
77 void QgsOnlineTerrainGenerator::readXml( const QDomElement &elem )
78 {
79  mResolution = elem.attribute( QStringLiteral( "resolution" ) ).toInt();
80  mSkirtHeight = elem.attribute( QStringLiteral( "skirt-height" ) ).toFloat();
81 
82  const QDomElement elemExtent = elem.firstChildElement( QStringLiteral( "extent" ) );
83  const double xmin = elemExtent.attribute( QStringLiteral( "xmin" ) ).toDouble();
84  const double xmax = elemExtent.attribute( QStringLiteral( "xmax" ) ).toDouble();
85  const double ymin = elemExtent.attribute( QStringLiteral( "ymin" ) ).toDouble();
86  const double ymax = elemExtent.attribute( QStringLiteral( "ymax" ) ).toDouble();
87 
88  setExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
89 
90  // crs is not read/written - it should be the same as destination crs of the map
91 }
92 
94 {
95  mCrs = crs;
96  mTransformContext = context;
97  updateGenerator();
98 }
99 
101 {
102  if ( mExtent == extent )
103  return;
104 
105  mExtent = extent;
106  updateGenerator();
107 
108  emit extentChanged();
109 }
110 
111 void QgsOnlineTerrainGenerator::updateGenerator()
112 {
113  if ( mExtent.isNull() )
114  {
116  }
117  else
118  {
119  // the real extent will be a square where the given extent fully fits
120  mTerrainTilingScheme = QgsTilingScheme( mExtent, mCrs );
121  }
122 
123  mHeightMapGenerator.reset( new QgsDemHeightMapGenerator( nullptr, mTerrainTilingScheme, mResolution, mTransformContext ) );
124 }
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
QgsTerrainGenerator::extentChanged
void extentChanged()
Emitted when the terrain extent has changed.
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsOnlineTerrainGenerator::setExtent
void setExtent(const QgsRectangle &extent) override
sets the extent of the terrain in terrain's CRS
Definition: qgsonlineterraingenerator.cpp:100
QgsRectangle::yMinimum
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
QgsOnlineTerrainGenerator::clone
QgsTerrainGenerator * clone() const override SIP_FACTORY
Makes a copy of the current instance.
Definition: qgsonlineterraingenerator.cpp:30
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsOnlineTerrainGenerator::crs
QgsCoordinateReferenceSystem crs() const
Returns CRS of the terrain.
Definition: qgsonlineterraingenerator.h:48
QgsRectangle::xMaximum
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
QgsTerrainGenerator::mTerrain
QgsTerrainEntity * mTerrain
Definition: qgsterraingenerator.h:122
QgsTerrainGenerator::mTerrainTilingScheme
QgsTilingScheme mTerrainTilingScheme
Tiling scheme of the terrain.
Definition: qgsterraingenerator.h:121
qgsonlineterraingenerator.h
QgsTerrainGenerator
Base class for generators of terrain.
Definition: qgsterraingenerator.h:49
QgsOnlineTerrainGenerator::type
Type type() const override
What texture generator implementation is this.
Definition: qgsonlineterraingenerator.cpp:42
QgsOnlineTerrainGenerator::readXml
void readXml(const QDomElement &elem) override
Read terrain generator's configuration from XML.
Definition: qgsonlineterraingenerator.cpp:77
QgsOnlineTerrainGenerator::setCrs
void setCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets CRS of the terrain.
Definition: qgsonlineterraingenerator.cpp:93
qgsdemterraintileloader_p.h
QgsTerrainGenerator::Type
Type
Enumeration of the available terrain generators.
Definition: qgsterraingenerator.h:55
Qgs3DMapSettings
Definition of the world.
Definition: qgs3dmapsettings.h:57
QgsOnlineTerrainGenerator::~QgsOnlineTerrainGenerator
~QgsOnlineTerrainGenerator() override
QgsRectangle::xMinimum
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
QgsOnlineTerrainGenerator::createChunkLoader
QgsChunkLoader * createChunkLoader(QgsChunkNode *node) const override SIP_FACTORY
Definition: qgsonlineterraingenerator.cpp:25
QgsTilingScheme::tileToExtent
QgsRectangle tileToExtent(int x, int y, int z) const
Returns map coordinates of the extent of a tile.
Definition: qgstilingscheme.cpp:43
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsRectangle::yMaximum
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
QgsOnlineTerrainGenerator::writeXml
void writeXml(QDomElement &elem) const override
Write terrain generator's configuration to XML.
Definition: qgsonlineterraingenerator.cpp:61
QgsTerrainGenerator::Online
@ Online
Terrain is built from downloaded tiles with digital elevation model.
Definition: qgsterraingenerator.h:59
QgsOnlineTerrainGenerator
Implementation of terrain generator that uses online resources to download heightmaps.
Definition: qgsonlineterraingenerator.h:37
QgsTilingScheme
The class encapsulates tiling scheme (just like with WMTS / TMS / XYZ layers).
Definition: qgstilingscheme.h:37
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:52
QgsOnlineTerrainGenerator::extent
QgsRectangle extent() const override
extent of the terrain in terrain's CRS
Definition: qgsonlineterraingenerator.cpp:47
QgsRectangle::isNull
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Definition: qgsrectangle.h:479
QgsTerrainGenerator::setTerrain
void setTerrain(QgsTerrainEntity *t)
Sets terrain entity for the generator (does not transfer ownership)
Definition: qgsterraingenerator.h:64