|
|
@ -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";
|
|
|
|