1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Compare commits

...

3 Commits

5 changed files with 83 additions and 37 deletions

View File

@ -2,7 +2,7 @@
<map xmlns="http://www.gpxsee.org/map/1.4">
<name>USGS Imagery</name>
<url>https://basemap.nationalmap.gov/ArcGIS/rest/services/USGSImageryOnly/MapServer/tile/$z/$y/$x</url>
<zoom min="2" max="15"/>
<zoom min="2" max="16"/>
<bounds bottom="0" top="74"/>
<copyright>Map services and data available from U.S. Geological Survey, National Geospatial Program.</copyright>
</map>

View File

@ -2,6 +2,6 @@
<map xmlns="http://www.gpxsee.org/map/1.4">
<name>USGS Topo</name>
<url>https://basemap.nationalmap.gov/arcgis/rest/services/USGSTopo/MapServer/tile/$z/$y/$x</url>
<zoom min="2" max="15"/>
<zoom min="2" max="16"/>
<copyright>Map services and data available from U.S. Geological Survey, National Geospatial Program.</copyright>
</map>

View File

@ -32,7 +32,12 @@ static bool isZIP(QFile *file)
qreal KMLParser::number()
{
bool res;
qreal ret = _reader.readElementText().toDouble(&res);
QString str(_reader.readElementText());
if (str.isEmpty())
return NAN;
qreal ret = str.toDouble(&res);
if (!res)
_reader.raiseError(QString("Invalid %1").arg(
_reader.name().toString()));
@ -59,6 +64,8 @@ bool KMLParser::coord(Trackpoint &trackpoint)
qreal val[3];
bool res;
if (data.isEmpty())
return true;
sp = data.constData();
ep = sp + data.size();
@ -331,9 +338,9 @@ void KMLParser::point(Waypoint &waypoint)
_reader.raiseError("Missing Point coordinates");
}
void KMLParser::heartRate(SegmentData &segment, int start)
void KMLParser::heartRate(SegmentData &segment)
{
int i = start;
int i = 0;
const char error[] = "Heartrate data count mismatch";
while (_reader.readNextStartElement()) {
@ -348,13 +355,13 @@ void KMLParser::heartRate(SegmentData &segment, int start)
_reader.skipCurrentElement();
}
if (i != segment.size())
if (!_reader.error() && i != segment.size())
_reader.raiseError(error);
}
void KMLParser::cadence(SegmentData &segment, int start)
void KMLParser::cadence(SegmentData &segment)
{
int i = start;
int i = 0;
const char error[] = "Cadence data count mismatch";
while (_reader.readNextStartElement()) {
@ -369,13 +376,13 @@ void KMLParser::cadence(SegmentData &segment, int start)
_reader.skipCurrentElement();
}
if (i != segment.size())
if (!_reader.error() && i != segment.size())
_reader.raiseError(error);
}
void KMLParser::speed(SegmentData &segment, int start)
void KMLParser::speed(SegmentData &segment)
{
int i = start;
int i = 0;
const char error[] = "Speed data count mismatch";
while (_reader.readNextStartElement()) {
@ -390,13 +397,13 @@ void KMLParser::speed(SegmentData &segment, int start)
_reader.skipCurrentElement();
}
if (i != segment.size())
if (!_reader.error() && i != segment.size())
_reader.raiseError(error);
}
void KMLParser::temperature(SegmentData &segment, int start)
void KMLParser::temperature(SegmentData &segment)
{
int i = start;
int i = 0;
const char error[] = "Temperature data count mismatch";
while (_reader.readNextStartElement()) {
@ -411,25 +418,49 @@ void KMLParser::temperature(SegmentData &segment, int start)
_reader.skipCurrentElement();
}
if (i != segment.size())
if (!_reader.error() && i != segment.size())
_reader.raiseError(error);
}
void KMLParser::schemaData(SegmentData &segment, int start)
void KMLParser::power(SegmentData &segment)
{
int i = 0;
const char error[] = "Power data count mismatch";
while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("value")) {
if (i < segment.size())
segment[i++].setPower(number());
else {
_reader.raiseError(error);
return;
}
} else
_reader.skipCurrentElement();
}
if (!_reader.error() && i != segment.size())
_reader.raiseError(error);
}
void KMLParser::schemaData(SegmentData &segment)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("SimpleArrayData")) {
QXmlStreamAttributes attr = _reader.attributes();
QString name(attr.value("name").toString());
// There are files using capitalized names in the wild!
QString name(attr.value("name").toString().toLower());
if (name == QLatin1String("Heartrate"))
heartRate(segment, start);
else if (name == QLatin1String("Cadence"))
cadence(segment, start);
else if (name == QLatin1String("Speed"))
speed(segment, start);
else if (name == QLatin1String("Temperature"))
temperature(segment, start);
if (name == QLatin1String("heartrate"))
heartRate(segment);
else if (name == QLatin1String("cadence"))
cadence(segment);
else if (name == QLatin1String("speed"))
speed(segment);
else if (name == QLatin1String("temperature"))
temperature(segment);
else if (name == QLatin1String("power"))
power(segment);
else
_reader.skipCurrentElement();
} else
@ -437,11 +468,11 @@ void KMLParser::schemaData(SegmentData &segment, int start)
}
}
void KMLParser::extendedData(SegmentData &segment, int start)
void KMLParser::extendedData(SegmentData &segment)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("SchemaData"))
schemaData(segment, start);
schemaData(segment);
else
_reader.skipCurrentElement();
}
@ -450,8 +481,7 @@ void KMLParser::extendedData(SegmentData &segment, int start)
void KMLParser::track(SegmentData &segment)
{
const char error[] = "gx:coord/when element count mismatch";
int first = segment.size();
int i = first;
int i = 0;
while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("when")) {
@ -467,13 +497,20 @@ void KMLParser::track(SegmentData &segment)
}
i++;
} else if (_reader.name() == QLatin1String("ExtendedData"))
extendedData(segment, first);
extendedData(segment);
else
_reader.skipCurrentElement();
}
if (i != segment.size())
if (i != segment.size()) {
_reader.raiseError(error);
return;
}
// empty (invalid) coordinates are allowed per KML specification!
for (int i = 0; i < segment.size(); i++)
if (segment.at(i).coordinates().isNull())
segment.remove(i);
}
void KMLParser::multiTrack(TrackData &t)

