forked from NetworkAndSoftware/gopro2gpx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpx.c
48 lines (41 loc) · 1.31 KB
/
gpx.c
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
// Sun Jul 21 09:34:39 DST 2019
// Copyright Michiel van Wessem
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "platform.h"
#include "gpx.h"
void write_gpx_header(FILE* output)
{
fprintf(output, "\
<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n\
<gpx creator=\"gopro2gpx\" version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n\
<trk>\n\
<name>Untitled</name>\n\
<trkseg>\n");
}
void write_gpx_footer(FILE* output)
{
fprintf(output, "\
</trkseg>\n\
</trk>\n\
</gpx>");
}
void write_gpx_track_point(FILE* output, const double latitude, const double longitude, const double elevation_wgs84, const double speed_ground, const double speed_3d, const double time)
{
char s[256];
time_t seconds = (time_t) floor(time);
const double fraction = time - seconds;
const size_t n = strftime(s, sizeof s, "%FT%T", gmtime(&seconds));
if (n < sizeof(s))
snprintf(s + n, (sizeof s) - n, ".%03.0fZ", fraction * 1000);
fprintf(output, "\
<trkpt lat=\"%f\" lon=\"%f\">\n\
<ele>%f</ele>\n\
<time>%s</time>\n\
</trkpt>\n\
",
latitude, longitude, elevation_wgs84, s);
}