TerrainTile.h 3.14 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

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

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

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

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

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

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

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

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

Andreas Bircher's avatar
Andreas Bircher committed
84 85 86 87 88 89 90
    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

91 92 93
    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
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    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