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

Added support for OziExplorer data files

This commit is contained in:
Martin Tůma 2018-04-13 20:54:38 +02:00
parent f64e88290d
commit f8009b0151
11 changed files with 364 additions and 7 deletions

View File

@ -123,7 +123,11 @@ HEADERS += src/config.h \
src/map/wmsmap.h \ src/map/wmsmap.h \
src/map/wms.h \ src/map/wms.h \
src/map/crs.h \ src/map/crs.h \
src/map/coordinatesystem.h src/map/coordinatesystem.h \
src/data/pltparser.h \
src/data/date.h \
src/data/wptparser.h \
src/data/rteparser.h
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/common/coordinates.cpp \ src/common/coordinates.cpp \
src/common/rectc.cpp \ src/common/rectc.cpp \
@ -216,7 +220,10 @@ SOURCES += src/main.cpp \
src/map/wmsmap.cpp \ src/map/wmsmap.cpp \
src/map/wms.cpp \ src/map/wms.cpp \
src/map/crs.cpp \ src/map/crs.cpp \
src/map/coordinatesystem.cpp src/map/coordinatesystem.cpp \
src/data/pltparser.cpp \
src/data/wptparser.cpp \
src/data/rteparser.cpp
RESOURCES += gpxsee.qrc RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts \ TRANSLATIONS = lang/gpxsee_cs.ts \
lang/gpxsee_sv.ts \ lang/gpxsee_sv.ts \

View File

