1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Compare commits

..

No commits in common. "f6a14e600899cefd32e679f2e2cc7ff121a875c5" and "8780a40b9fba474adf7846c4b9dcec22f0233ae3" have entirely different histories.

6 changed files with 62 additions and 58 deletions

View File

@ -478,7 +478,8 @@ bool FITParser::parse(QFile *file, QList<TrackData> &tracks,
if (!parseRecord(ctx)) if (!parseRecord(ctx))
return false; return false;
tracks.append(ctx.segment); tracks.append(TrackData());
tracks.last().append(ctx.segment);
return true; return true;
} }

View File

@ -182,7 +182,7 @@ GeoJSONParser::Type GeoJSONParser::type(const QJsonObject &json)
} }
bool GeoJSONParser::point(const QJsonObject &object, const Projection &parent, bool GeoJSONParser::point(const QJsonObject &object, const Projection &parent,
const QJsonValue &properties, QVector<Waypoint> &waypoints) const QJsonValue &properties, Waypoint &waypoint)
{ {
if (!object.contains("coordinates")) { if (!object.contains("coordinates")) {
_errorString = "Missing Point coordinates array"; _errorString = "Missing Point coordinates array";
@ -203,11 +203,11 @@ bool GeoJSONParser::point(const QJsonObject &object, const Projection &parent,
return false; return false;
} }
Waypoint waypoint(c); waypoint.setCoordinates(c);
if (coordinates.count() == 3 && coordinates.at(2).isDouble()) if (coordinates.count() == 3 && coordinates.at(2).isDouble())
waypoint.setElevation(coordinates.at(2).toDouble()); waypoint.setElevation(coordinates.at(2).toDouble());
setWaypointProperties(waypoint, properties); setWaypointProperties(waypoint, properties);
waypoints.append(waypoint);
return true; return true;
} }
@ -223,6 +223,8 @@ bool GeoJSONParser::multiPoint(const QJsonObject &object,
if (object["coordinates"].isNull()) if (object["coordinates"].isNull())
return true; return true;
QJsonArray coordinates(object["coordinates"].toArray()); QJsonArray coordinates(object["coordinates"].toArray());
if (coordinates.isEmpty())
return true;
Projection proj; Projection proj;
if (!crs(object, proj)) if (!crs(object, proj))
return false; return false;
@ -232,6 +234,8 @@ bool GeoJSONParser::multiPoint(const QJsonObject &object,
_errorString = "Invalid MultiPoint data"; _errorString = "Invalid MultiPoint data";
return false; return false;
} else { } else {
waypoints.resize(waypoints.size() + 1);
QJsonArray data(coordinates.at(i).toArray()); QJsonArray data(coordinates.at(i).toArray());
Coordinates c(::coordinates(data, proj.isNull() ? parent : proj)); Coordinates c(::coordinates(data, proj.isNull() ? parent : proj));
if (!c.isValid()) { if (!c.isValid()) {
@ -239,11 +243,11 @@ bool GeoJSONParser::multiPoint(const QJsonObject &object,
return false; return false;
} }
Waypoint waypoint(c); waypoints.last().setCoordinates(c);
if (data.count() == 3 && data.at(2).isDouble()) if (data.count() == 3 && data.at(2).isDouble())
waypoint.setElevation(data.at(2).toDouble()); waypoints.last().setElevation(data.at(2).toDouble());
setWaypointProperties(waypoint, properties);
waypoints.append(waypoint); setWaypointProperties(waypoints.last(), properties);
} }
} }
@ -251,8 +255,7 @@ bool GeoJSONParser::multiPoint(const QJsonObject &object,
} }
bool GeoJSONParser::lineString(const QJsonObject &object, bool GeoJSONParser::lineString(const QJsonObject &object,
const Projection &parent, const QJsonValue &properties, const Projection &parent, const QJsonValue &properties, TrackData &track)
QList<TrackData> &tracks)
{ {
if (!object.contains("coordinates")) { if (!object.contains("coordinates")) {
_errorString = "Missing LineString coordinates array"; _errorString = "Missing LineString coordinates array";
@ -266,7 +269,8 @@ bool GeoJSONParser::lineString(const QJsonObject &object,
Projection proj; Projection proj;
if (!crs(object, proj)) if (!crs(object, proj))
return false; return false;
SegmentData sd;
track.append(SegmentData());
for (int i = 0; i < coordinates.size(); i++) { for (int i = 0; i < coordinates.size(); i++) {
if (!coordinates.at(i).isArray()) { if (!coordinates.at(i).isArray()) {
@ -284,19 +288,16 @@ bool GeoJSONParser::lineString(const QJsonObject &object,
Trackpoint t(c); Trackpoint t(c);
if (data.count() == 3 && data.at(2).isDouble()) if (data.count() == 3 && data.at(2).isDouble())
t.setElevation(data.at(2).toDouble()); t.setElevation(data.at(2).toDouble());
sd.append(t); track.last().append(t);
} }
TrackData track(sd);
setTrackProperties(track, properties); setTrackProperties(track, properties);
tracks.append(track);
return true; return true;
} }
bool GeoJSONParser::multiLineString(const QJsonObject &object, bool GeoJSONParser::multiLineString(const QJsonObject &object,
const Projection &parent, const QJsonValue &properties, const Projection &parent, const QJsonValue &properties, TrackData &track)
QList<TrackData> &tracks)
{ {
if (!object.contains("coordinates")) { if (!object.contains("coordinates")) {
_errorString = "Missing MultiLineString coordinates array"; _errorString = "Missing MultiLineString coordinates array";
@ -310,14 +311,13 @@ bool GeoJSONParser::multiLineString(const QJsonObject &object,
Projection proj; Projection proj;
if (!crs(object, proj)) if (!crs(object, proj))
return false; return false;
TrackData track;
for (int i = 0; i < coordinates.size(); i++) { for (int i = 0; i < coordinates.size(); i++) {
if (!coordinates.at(i).isArray()) { if (!coordinates.at(i).isArray()) {
_errorString = "Invalid MultiLineString data"; _errorString = "Invalid MultiLineString data";
return false; return false;
} else { } else {
SegmentData sd; track.append(SegmentData());
QJsonArray ls(coordinates.at(i).toArray()); QJsonArray ls(coordinates.at(i).toArray());
for (int j = 0; j < ls.size(); j++) { for (int j = 0; j < ls.size(); j++) {
@ -336,21 +336,18 @@ bool GeoJSONParser::multiLineString(const QJsonObject &object,
Trackpoint t(c); Trackpoint t(c);
if (data.count() == 3 && data.at(2).isDouble()) if (data.count() == 3 && data.at(2).isDouble())
t.setElevation(data.at(2).toDouble()); t.setElevation(data.at(2).toDouble());
sd.append(t); track.last().append(t);
} }
track.append(sd);
} }
} }
setTrackProperties(track, properties); setTrackProperties(track, properties);
tracks.append(track);
return true; return true;
} }
bool GeoJSONParser::polygon(const QJsonObject &object, const Projection &parent, bool GeoJSONParser::polygon(const QJsonObject &object, const Projection &parent,
const QJsonValue &properties, QList<Area> &areas) const QJsonValue &properties, Area &area)
{ {
if (!object.contains("coordinates")) { if (!object.contains("coordinates")) {
_errorString = "Missing Polygon coordinates array"; _errorString = "Missing Polygon coordinates array";
@ -393,15 +390,14 @@ bool GeoJSONParser::polygon(const QJsonObject &object, const Projection &parent,
pg.append(data); pg.append(data);
} }
Area area(pg); area.append(pg);
setAreaProperties(area, properties); setAreaProperties(area, properties);
areas.append(area);
return true; return true;
} }
bool GeoJSONParser::multiPolygon(const QJsonObject &object, bool GeoJSONParser::multiPolygon(const QJsonObject &object,
const Projection &parent, const QJsonValue &properties, QList<Area> &areas) const Projection &parent, const QJsonValue &properties, Area &area)
{ {
if (!object.contains("coordinates")) { if (!object.contains("coordinates")) {
_errorString = "Missing MultiPolygon coordinates array"; _errorString = "Missing MultiPolygon coordinates array";
@ -415,8 +411,6 @@ bool GeoJSONParser::multiPolygon(const QJsonObject &object,
Projection proj; Projection proj;
if (!crs(object, proj)) if (!crs(object, proj))
return false; return false;
Area area;
for (int i = 0; i < coordinates.size(); i++) { for (int i = 0; i < coordinates.size(); i++) {
if (!coordinates.at(i).isArray()) { if (!coordinates.at(i).isArray()) {
@ -458,7 +452,6 @@ bool GeoJSONParser::multiPolygon(const QJsonObject &object,
} }
setAreaProperties(area, properties); setAreaProperties(area, properties);
areas.append(area);
return true; return true;
} }
@ -482,8 +475,9 @@ bool GeoJSONParser::geometryCollection(const QJsonObject &object,
switch (type(geometry)) { switch (type(geometry)) {
case Point: case Point:
waypoints.resize(waypoints.size() + 1);
if (!point(geometry, proj.isNull() ? parent : proj, properties, if (!point(geometry, proj.isNull() ? parent : proj, properties,
waypoints)) waypoints.last()))
return false; return false;
break; break;
case MultiPoint: case MultiPoint:
@ -492,23 +486,27 @@ bool GeoJSONParser::geometryCollection(const QJsonObject &object,
return false; return false;
break; break;
case LineString: case LineString:
tracks.append(TrackData());
if (!lineString(geometry, proj.isNull() ? parent : proj, if (!lineString(geometry, proj.isNull() ? parent : proj,
properties, tracks)) properties, tracks.last()))
return false; return false;
break; break;
case MultiLineString: case MultiLineString:
tracks.append(TrackData());
if (!multiLineString(geometry, proj.isNull() ? parent : proj, if (!multiLineString(geometry, proj.isNull() ? parent : proj,
properties, tracks)) properties, tracks.last()))
return false; return false;
break; break;
case Polygon: case Polygon:
areas.append(Area());
if (!polygon(geometry, proj.isNull() ? parent : proj, properties, if (!polygon(geometry, proj.isNull() ? parent : proj, properties,
areas)) areas.last()))
return false; return false;
break; break;
case MultiPolygon: case MultiPolygon:
areas.append(Area());
if (!multiPolygon(geometry, proj.isNull() ? parent : proj, if (!multiPolygon(geometry, proj.isNull() ? parent : proj,
properties, areas)) properties, areas.last()))
return false; return false;
break; break;
case GeometryCollection: case GeometryCollection:
@ -542,26 +540,31 @@ bool GeoJSONParser::feature(const QJsonObject &object, const Projection &parent,
switch (type(geometry)) { switch (type(geometry)) {
case Point: case Point:
waypoints.resize(waypoints.size() + 1);
return point(geometry, proj.isNull() ? parent : proj, properties, return point(geometry, proj.isNull() ? parent : proj, properties,
waypoints); waypoints.last());
case MultiPoint: case MultiPoint:
return multiPoint(geometry, proj.isNull() ? parent : proj, return multiPoint(geometry, proj.isNull() ? parent : proj,
properties, waypoints); properties, waypoints);
case LineString: case LineString:
tracks.append(TrackData());
return lineString(geometry, proj.isNull() ? parent : proj, return lineString(geometry, proj.isNull() ? parent : proj,
properties, tracks); properties, tracks.last());
case MultiLineString: case MultiLineString:
tracks.append(TrackData());
return multiLineString(geometry, proj.isNull() ? parent : proj, return multiLineString(geometry, proj.isNull() ? parent : proj,
properties, tracks); properties, tracks.last());
case GeometryCollection: case GeometryCollection:
return geometryCollection(geometry, proj.isNull() ? parent : proj, return geometryCollection(geometry, proj.isNull() ? parent : proj,
properties, tracks, areas, waypoints); properties, tracks, areas, waypoints);
case Polygon: case Polygon:
areas.append(Area());
return polygon(geometry, proj.isNull() ? parent : proj, properties, return polygon(geometry, proj.isNull() ? parent : proj, properties,
areas); areas.last());
case MultiPolygon: case MultiPolygon:
areas.append(Area());
return multiPolygon(geometry, proj.isNull() ? parent : proj, return multiPolygon(geometry, proj.isNull() ? parent : proj,
properties, areas); properties, areas.last());
default: default:
_errorString = geometry["type"].toString() _errorString = geometry["type"].toString()
+ ": invalid/missing Feature geometry"; + ": invalid/missing Feature geometry";
@ -617,13 +620,16 @@ bool GeoJSONParser::parse(QFile *file, QList<TrackData> &tracks,
switch (type(object)) { switch (type(object)) {
case Point: case Point:
return point(object, proj, QJsonValue(), waypoints); waypoints.resize(waypoints.size() + 1);
return point(object, proj, QJsonValue(), waypoints.last());
case MultiPoint: case MultiPoint:
return multiPoint(object, proj, QJsonValue(), waypoints); return multiPoint(object, proj, QJsonValue(), waypoints);
case LineString: case LineString:
return lineString(object, proj, QJsonValue(), tracks); tracks.append(TrackData());
return lineString(object, proj, QJsonValue(), tracks.last());
case MultiLineString: case MultiLineString:
return multiLineString(object, proj, QJsonValue(), tracks); tracks.append(TrackData());
return multiLineString(object, proj, QJsonValue(), tracks.last());
case GeometryCollection: case GeometryCollection:
return geometryCollection(object, proj, QJsonValue(), tracks, areas, return geometryCollection(object, proj, QJsonValue(), tracks, areas,
waypoints); waypoints);
@ -632,9 +638,11 @@ bool GeoJSONParser::parse(QFile *file, QList<TrackData> &tracks,
case FeatureCollection: case FeatureCollection:
return featureCollection(object, proj, tracks, areas, waypoints); return featureCollection(object, proj, tracks, areas, waypoints);
case Polygon: case Polygon:
return polygon(object, proj, QJsonValue(), areas); areas.append(Area());
return polygon(object, proj, QJsonValue(), areas.last());
case MultiPolygon: case MultiPolygon:
return multiPolygon(object, proj, QJsonValue(), areas); areas.append(Area());
return multiPolygon(object, proj, QJsonValue(), areas.last());
case Unknown: case Unknown:
if (object["type"].toString().isNull()) if (object["type"].toString().isNull())
_errorString = "Not a GeoJSON file"; _errorString = "Not a GeoJSON file";

View File

@ -33,17 +33,17 @@ private:
Type type(const QJsonObject &json); Type type(const QJsonObject &json);
bool crs(const QJsonObject &object, Projection &proj); bool crs(const QJsonObject &object, Projection &proj);
bool point(const QJsonObject &object, const Projection &parent, bool point(const QJsonObject &object, const Projection &parent,
const QJsonValue &properties, QVector<Waypoint> &waypoints); const QJsonValue &properties, Waypoint &waypoint);
bool multiPoint(const QJsonObject &object, const Projection &parent, bool multiPoint(const QJsonObject &object, const Projection &parent,
const QJsonValue &properties, QVector<Waypoint> &waypoints); const QJsonValue &properties, QVector<Waypoint> &waypoints);
bool lineString(const QJsonObject &coordinates, const Projection &parent, bool lineString(const QJsonObject &coordinates, const Projection &parent,
const QJsonValue &properties, QList<TrackData> &tracks); const QJsonValue &properties, TrackData &track);
bool multiLineString(const QJsonObject &object, const Projection &proj, bool multiLineString(const QJsonObject &object, const Projection &proj,
const QJsonValue &properties, QList<TrackData> &tracks); const QJsonValue &properties, TrackData &track);
bool polygon(const QJsonObject &object, const Projection &parent, bool polygon(const QJsonObject &object, const Projection &parent,
const QJsonValue &properties, QList<Area> &areas); const QJsonValue &properties, Area &area);
bool multiPolygon(const QJsonObject &object, const Projection &proj, bool multiPolygon(const QJsonObject &object, const Projection &proj,
const QJsonValue &properties, QList<Area> &areas); const QJsonValue &properties, Area &area);
bool geometryCollection(const QJsonObject &json, const Projection &parent, bool geometryCollection(const QJsonObject &json, const Projection &parent,
const QJsonValue &properties, QList<TrackData> &tracks, const QJsonValue &properties, QList<TrackData> &tracks,
QList<Area> &areas, QVector<Waypoint> &waypoints); QList<Area> &areas, QVector<Waypoint> &waypoints);

View File

@ -247,7 +247,8 @@ bool IGCParser::parse(QFile *file, QList<TrackData> &tracks,
ctx.date = QDate(1970, 1, 1); ctx.date = QDate(1970, 1, 1);
} }
if (!track) { if (!track) {
tracks.append(SegmentData()); tracks.append(TrackData());
tracks.last().append(SegmentData());
ctx.time = QTime(0, 0); ctx.time = QTime(0, 0);
track = true; track = true;
} }

View File

@ -13,13 +13,6 @@ typedef QVector<Trackpoint> SegmentData;
class TrackData : public QList<SegmentData> class TrackData : public QList<SegmentData>
{ {
public: public:
TrackData() {}
TrackData(const SegmentData &segment)
{
reserve(1);
append(segment);
}
const QString &name() const {return _name;} const QString &name() const {return _name;}
const QString &description() const {return _desc;} const QString &description() const {return _desc;}
const QString &comment() const {return _comment;} const QString &comment() const {return _comment;}

View File

@ -151,7 +151,8 @@ bool TwoNavParser::parse(QFile *file, QList<TrackData> &tracks,
} }
if (!track) { if (!track) {
tracks.append(SegmentData()); tracks.append(TrackData());
tracks.last().append(SegmentData());
track = true; track = true;
} }