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