source: subversion/applications/utils/import/srtm2wayinfo/srtm.h

Last change on this file was 16775, checked in by herm, 8 years ago

Copyright messages added to all files.
Small documentation changes.

File size: 2.2 KB
Line 
1/* Copyright (c) 2009 Hermann Kraus
2 * This software is available under a "MIT Style" license
3 * (see COPYING).
4 */
5/** \file
6  * SRTM data downloader and tile handler.
7  */
8#ifndef __SRTM_H__
9#define __SRTM_H__
10
11#include <QString>
12#include <QObject>
13#include <QMap>
14#include <QRegExp>
15#include <QFile>
16#include <QCache>
17#include <curl/curl.h>
18
19/** Value of pixels where no SRTM data is available. */
20#define SRTM_DATA_VOID -32768
21/** Total number of SRTM files on NASA's server. */
22#define SRTM_FILE_COUNT 14047
23
24/** Handles the loading and parsing of an SRTM tile.
25  *
26  * This class should work for both SRTM1 and SRTM3 data.
27  * But currently only SRTM3 is used.
28  */
29class SrtmTile
30{
31    public:
32        SrtmTile(QString file, int lat, int lon);
33        ~SrtmTile();
34        int getPixelValue(int x, int y);
35        float getAltitudeFromLatLon(float lat, float lon);
36    private:
37        /** Returns the weighted average of a and b.
38          *
39          * weight == 0 => a only
40          *
41          * weight == 1 => b only
42          *
43          * If one of the values is SRTM_DATA_VOID the other
44          * value is returned, if both void then SRTM_DATA_VOID
45          * is returned.
46          */
47        float avg(float a, float b, float weight) {
48            if (a == SRTM_DATA_VOID) return b;
49            if (b == SRTM_DATA_VOID) return a;
50            return b * weight + a * (1 - weight);
51        }
52        int lat;
53        int lon;
54        qint16 *buffer;
55        QFile file;
56        int size;
57        bool valid;
58};
59
60/** Downloads SRTM data from NASA's server. */
61class SrtmDownloader
62{
63    public:
64        SrtmDownloader(QString url, QString cachedir);
65        ~SrtmDownloader() { curl_easy_cleanup(curl); }
66        void createFileList();
67        void loadFileList();
68        SrtmTile *getTile(float lat, float lon);
69        void downloadTile(QString filename);
70        float getAltitudeFromLatLon(float lat, float lon);
71        void curlAddData(void *ptr, int size);
72    private:
73        QString url;
74        QString cachedir;
75        QRegExp regex;
76        CURL *curl;
77        QString curlData;
78        QMap<int, QString> fileList;
79        QCache<int, SrtmTile> tileCache;
80        int latLonToIndex(int lat, int lon) { return lat * 1000 + lon; }
81};
82
83#endif
Note: See TracBrowser for help on using the repository browser.