-
Notifications
You must be signed in to change notification settings - Fork 17
/
CoordsGpx.cpp
140 lines (131 loc) · 5.15 KB
/
CoordsGpx.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
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
/* This file is part of TSRE5.
*
* TSRE5 - train sim game engine and MSTS/OR Editors.
* Copyright (C) 2016 Piotr Gadecki <[email protected]>
*
* Licensed under GNU General Public License 3.0 or later.
*
* See LICENSE.md or https://www.gnu.org/licenses/gpl.html
*/
#include "CoordsGpx.h"
#include <QFile>
#include "GLMatrix.h"
#include <math.h>
#include "ParserX.h"
#include <QDebug>
#include <cstdlib>
#include "Vector2f.h"
#include "TerrainLib.h"
#include "TS.h"
#include "Game.h"
#include "FileFunctions.h"
#include "ReadFile.h"
#include "GeoCoordinates.h"
CoordsGpx::CoordsGpx(QString path) {
qDebug() << "gpx!";
loaded = false;
QFile file(path);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
qDebug() << "no file" << file.errorString();
return;
}
qDebug() << "file";
QByteArray data = file.readAll();
bool placemark = false;
bool line = false;
bool coordinates = false;
bool nametext = false;
int iii = 0, uuu = 0;
IghCoordinate* igh;
PreciseTileCoordinate* ppp;
QXmlStreamReader reader((data));
reader.readNext();
QString name;
QXmlStreamAttributes attr;
while (!reader.isEndDocument()) {
if (reader.isStartElement()) {
name = reader.name().toString();
attr = reader.attributes();
if (name.toUpper() == ("WPT")) {
placemark = true;
markerList.push_back(Marker());
float lat = 0;
float lon = 0;
if(attr.size() == 2){
if(attr[0].name().toString().toUpper() == "LAT")
lat = attr[0].value().toFloat();
if(attr[0].name().toString().toUpper() == "LON")
lon = attr[0].value().toFloat();
if(attr[1].name().toString().toUpper() == "LAT")
lat = attr[1].value().toFloat();
if(attr[1].name().toString().toUpper() == "LON")
lon = attr[1].value().toFloat();
igh = Game::GeoCoordConverter->ConvertToInternal(lat, lon);
ppp = Game::GeoCoordConverter->ConvertToTile(igh);
markerList.back().lat = lat;
markerList.back().lon = lon;
markerList.back().type = 0;
markerList.back().tileX.push_back(ppp->TileX);
markerList.back().tileZ.push_back(ppp->TileZ);
markerList.back().x.push_back(ppp->X*2048-1024);
markerList.back().y.push_back(0);
markerList.back().z.push_back(ppp->Z*2048-1024);
}
} else if (name.toUpper() == ("TRK")) {
placemark = true;
markerList.push_back(Marker());
} else if (name.toUpper() == ("TRKPT")) {
float lat = 0;
float lon = 0;
if(attr.size() == 2){
if(attr[0].name().toString().toUpper() == "LAT")
lat = attr[0].value().toFloat();
if(attr[0].name().toString().toUpper() == "LON")
lon = attr[0].value().toFloat();
if(attr[1].name().toString().toUpper() == "LAT")
lat = attr[1].value().toFloat();
if(attr[1].name().toString().toUpper() == "LON")
lon = attr[1].value().toFloat();
igh = Game::GeoCoordConverter->ConvertToInternal(lat, lon);
ppp = Game::GeoCoordConverter->ConvertToTile(igh);
if(markerList.back().tileX.size() == 0){
markerList.back().lat = lat;
markerList.back().lon = lon;
markerList.back().type = 0;
}
markerList.back().tileX.push_back(ppp->TileX);
markerList.back().tileZ.push_back(ppp->TileZ);
markerList.back().x.push_back(ppp->X*2048-1024);
markerList.back().y.push_back(0);
markerList.back().z.push_back(ppp->Z*2048-1024);
}
} else if (name.toUpper() == ("NAME")) {
if(placemark){
nametext = true;
}
}
} else if (reader.isEndElement()) {
name = reader.name().toString();
if (name.toUpper() == ("WPT")) {
placemark = false;
}
if (name.toUpper() == ("TRK")) {
placemark = false;
}
if (name.toUpper() == ("NAME")) {
if(placemark){
nametext = false;
}
}
} else if (reader.isCharacters()) {
if(nametext){
//qDebug() << reader.text();
markerList.back().name = reader.text().toString();
}
}
reader.readNext();
}
loaded = true;
}
CoordsGpx::~CoordsGpx() {
}