source: subversion/applications/utils/import/srtm2wayinfo/relations.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: 1.7 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  * Create altitude relations from an OSMData object.
7  */
8#ifndef __RELATIONS_H__
9#define __RELATIONS_H__
10
11#include "osm-parse.h"
12#include <math.h>
13
14/** Maximum distance between sampling points. Half SRTM grid size. */
15#define MAX_DIST 0.045
16
17class QFile;
18class SrtmDownloader;
19
20/** Writes relations and calculates the neccessary data. */
21class RelationWriter
22{
23    public:
24        RelationWriter(OsmData *data, QIODevice *output, SrtmDownloader *downloader);
25        void writeRelations();
26    private:
27        void processWay(OsmWay *way);
28        void calcUpDown(float from_lat, float from_lon, float to_lat, float to_lon, float *up, float *down);
29        void calc(OsmNodeId from, OsmNodeId to, float *length, float *up, float *down);
30        void writeRelation(OsmWayId wayId, OsmNodeId startNode, OsmNodeId endNode,
31            float length, float up, float down);
32        //Inlined for performance reasons
33        float distance(float from_lat, float from_lon, float to_lat, float to_lon) {
34            //Distances are small => Assume earth is flat in this region to simplify calculation and avoid rounding errors that easily get very large with great circle distance calculations
35            float delta_lat = (to_lat - from_lat) * 111.11; //TODO: Exact value
36            float delta_lon = (to_lon - from_lon) * 111.11 * cos(to_lat/360.0*2.0*M_PI);
37            return sqrt(delta_lat*delta_lat + delta_lon*delta_lon);
38        }
39        OsmData *data;
40        QIODevice *output;
41        SrtmDownloader *downloader;
42        OsmRelationId relationId;
43};
44
45#endif
Note: See TracBrowser for help on using the repository browser.