-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsterraindownloader.h
109 lines (88 loc) · 4.05 KB
/
qgsterraindownloader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/***************************************************************************
qgsterraindownloader.h
--------------------------------------
Date : March 2019
Copyright : (C) 2019 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSTERRAINDOWNLOADER_H
#define QGSTERRAINDOWNLOADER_H
#include "qgis_3d.h"
#include <memory>
#include <QByteArray>
#include <QImage>
#include "qgscoordinatetransformcontext.h"
class QgsRectangle;
class QgsCoordinateReferenceSystem;
class QgsRasterLayer;
class QgsCoordinateTransformContext;
#define SIP_NO_FILE
/**
* \ingroup 3d
* Takes care of downloading terrain data from a publicly available data source.
*
* Currently using terrain tiles in Terrarium format hosted on AWS. More info:
*
* - data format: https://github.com/tilezen/joerd/blob/master/docs/formats.md
* - data sources: https://github.com/tilezen/joerd/blob/master/docs/data-sources.md
* - hosting: https://registry.opendata.aws/terrain-tiles/
*
* \note Not available in Python bindings
*
* \since QGIS 3.8
*/
class _3D_EXPORT QgsTerrainDownloader
{
public:
/**
* Constructs a QgsTerrainDownloader object
* \param transformContext coordinate transform context
*/
QgsTerrainDownloader( const QgsCoordinateTransformContext &transformContext );
~QgsTerrainDownloader();
//! Definition of data source for terrain tiles (assuming "terrarium" data encoding with usual XYZ tiling scheme)
typedef struct
{
QString uri; //!< HTTP(S) template for XYZ tiles requests (e.g. http://example.com/{z}/{x}/{y}.png)
int zMin = 0; //!< Minimum zoom level (Z) with valid data
int zMax = 0; //!< Maximum zoom level (Z) with valid data
} DataSource;
//! Returns the data source used by default
static DataSource defaultDataSource();
//! Configures data source to be used for download of terrain tiles
void setDataSource( const DataSource &ds );
//! Returns currently configured data source
DataSource dataSource() const { return mDataSource; }
/**
* For given extent and resolution (number of pixels for width/height) in specified CRS, download necessary
* tile images (if not cached already) and produce height map out of them (byte array of res*res float values)
*/
QByteArray getHeightMap( const QgsRectangle &extentOrig, int res, const QgsCoordinateReferenceSystem &destCrs, const QgsCoordinateTransformContext &context = QgsCoordinateTransformContext(), QString tmpFilenameImg = QString(), QString tmpFilenameTif = QString() );
private:
/**
* For the requested resolution given as map units per pixel, find out the best native tile resolution
* (higher resolution = fewer map units per pixel)
*/
double findBestTileResolution( double requestedMupp );
/**
* Given extent and map units per pixels, adjust the extent and resolution
*/
static void adjustExtentAndResolution( double mupp, const QgsRectangle &extentOrig, QgsRectangle &extent, int &res );
/**
* Takes an image tile with heights encoded using "terrarium" encoding and converts it to
* an array of 32-bit floats with decoded elevations.
*/
static void tileImageToHeightMap( const QImage &img, QByteArray &heightMap );
private:
DataSource mDataSource;
std::unique_ptr<QgsRasterLayer> mOnlineDtm;
double mXSpan = 0; //!< Width of the tile at zoom level 0 in map units
};
#endif // QGSTERRAINDOWNLOADER_H