@ -1,9 +1,9 @@
#include "csvparser.h" #include "csvparser.h"
bool CSVParser::parse(QFile *file, QList<TrackData> &track, bool CSVParser::parse(QFile *file, QList<TrackData> &tracks,
QList<RouteData> &routes, QList<Waypoint> &waypoints) QList<RouteData> &routes, QList<Waypoint> &waypoints)
{ {
Q_UNUSED(track); Q_UNUSED(tracks);
Q_UNUSED(routes); Q_UNUSED(routes);
bool res; bool res;

View File

@ -8,7 +8,7 @@ class CSVParser : public Parser
public: public:
CSVParser() : _errorLine(0) {} CSVParser() : _errorLine(0) {}
bool parse(QFile *file, QList<TrackData> &track, QList<RouteData> &routes, bool parse(QFile *file, QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints); QList<Waypoint> &waypoints);
QString errorString() const {return _errorString;} QString errorString() const {return _errorString;}
int errorLine() const {return _errorLine;} int errorLine() const {return _errorLine;}

View File

@ -8,6 +8,9 @@
#include "fitparser.h" #include "fitparser.h"
#include "igcparser.h" #include "igcparser.h"
#include "nmeaparser.h" #include "nmeaparser.h"
#include "pltparser.h"
#include "wptparser.h"
#include "rteparser.h"
#include "data.h" #include "data.h"
@ -18,6 +21,9 @@ static FITParser fit;
static CSVParser csv; static CSVParser csv;
static IGCParser igc; static IGCParser igc;
static NMEAParser nmea; static NMEAParser nmea;
static PLTParser plt;
static WPTParser wpt;
static RTEParser rte;
static QHash<QString, Parser*> parsers() static QHash<QString, Parser*> parsers()
{ {
@ -30,6 +36,9 @@ static QHash<QString, Parser*> parsers()
hash.insert("csv", &csv); hash.insert("csv", &csv);
hash.insert("igc", &igc); hash.insert("igc", &igc);
hash.insert("nmea", &nmea); hash.insert("nmea", &nmea);
hash.insert("plt", &plt);
hash.insert("wpt", &wpt);
hash.insert("rte", &rte);
return hash; return hash;
} }
@ -100,11 +109,14 @@ bool Data::loadFile(const QString &fileName)
QString Data::formats() QString Data::formats()
{ {
return return
tr("Supported files") + " (*.csv *.fit *.gpx *.igc *.kml *.nmea *.tcx);;" tr("Supported files")
+ " (*.csv *.fit *.gpx *.igc *.kml *.nmea *.plt *.rte *.tcx *.wpt);;"
+ tr("CSV files") + " (*.csv);;" + tr("FIT files") + " (*.fit);;" + tr("CSV files") + " (*.csv);;" + tr("FIT files") + " (*.fit);;"
+ tr("GPX files") + " (*.gpx);;" + tr("IGC files") + " (*.igc);;" + tr("GPX files") + " (*.gpx);;" + tr("IGC files") + " (*.igc);;"
+ tr("KML files") + " (*.kml);;" + tr("NMEA files") + " (*.nmea);;" + tr("KML files") + " (*.kml);;" + tr("NMEA files") + " (*.nmea);;"
+ tr("TCX files") + " (*.tcx);;" + tr("All files") + "(*)"; + tr("PLT files") + " (*.plt);;" + tr("RTE files") + " (*.rte);;"
+ tr("TCX files") + " (*.tcx);;" + tr("WPT files") + " (*.wpt);;"
+ tr("All files") + " (*)";
} }
QStringList Data::filter() QStringList Data::filter()

14
src/data/date.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef DATE_H
#define DATE_H
#include <QtGlobal>
namespace Date
{
inline qint64 delphi2unixMS(double date)
{
return (qint64)((date - 25569.0) * 86400000);
}
}
#endif // DATE_H

83
src/data/pltparser.cpp Normal file
View File

@ -0,0 +1,83 @@
#include "map/gcs.h"
#include "date.h"
#include "pltparser.h"
bool PLTParser::parse(QFile *file, QList<TrackData> &tracks,
QList<RouteData> &routes, QList<Waypoint> &waypoints)
{
Q_UNUSED(waypoints);
Q_UNUSED(routes);
bool res;
const GCS *gcs;
_errorLine = 1;
_errorString.clear();
tracks.append(TrackData());
TrackData &track = tracks.last();
while (!file->atEnd()) {
QByteArray line = file->readLine();
if (_errorLine == 1) {
if (!line.trimmed().startsWith("OziExplorer Track Point File")) {
_errorString = "Not a PLT file";
return false;
}
} else if (_errorLine == 2) {
if (!(gcs = GCS::gcs(QString(line.trimmed())))) {
_errorString = "Invalid/unknown datum";
return false;
}
} else if (_errorLine == 5) {
QList<QByteArray> list = line.split(',');
if (list.size() >= 4)
track.setName(list.at(3));
} else if (_errorLine > 6) {
QList<QByteArray> list = line.split(',');
if (list.size() < 2) {
_errorString = "Parse error";
return false;
}
qreal lat = list.at(0).trimmed().toDouble(&res);
if (!res || (lat < -90.0 || lat > 90.0)) {
_errorString = "Invalid latitude";
return false;
}
qreal lon = list.at(1).trimmed().toDouble(&res);
if (!res || (lon < -180.0 || lon > 180.0)) {
_errorString = "Invalid longitude";
return false;
}
Trackpoint tp(gcs->toWGS84(Coordinates(lon, lat)));
if (list.size() >= 4) {
double elevation = list.at(3).trimmed().toDouble(&res);
if (!res) {
_errorString = "Invalid elevation";
return false;
}
if (elevation != -777)
tp.setElevation(elevation * 0.3048);
}
if (list.size() >= 5) {
double date = list.at(4).trimmed().toDouble(&res);
if (!res) {
_errorString = "Invalid date";
return false;
}
tp.setTimestamp(QDateTime::fromMSecsSinceEpoch(
Date::delphi2unixMS(date)));
}
track.append(tp);
}
_errorLine++;
}
return true;
}

21
src/data/pltparser.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef PLTPARSER_H
#define PLTPARSER_H
#include "parser.h"
class PLTParser : public Parser
{
public:
PLTParser() : _errorLine(0) {}
bool parse(QFile *file, QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints);
QString errorString() const {return _errorString;}
int errorLine() const {return _errorLine;}
private:
QString _errorString;
int _errorLine;
};
#endif // PLTPARSER_H

95
src/data/rteparser.cpp Normal file
View File

@ -0,0 +1,95 @@
#include "map/gcs.h"
#include "date.h"
#include "rteparser.h"
bool RTEParser::parse(QFile *file, QList<TrackData> &tracks,
QList<RouteData> &routes, QList<Waypoint> &waypoints)
{
Q_UNUSED(waypoints);
Q_UNUSED(tracks);
bool res, record = false;
const GCS *gcs;
_errorLine = 1;
_errorString.clear();
while (!file->atEnd()) {
QByteArray line = file->readLine();
if (_errorLine == 1) {
if (!line.trimmed().startsWith("OziExplorer Route File")) {
_errorString = "Not a RTE file";
return false;
}
} else if (_errorLine == 2) {
if (!(gcs = GCS::gcs(QString(line.trimmed())))) {
_errorString = "Invalid/unknown datum";
return false;
}
} else if (_errorLine > 4) {
QList<QByteArray> list = line.split(',');
if (list.size() < 2) {
_errorString = "Parse error";
return false;
}
if (list.at(0).trimmed() == "R") {
routes.append(RouteData());
record = true;
if (list.size() >= 3)
routes.last().setName(list.at(2).trimmed()
.replace('\xD1', ','));
if (list.size() >= 4)
routes.last().setDescription(list.at(3).trimmed()
.replace('\xD1', ','));
} else if (list.at(0).trimmed() == "W") {
if (!record || list.size() < 7) {
_errorString = "Parse error";
return false;
}
qreal lat = list.at(5).trimmed().toDouble(&res);
if (!res || (lat < -90.0 || lat > 90.0)) {
_errorString = "Invalid latitude";
return false;
}
qreal lon = list.at(6).trimmed().toDouble(&res);
if (!res || (lon < -180.0 || lon > 180.0)) {
_errorString = "Invalid longitude";
return false;
}
Waypoint wp(gcs->toWGS84(Coordinates(lon, lat)));
QString name(list.at(4).trimmed().replace('\xD1', ','));
if (!name.isEmpty())
wp.setName(name);
if (list.size() >= 8) {
double date = list.at(7).trimmed().toDouble(&res);
if (!res) {
_errorString = "Invalid date";
return false;
}
wp.setTimestamp(QDateTime::fromMSecsSinceEpoch(
Date::delphi2unixMS(date)));
}
if (list.size() >= 14) {
QString desc(list.at(13).trimmed().replace('\xD1', ','));
wp.setDescription(desc);
}
routes.last().append(wp);
} else {
_errorString = "Parse error";
return false;
}
}
_errorLine++;
}
return true;
}

21
src/data/rteparser.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef RTEPARSER_H
#define RTEPARSER_H
#include "parser.h"
class RTEParser : public Parser
{
public:
RTEParser() : _errorLine(0) {}
bool parse(QFile *file, QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints);
QString errorString() const {return _errorString;}
int errorLine() const {return _errorLine;}
private:
QString _errorString;
int _errorLine;
};
#endif // RTEPARSER_H

83
src/data/wptparser.cpp Normal file
View File

@ -0,0 +1,83 @@
#include "map/gcs.h"
#include "date.h"
#include "wptparser.h"
bool WPTParser::parse(QFile *file, QList<TrackData> &tracks,
QList<RouteData> &routes, QList<Waypoint> &waypoints)
{
Q_UNUSED(tracks);
Q_UNUSED(routes);
bool res;
const GCS *gcs;
_errorLine = 1;
_errorString.clear();
while (!file->atEnd()) {
QByteArray line = file->readLine();
if (_errorLine == 1) {
if (!line.trimmed().startsWith("OziExplorer Waypoint File")) {
_errorString = "Not a WPT file";
return false;
}
} else if (_errorLine == 2) {
if (!(gcs = GCS::gcs(QString(line.trimmed())))) {
_errorString = "Invalid/unknown datum";
return false;
}
} else if (_errorLine > 4) {
QList<QByteArray> list = line.split(',');
if (list.size() < 4) {
_errorString = "Parse error";
return false;
}
qreal lat = list.at(2).trimmed().toDouble(&res);
if (!res || (lat < -90.0 || lat > 90.0)) {
_errorString = "Invalid latitude";
return false;
}
qreal lon = list.at(3).trimmed().toDouble(&res);
if (!res || (lon < -180.0 || lon > 180.0)) {
_errorString = "Invalid longitude";
return false;
}
Waypoint wp(gcs->toWGS84(Coordinates(lon, lat)));
QString name(list.at(1).trimmed().replace('\xD1', ','));
if (!name.isEmpty())
wp.setName(name);
if (list.size() >= 5) {
double date = list.at(4).trimmed().toDouble(&res);
if (!res) {
_errorString = "Invalid date";
return false;
}
wp.setTimestamp(QDateTime::fromMSecsSinceEpoch(
Date::delphi2unixMS(date)));
}
if (list.size() >= 11) {
QString desc(list.at(10).trimmed().replace('\xD1', ','));
if (!desc.isEmpty())
wp.setDescription(desc);
} if (list.size() >= 15) {
double elevation = list.at(14).trimmed().toDouble(&res);
if (!res) {
_errorString = "Invalid elevation";
return false;
}
if (elevation != -777)
wp.setElevation(elevation * 0.3048);
}
waypoints.append(wp);
}
_errorLine++;
}
return true;
}

21
src/data/wptparser.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef WPTPARSER_H
#define WPTPARSER_H
#include "parser.h"
class WPTParser : public Parser
{
public:
WPTParser() : _errorLine(0) {}
bool parse(QFile *file, QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints);
QString errorString() const {return _errorString;}
int errorLine() const {return _errorLine;}
private:
QString _errorString;
int _errorLine;
};
#endif // WPTPARSER_H