-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracklist.cpp
93 lines (76 loc) · 2.38 KB
/
tracklist.cpp
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
#include "tracklist.h"
#include "exception.h"
#include <QtConcurrentMap>
#include <QtAlgorithms>
#include <QtXml>
TrackList::TrackList()
{
}
TrackList::TrackList(QFile &input)
{
if (!input.exists()) {
throw new Exception(QString("File not found: <%1>").arg(input.fileName()));
}
QDomDocument d;
d.setContent(&input);
QDomElement root = d.documentElement();
QDomElement pointNode, segmentNode, trackNode;
Track t;
// <gpx
// <trk><name>АВГ-30-09 14:15:47</name>
// <trkseg>
// <trkpt lat="54.11111" lon="37.11111"><ele>112.13</ele><time>2009-08-29T15:36:42Z</time></trkpt>
tracks.clear();
trackNode = root.firstChildElement("trk");
for (; !trackNode.isNull(); trackNode = trackNode.nextSiblingElement("trk")) {
t.name = trackNode.firstChildElement("name").text();
segmentNode = trackNode.firstChildElement("trkseg");
for (; !segmentNode.isNull(); segmentNode = segmentNode.nextSiblingElement("trkseg")) {
t.points.clear();
pointNode = segmentNode.firstChildElement("trkpt");
for (; !pointNode.isNull(); pointNode = pointNode.nextSiblingElement("trkpt")) {
t.points.append(TrackPoint(
pointNode.attribute("lat").toFloat(),
pointNode.attribute("lon").toFloat(),
QDateTime::fromString(pointNode.firstChildElement("time").text(), Qt::ISODate)
));
}
qSort(t.points);
if (t.points.length()) {
tracks.append(t);
}
}
}
}
QString TrackList::toJSON() const
{
QStringList jsons = QtConcurrent::blockingMapped<QStringList>(tracks, &Track_toJSON);
return QString("[%1]").arg(jsons.join(","));
}
BBox TrackList::getBBox() const
{
if (!tracks.length()) {
return BBox();
}
BBox cur, max;
Track t = tracks.first();
max = t.getBBox();
QList<Track>::const_iterator i = tracks.begin();
++i;
for (; i != tracks.end(); ++i) {
cur = (*i).getBBox();
if (cur.left < max.left) {
max.left = cur.left;
}
if (cur.top < max.top) {
max.top = cur.top;
}
if (cur.right > max.right) {
max.right = cur.right;
}
if (cur.bottom > max.bottom) {
max.bottom = cur.bottom;
}
}
return max;
}