View File

@ -53,12 +53,13 @@ private:
bool lineCoordinates(SegmentData &segment);
bool polygonCoordinates(QVector<Coordinates> &points);
bool coord(Trackpoint &trackpoint);
void extendedData(SegmentData &segment, int start);
void schemaData(SegmentData &segment, int start);
void heartRate(SegmentData &segment, int start);
void cadence(SegmentData &segment, int start);
void speed(SegmentData &segment, int start);
void temperature(SegmentData &segment, int start);
void extendedData(SegmentData &segment);
void schemaData(SegmentData &segment);
void heartRate(SegmentData &segment);
void cadence(SegmentData &segment);
void speed(SegmentData &segment);
void temperature(SegmentData &segment);
void power(SegmentData &segment);
QDateTime timeStamp();
qreal number();
QDateTime time();

View File

@ -61,6 +61,9 @@ bool PLTParser::parse(QFile *file, QList<TrackData> &tracks,
}
} else if (_errorLine == 5) {
QList<QByteArray> list = line.split(',');
if (list.size() >= 3 && !list.at(2).isEmpty())
track.setStyle(LineStyle(QColor(list.at(2).toUInt()),
list.at(1).toUInt()));
if (list.size() >= 4)
track.setName(list.at(3));
} else if (_errorLine > 6) {
@ -166,6 +169,9 @@ bool RTEParser::parse(QFile *file, QList<TrackData> &tracks,
QByteArray description(list.at(3).trimmed());
routes.last().setDescription(decode(description));
}
if (list.size() >= 5 && !list.at(4).isEmpty())
routes.last().setStyle(
LineStyle(QColor(list.at(4).toUInt())));
} else if (list.at(0).trimmed() == "W") {
if (!record || list.size() < 7) {
_errorString = "Parse error";
@ -282,6 +288,8 @@ bool WPTParser::parse(QFile *file, QList<TrackData> &tracks,
delphi2unixMS(date)));
}
}
if (list.size() >= 9 && !list.at(8).isEmpty())
wp.setStyle(PointStyle(QColor(list.at(8).toUInt())));
if (list.size() >= 11) {
QByteArray description(list.at(10).trimmed());
if (!description.isEmpty())