-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gpx_model.h
457 lines (406 loc) · 17.4 KB
/
gpx_model.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
/****************************************************************************
* Copyright (c) 2014 - 2015 Frederic Bourgeois <[email protected]> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with This program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************/
#ifndef _GPX_MODEL_H_
#define _GPX_MODEL_H_
#include <string>
#include <vector>
#include "gpxmodel_export.h"
using namespace std;
/**
* @defgroup GPX_model GPX model
* @brief Model representation of a GPX file
*
* This model can be used to represent a GPX file (GPS exchange format).
* The structure is based on the GPX version 1.1.
*
* The model is divided in tracks (GPX_trkType), track segments
* (GPX_trksegType) and track points (GPX_wptType).
*
* The model is represented by a tree like this:
* <PRE>
* GPX_model
* creator
* GPX_metadataType
* GPX_extensionsType [0...*]
* GPX_statsType [1]
* GPX_trkType [0...*]
* GPX_trkMetadataType [1]
* GPX_extensionsType [0...*]
* GPX_statsType [1]
* GPX_trksegType [0...*]
* GPX_extensionsType [0...*]
* GPX_statsType [1]
* GPX_wptType [0...*]
* </PRE>
*
* @see http://www.topografix.com/gpx.asp
*
* @{
*/
class GPXMODEL_EXPORT GPX_trkType;
class GPXMODEL_EXPORT GPX_trksegType;
class GPXMODEL_EXPORT GPX_wptType;
/**
* @brief Information about the copyright holder and any license governing use of the GPX file
*/
struct GPXMODEL_EXPORT GPX_copyrightType
{
string author; /**< Copyright holder */
string year; /**< Year of copyright */
string license; /**< Link to external file containing license text */
};
/**
* @brief Representation of a link to an external resource
*/
struct GPXMODEL_EXPORT GPX_linkType
{
string href; /**< URL of the link */
string text; /**< Text of the link */
string type; /**< Mime type of content (text/html) */
};
/**
* @brief Representation of an email address
*/
struct GPXMODEL_EXPORT GPX_emailType
{
string id; /**< ID half of email address (bourgeoislab) */
string domain; /**< Domain half of email address (gmail.com) */
};
/**
* @brief Representation of a person or organization
*/
struct GPXMODEL_EXPORT GPX_personType
{
string name; /**< Name of person or organization */
GPX_emailType email; /**< Email address */
GPX_linkType link; /**< Link to Web site or other external information */
};
/**
* @brief Bound given by minimal and maximal latitude / longitude
*/
struct GPXMODEL_EXPORT GPX_boundsType
{
double minlat; /**< Minimum latitude [deg] */
double minlon; /**< Minimum longitude [deg] */
double maxlat; /**< Maximum latitude [deg] */
double maxlon; /**< Maximum longitude [deg] */
};
/**
* @brief Any extension to the standard GPX format
*/
struct GPXMODEL_EXPORT GPX_extType
{
vector <string> extension; /**< Any extension element */
};
/**
* @brief Garmin's TrackPointExtension GPX extension
*/
struct GPXMODEL_EXPORT GPX_extTPExtType
{
unsigned int heartrate; /**< Heart rate [bpm] */
vector <string> other; /**< Any other extension element */
};
/**
* @brief Information about the GPX file
*/
struct GPXMODEL_EXPORT GPX_metadataType
{
string name; /**< Name of the GPX file */
string desc; /**< Description of the contents of the GPX file */
GPX_personType author; /**< Person or organization who created the GPX file */
GPX_copyrightType copyright; /**< Copyright and license information governing use of the file */
vector <GPX_linkType> links; /**< Links associated with the location described in the file */
time_t timestamp; /**< GMT creation date of the file [s] */
int millisecond; /**< GMT creation date of the file (0-999) [ms] */
string keywords; /**< Keywords associated with the file */
GPX_boundsType bounds; /**< Minimum and maximum coordinates */
GPX_extType extensions; /**< Extensions */
};
/**
* @brief Information about a track
*/
struct GPXMODEL_EXPORT GPX_trkMetadataType
{
string name; /**< Name of the track */
string cmt; /**< Comment for track */
string desc; /**< Description of track */
string src; /**< Source of data */
vector <GPX_linkType> links; /**< Links to external information about track */
size_t number; /**< Track number */
string type; /**< Type (classification) of the track */
};
/**
* @brief Statistic information about a list of track points
*/
struct GPXMODEL_EXPORT GPX_statsType
{
int points; /**< Number of track points within the list */
time_t startTime; /**< GMT timestamp of the first point [s] */
time_t endTime; /**< GMT timestamp of the last point [s] */
unsigned int duration; /**< Time elapsed between first and last point [s] */
double distance; /**< Distance covered [km] */
float speed; /**< Average speed [km/h] */
float minhei; /**< Minimal height [m] */
float maxhei; /**< Maximal height [m] */
float heightIntUp; /**< Height integral uphill */
float heightIntDown; /**< Height integral downhill */
GPX_boundsType bounds; /**< Minimum and maximum coordinates */
};
/**
* @class GPX_model
*
* @brief Class representing the content of a GPX file
*
* @author Frederic Bourgeois <[email protected]>
* @version 1.1
* @date 10 Jan 2015
*/
class GPXMODEL_EXPORT GPX_model
{
public:
/**
* @brief Return code
*/
enum retCode_e
{
GPXM_OK = 0, /**< Success */
GPXM_ERR_INVALID_ARG = -1, /**< Invalid argument */
GPXM_ERR_FILEOPEN = -2, /**< Failed to open file (read or write) */
GPXM_ERR_FAILED = -3, /**< Operation failed */
GPXM_ERR_OUTOFMEM = -4, /**< Out of memory */
GPXM_WARN_NOTHING_CHANGED = 1 /**< Function call had no effect */
};
/**
* @brief File Type
*/
enum fileType_e
{
GPXM_FILE_AUTOMATIC, /**< Automatic detection */
GPXM_FILE_NOT_SUPPORTED, /**< Not supported */
GPXM_FILE_GPX, /**< GPX file */
GPXM_FILE_NMEA, /**< NMEA file */
#ifdef BUILD_LIBKML
GPXM_FILE_LIBKML, /**< KML file*/
#endif
GPXM_FILE_ACT /**< ACT file */
};
const string creator; /**< Creator of the GPX file */
GPX_metadataType metadata; /**< Information about the GPX file */
GPX_extType extensions; /**< Extensions */
GPX_statsType stats; /**< Statistic information */
vector <GPX_trkType> trk; /**< A list of tracks */
/**
* @brief Gets the type of a file
* @param fileName File
* @return File type
*/
static fileType_e getFileType(const string& fileName);
/**
* @brief Construcst a GPX model representing the content of a GPX file
* @param creator Creator of the model
*/
GPX_model(const string& creator);
/**
* @brief Constructs a GPX model representing the content of a GPX file
* @param creator Creator of the model
* @param fileName File to parse and add to the model
*/
GPX_model(const string& creator, const string& fileName);
/**
* @brief Parses a file and add its content to the model
* @param fileName File to parse
* @param fileType Specify type of file, GPXM_FILE_AUTOMATIC for automatic detection
* @param overwriteMetadata If true the model metadata is overwritten with the metadata of the new file
* @return Return code, GPXM_OK on success
*/
retCode_e load(const string& fileName, fileType_e fileType = GPXM_FILE_AUTOMATIC, bool overwriteMetadata = false);
/**
* @brief Saves the content of the model to a file
* @param fileName File name
* @return Return code, GPXM_OK on success
*/
retCode_e save(const string& fileName);
/**
* @brief Updates the properties of the model
* @note Should be called when the model was changed in any way
* @param propagate If true also update the properties of
* the tracks, track segments and track points
*/
void update(bool propagate = true);
/**
* @brief Updates the properties of a given track
* @note Should be called if the track was modified in any way
* @param track Track to update
* @param propagate If true also update the properties of
* the track segments and track points
*/
void updateTrack(GPX_trkType &track, bool propagate = true);
private:
/**
* @brief Clears the metadata of the model
*/
void clearMetadata();
};
/**
* @class GPX_trkType
*
* @brief Track class holding a list of track segments
*
* @author Frederic Bourgeois <[email protected]>
* @version 1.1
* @date 10 Jan 2015
*/
class GPXMODEL_EXPORT GPX_trkType
{
public:
friend class GPX_model;
GPX_trkMetadataType metadata; /**< Information about the track */
GPX_extType extensions; /**< Extensions */
GPX_statsType stats; /**< Statistic information */
vector <GPX_trksegType> trkseg; /**< List of track segments */
/**
* @brief Constructs a new track
* @param number Track number
*/
GPX_trkType(size_t number);
private:
/**
* @brief Updates the properties of the track
* @param propagate If true also update the properties of
* the track segments and track points
*/
void update(bool propagate);
};
/**
* @class GPX_trksegType
*
* @brief Track segment class holding a list of points which are logically connected in order
*
* @author Frederic Bourgeois <[email protected]>
* @version 1.1
* @date 10 Jan 2015
*/
class GPXMODEL_EXPORT GPX_trksegType
{
public:
friend class GPX_trkType;
GPX_extType extensions; /**< Extensions */
GPX_statsType stats; /**< Statistic information */
vector <GPX_wptType> trkpt; /**< List of track points */
/**
* @brief Constructs a new track segment
*/
GPX_trksegType();
private:
/**
* @brief Updates the properties of the track segment
* @param propagate If true also update the properties of the track points
* @param trackStartTime Timestamp of the beginning of the track (used for elapsedTime)
* @param prevWpt Pointer to last track point of the previous track segment
*/
void update(bool propagate, time_t trackStartTime, const GPX_wptType* prevWpt);
};
/**
* @class GPX_wptType
*
* @brief Track point class representing a single GPS localization point
*
* @author Frederic Bourgeois <[email protected]>
* @version 1.1
* @date 10 Jan 2015
*/
class GPXMODEL_EXPORT GPX_wptType
{
public:
friend class GPX_trksegType;
string fix; /**< Type of fix ("none", "2d", "3d", "dgps" or "pps") */
int sat; /**< Number of satellites used to calculate the fix */
time_t timestamp; /**< GMT timestamp [s] */
int millisecond; /**< GMT timestamp milliseconds (0-999) [ms] */
float magvar; /**< Magnetic variation at the point [deg] */
double altitude; /**< Elevation of the point [m] */
float hdop; /**< Horizontal dilution of precision */
float vdop; /**< Vertical dilution of precision */
float pdop; /**< Position dilution of precision */
float ageofdgpsdata; /**< Number of seconds since last DGPS update */
int dgpsid; /**< ID of DGPS station used in differential correction */
float geoidheight; /**< Height of geoid above WGS84 earth ellipsoid [m] */
double latitude; /**< Latitude of the point [deg] */
double longitude; /**< Longitude of the point [deg] */
string name; /**< Name of the track point */
string cmt; /**< Comment about the point */
string desc; /**< Description of the point */
string src; /**< Source of data */
vector <GPX_linkType> links; /**< Links to additional information about the point */
string sym; /**< Symbol name */
string type; /**< Type (classification) of the point */
GPX_extType extensions; /**< Extensions */
GPX_extTPExtType extensionsGarmin; /**< Garmin extensions */
float speed; /**< Ground speed [km/h] */
float heading; /**< Heading angle [deg] */
double leglength; /**< Distance from the previous point [m] */
double distanceTot; /**< Distance from first point [km] */
unsigned int elapsedTime; /**< Time elapsed since start [s] */
/**
* @brief Constructs a new track point
*/
GPX_wptType();
/**
* @brief Clears all properties
*/
void clear();
/**
* @brief Gets the timestamp
* @return Timestamp
*/
double getTime() const;
/**
* @brief Checks if the reference track point has the same time
* @param wptRef Reference point
* @return True if both have the same time
*/
bool isSameTime(const GPX_wptType &wptRef) const;
/**
* @brief Returns a human readable string representing the heading
* @return Cardinal string
*/
const string& cardinal() const;
private:
/**
* @brief Updates the properties of the track point
* @param trackStartTime Timestamp of the beginning of the track (used for elapsedTime)
* @param prevWpt Pointer to previous track point (used for distance and speed)
* @param nextWpt Pointer to next track point (used for heading)
*/
void update(time_t trackStartTime, const GPX_wptType *prevWpt, const GPX_wptType *nextWpt);
/**
* @brief Calculates the distance from a given point and set the member distance.
* @param latitudeFrom Latitude of the point
* @param longitudeFrom Longitude of the point
* @see http://www.movable-type.co.uk/scripts/latlong.html
*/
void setDistance(double latitudeFrom, double longitudeFrom);
/**
* @brief Calculates the heading to a given point and set the member heading.
* @param latitudeTo Latitude of the point
* @param longitudeTo Longitude of the point
* @see http://www.movable-type.co.uk/scripts/latlong.html
*/
void setHeading(double latitudeTo, double longitudeTo);
};
/** @} GPX_model */
#endif // _GPX_MODEL_H_