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

#include "QGCLoggingCategory.h"

#include <QGeoCoordinate>

Andreas Bircher's avatar
Andreas Bircher committed
8
#define TERRAIN_TILE_SIZE 91
Andreas Bircher's avatar
Andreas Bircher committed
9 10 11

Q_DECLARE_LOGGING_CATEGORY(TerrainTileLog)

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

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

    /**
    * Constructor from json doc with elevation data (either from file or web)
    *
Andreas Bircher's avatar
Andreas Bircher committed
27
    * @param document
Andreas Bircher's avatar
Andreas Bircher committed
28
    */
Andreas Bircher's avatar
Andreas Bircher committed
29
    TerrainTile(QJsonDocument document);
Andreas Bircher's avatar
Andreas Bircher committed
30 31 32 33 34 35 36

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

    /**
    * Check whether valid data is loaded
    *
    * @return true if data is valid
    */
Andreas Bircher's avatar
Andreas Bircher committed
44
    bool isValid(void) const { return _isValid; }
Andreas Bircher's avatar
Andreas Bircher committed
45 46 47 48 49 50 51

    /**
    * Evaluates the elevation at the given coordinate
    *
    * @param coordinate
    * @return elevation
    */
Andreas Bircher's avatar
Andreas Bircher committed
52
    float elevation(const QGeoCoordinate& coordinate) const;
Andreas Bircher's avatar
Andreas Bircher committed
53 54 55 56 57 58

    /**
    * Accessor for the minimum elevation of the tile
    *
    * @return minimum elevation
    */
Andreas Bircher's avatar
Andreas Bircher committed
59
    float minElevation(void) const { return _minElevation; }
Andreas Bircher's avatar
Andreas Bircher committed
60 61 62 63 64 65

    /**
    * Accessor for the maximum elevation of the tile
    *
    * @return maximum elevation
    */
Andreas Bircher's avatar
Andreas Bircher committed
66
    float maxElevation(void) const { return _maxElevation; }
Andreas Bircher's avatar
Andreas Bircher committed
67 68 69 70 71 72

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

Andreas Bircher's avatar
Andreas Bircher committed
75 76 77 78 79 80 81
    /**
    * Accessor for the center coordinate
    *
    * @return center coordinate
    */
    QGeoCoordinate centerCoordinate(void) const;

Andreas Bircher's avatar
Andreas Bircher committed
82
private:
83 84 85
    inline int _latToDataIndex(double latitude) const;
    inline int _lonToDataIndex(double longitude) const;

Andreas Bircher's avatar
Andreas Bircher committed
86 87 88 89 90 91 92
    QGeoCoordinate      _southWest;                                     /// South west corner of the tile
    QGeoCoordinate      _northEast;                                     /// North east corner of the tile

    float               _minElevation;                                  /// Minimum elevation in tile
    float               _maxElevation;                                  /// Maximum elevation in tile
    float               _avgElevation;                                  /// Average elevation of the tile

93 94 95
    float**             _data;                                          /// 2D elevation data array
    int                 _gridSizeLat;                                   /// data grid size in latitude direction
    int                 _gridSizeLon;                                   /// data grid size in longitude direction
Andreas Bircher's avatar
Andreas Bircher committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    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