TerrainTile.h 3.42 KB
Newer Older
Andreas Bircher's avatar
Andreas Bircher committed
1 2 3 4 5 6 7 8 9
#ifndef TERRAINTILE_H
#define TERRAINTILE_H

#include "QGCLoggingCategory.h"

#include <QGeoCoordinate>

Q_DECLARE_LOGGING_CATEGORY(TerrainTileLog)

10 11 12 13 14 15
/**
 * @brief The TerrainTile class
 *
 * Implements an interface for https://developers.airmap.com/v2.0/docs/elevation-api
 */

Andreas Bircher's avatar
Andreas Bircher committed
16 17 18 19 20 21 22 23 24
class TerrainTile
{
public:
    TerrainTile();
    ~TerrainTile();

    /**
    * Constructor from json doc with elevation data (either from file or web)
    *
Andreas Bircher's avatar
Andreas Bircher committed
25
    * @param document
Andreas Bircher's avatar
Andreas Bircher committed
26
    */
Andreas Bircher's avatar
Andreas Bircher committed
27
    TerrainTile(QJsonDocument document);
Andreas Bircher's avatar
Andreas Bircher committed
28

29 30 31 32 33 34 35
    /**
    * Constructor from serialized elevation data (either from file or web)
    *
    * @param document
    */
    TerrainTile(QByteArray byteArray);

Andreas Bircher's avatar
Andreas Bircher committed
36 37 38 39 40 41
    /**
    * Check for whether a coordinate lies within this tile
    *
    * @param coordinate
    * @return true if within
    */
Andreas Bircher's avatar
Andreas Bircher committed
42
    bool isIn(const QGeoCoordinate& coordinate) const;
Andreas Bircher's avatar
Andreas Bircher committed
43 44 45 46 47 48

    /**
    * Check whether valid data is loaded
    *
    * @return true if data is valid
    */
Andreas Bircher's avatar
Andreas Bircher committed
49
    bool isValid(void) const { return _isValid; }
Andreas Bircher's avatar
Andreas Bircher committed
50 51 52 53 54 55 56

    /**
    * Evaluates the elevation at the given coordinate
    *
    * @param coordinate
    * @return elevation
    */
Andreas Bircher's avatar
Andreas Bircher committed
57
    float elevation(const QGeoCoordinate& coordinate) const;
Andreas Bircher's avatar
Andreas Bircher committed
58 59 60 61 62 63

    /**
    * Accessor for the minimum elevation of the tile
    *
    * @return minimum elevation
    */
Andreas Bircher's avatar
Andreas Bircher committed
64
    float minElevation(void) const { return _minElevation; }
Andreas Bircher's avatar
Andreas Bircher committed
65 66 67 68 69 70

    /**
    * Accessor for the maximum elevation of the tile
    *
    * @return maximum elevation
    */
Andreas Bircher's avatar
Andreas Bircher committed
71
    float maxElevation(void) const { return _maxElevation; }
Andreas Bircher's avatar
Andreas Bircher committed
72 73 74 75 76 77

    /**
    * Accessor for the average elevation of the tile
    *
    * @return average elevation
    */
Andreas Bircher's avatar
Andreas Bircher committed
78 79
    float avgElevation(void) const { return _avgElevation; }

Andreas Bircher's avatar
Andreas Bircher committed
80 81 82 83 84 85 86
    /**
    * Accessor for the center coordinate
    *
    * @return center coordinate
    */
    QGeoCoordinate centerCoordinate(void) const;

87 88 89 90 91
    /**
    * Serialize data
    *
    * @return serialized data
    */
92
    static QByteArray serialize(QByteArray input);
93

Andreas Bircher's avatar
Andreas Bircher committed
94
private:
95 96 97
    inline int _latToDataIndex(double latitude) const;
    inline int _lonToDataIndex(double longitude) const;

Andreas Bircher's avatar
Andreas Bircher committed
98 99 100
    QGeoCoordinate      _southWest;                                     /// South west corner of the tile
    QGeoCoordinate      _northEast;                                     /// North east corner of the tile

101 102 103
    int               _minElevation;                                    /// Minimum elevation in tile
    int               _maxElevation;                                    /// Maximum elevation in tile
    double            _avgElevation;                                    /// Average elevation of the tile
Andreas Bircher's avatar
Andreas Bircher committed
104

105
    double**            _data;                                          /// 2D elevation data array
106 107
    int                 _gridSizeLat;                                   /// data grid size in latitude direction
    int                 _gridSizeLon;                                   /// data grid size in longitude direction
Andreas Bircher's avatar
Andreas Bircher committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
    bool                _isValid;                                       /// data loaded is valid

    // Json keys
    static const char*  _jsonStatusKey;
    static const char*  _jsonDataKey;
    static const char*  _jsonBoundsKey;
    static const char*  _jsonSouthWestKey;
    static const char*  _jsonNorthEastKey;
    static const char*  _jsonStatsKey;
    static const char*  _jsonMaxElevationKey;
    static const char*  _jsonMinElevationKey;
    static const char*  _jsonAvgElevationKey;
    static const char*  _jsonCarpetKey;
};

#endif // TERRAINTILE_H