Commit c9aa03f4 authored by Volker Krause's avatar Volker Krause
Browse files

Parse EFA path description elements

Those are containing indoor navigation instructions for transfers. We
don't cover all details included in those yet though.
parent f102a45d
Pipeline #50403 passed with stage
in 24 seconds
[
{
"sections": [
{
"disruptionEffect": "NormalService",
"distance": 180,
"expectedArrivalPlatform": "",
"expectedArrivalTime": "2020-04-27T22:13:00",
"expectedDeparturePlatform": "",
"expectedDepartureTime": "2020-04-27T22:07:00",
"from": {
"identifier": {
"testid": "3000510"
},
"latitude": 49.44636917114258,
"locality": "Nürnberg",
"longitude": 11.081809997558594,
"name": "Nürnberg Hauptbahnhof"
},
"mode": "Walking",
"path": {
"sections": [
{
"description": "Ausstieg U-Bahn links"
},
{
"description": "Bahnsteig",
"path": {
"coordinates": [
[
11.08263,
49.44717
],
[
11.0826,
49.44716
]
],
"type": "LineString"
}
},
{
"path": {
"coordinates": [
[
11.08258,
49.44715
],
[
11.08258,
49.44714
]
],
"type": "LineString"
}
},
{
"description": "Weg im Geb�ude",
"path": {
"coordinates": [
[
11.08218,
49.44702
]
],
"type": "LineString"
}
},
{
"description": "Aufzug abw�rts"
},
{
"description": "Weg im Geb�ude",
"path": {
"coordinates": [
[
11.08216,
49.447
],
[
11.08222,
49.44701
],
[
11.0822,
49.44705
],
[
11.08201,
49.44701
],
[
11.08174,
49.44695
],
[
11.08166,
49.44693
],
[
11.08152,
49.4469
],
[
11.08155,
49.44683
],
[
11.08156,
49.44681
]
],
"type": "LineString"
}
},
{
"description": "Rolltreppe abw�rts",
"path": {
"coordinates": [
[
11.08158,
49.44674
]
],
"type": "LineString"
}
},
{
"description": "Weg im Geb�ude",
"path": {
"coordinates": [
[
11.08167,
49.44656
]
],
"type": "LineString"
}
},
{
"description": "Weg im Geb�ude",
"path": {
"coordinates": [
[
11.08171,
49.44653
],
[
11.08172,
49.44653
]
],
"type": "LineString"
}
},
{
"description": "Bahnsteig",
"path": {
"coordinates": [
[
11.08173,
49.44653
]
],
"type": "LineString"
}
},
{
"description": "Weg im Geb�ude",
"path": {
"coordinates": [
[
11.08162,
49.4465
],
[
11.0817,
49.44635
]
],
"type": "LineString"
}
},
{
"description": "Rolltreppe aufw�rts",
"path": {
"coordinates": [
[
11.08179,
49.44636
]
],
"type": "LineString"
}
},
{
"description": "Weg im Geb�ude",
"path": {
"coordinates": [
[
11.08181,
49.4463
],
[
11.08195,
49.44602
],
[
11.08198,
49.44599
],
[
11.08204,
49.44588
],
[
11.08212,
49.44573
],
[
11.08218,
49.4456
]
],
"type": "LineString"
}
},
{
"description": "Rolltreppe aufw�rts",
"path": {
"coordinates": [
[
11.08226,
49.44546
]
],
"type": "LineString"
}
},
{
"description": "Weg im Geb�ude",
"path": {
"coordinates": [
[
11.08235,
49.44547
],
[
11.08248,
49.4455
]
],
"type": "LineString"
}
},
{
"description": "Bahnsteig",
"path": {
"coordinates": [
[
11.08252,
49.44552
],
[
11.0825,
49.44555
]
],
"type": "LineString"
}
}
]
},
"scheduledArrivalPlatform": "",
"scheduledArrivalTime": "2020-04-27T22:13:00",
"scheduledDeparturePlatform": "",
"scheduledDepartureTime": "2020-04-27T22:07:00",
"to": {
"identifier": {
"testid": "99999998"
},
"latitude": 49.445499420166016,
"locality": "Nürnberg",
"longitude": 11.082300186157227,
"name": "Nürnberg, Bahnsteig"
}
}
]
}
]
This diff is collapsed.
......@@ -178,6 +178,9 @@ private Q_SLOTS:
QTest::newRow("vgn-trip")
<< s(SOURCE_DIR "/data/efa/trip-response-full-vgn.xml")
<< s(SOURCE_DIR "/data/efa/trip-response-full-vgn.json");
QTest::newRow("vgn-trip-indoor-path")
<< s(SOURCE_DIR "/data/efa/trip-response-full-indoor-path-vgn.xml")
<< s(SOURCE_DIR "/data/efa/trip-response-full-indoor-path-vgn.json");
}
void testParseTrips()
......
......@@ -302,6 +302,14 @@ JourneySection EfaXmlParser::parseTripPartialRoute(ScopedXmlStreamReader &&reade
section.setIntermediateStops(parsePartialTripStopSequence(reader.subReader()));
} else if (reader.name() == QLatin1String("itdPathCoordinates")) {
section.setPath(parsePathCoordinates(reader.subReader()));
} else if (reader.name() == QLatin1String("itdITPathDescription") && !section.path().isEmpty()) {
auto subreader = reader.subReader();
while (subreader.readNextSibling()) {
if (subreader.name() == QLatin1String("itdITPathDescriptionList")) {
const auto fullPath = section.path();
section.setPath(parsePathDescriptionList(subreader.subReader(), fullPath.sections()[0].path()));
}
}
}
}
......@@ -352,10 +360,48 @@ QStringList EfaXmlParser::parseInfoLink(ScopedXmlStreamReader &&reader) const
Path EfaXmlParser::parsePathCoordinates(ScopedXmlStreamReader &&reader) const
{
Path path;
while (reader.readNextSibling()) {
if (reader.name() == QLatin1String("itdCoordinateString")) {
return parsePathCoordinatesElement(reader);
path = parsePathCoordinatesElement(reader);
}
}
return path;
}
Path EfaXmlParser::parsePathDescriptionList(ScopedXmlStreamReader &&reader, const QPolygonF &poly) const
{
Path path;
std::vector<PathSection> sections;
while (reader.readNextSibling()) {
if (reader.name() == QLatin1String("itdITPathDescriptionElem")) {
PathSection section;
int fromIdx = -1; int toIdx = -1;
auto elemReader = reader.subReader();
while (elemReader.readNextSibling()) {
if (elemReader.name() == QLatin1String("fromPathCoordIdx")) {
fromIdx = elemReader.readElementText().toInt();
} else if (elemReader.name() == QLatin1String("toPathCoordIdx")) {
toIdx = elemReader.readElementText().toInt();
} else if (elemReader.name() == QLatin1String("streetname")) {
section.setDescription(elemReader.readElementText());
}
// turnDirection, turningManoeuvre, from/toPathLink??, skyDirection, traveltime, distance, niveau, genAttrList
}
if (fromIdx < 0 || toIdx < 0 || fromIdx >= poly.size() || toIdx >= poly.size() || toIdx < fromIdx) {
qWarning() << "weird polygon indexes?" << fromIdx << toIdx << poly.size();
continue;
}
QPolygonF subPoly;
subPoly.reserve(toIdx - fromIdx + 1);
std::copy(poly.begin() + fromIdx, poly.begin() + toIdx, std::back_inserter(subPoly));
section.setPath(subPoly);
sections.push_back(std::move(section));
}
}
return {};
path.setSections(std::move(sections));
return path;
}
......@@ -9,6 +9,8 @@
#include "efaparser.h"
class QPolygonF;
namespace KPublicTransport {
class ScopedXmlStreamReader;
......@@ -38,6 +40,7 @@ private:
Journey parseTripRoute(ScopedXmlStreamReader &&reader) const;
QStringList parseInfoLink(ScopedXmlStreamReader &&reader) const;
Path parsePathCoordinates(ScopedXmlStreamReader &&reader) const;
Path parsePathDescriptionList(ScopedXmlStreamReader &&reader, const QPolygonF &poly) const;
mutable QHash<QString, Location> m_locations;
};
......
......@@ -16,14 +16,20 @@ namespace KPublicTransport {
class PathSectionPrivate : public QSharedData {
public:
QPolygonF path;
QString description;
};
}
KPUBLICTRANSPORT_MAKE_GADGET(PathSection)
KPUBLICTRANSPORT_MAKE_PROPERTY(PathSection, QPolygonF, path, setPath)
KPUBLICTRANSPORT_MAKE_PROPERTY(PathSection, QString, description, setDescription)
int PathSection::distance() const
{
if (d->path.size() < 2) {
return 0;
}
int dist = 0;
for (auto it = d->path.begin(); it != std::prev(d->path.end()); ++it) {
const auto nextIt = std::next(it);
......@@ -35,7 +41,9 @@ int PathSection::distance() const
QJsonObject PathSection::toJson(const PathSection &section)
{
auto obj = Json::toJson(section);
obj.insert(QLatin1String("path"), GeoJson::writeLineString(section.path()));
if (!section.path().empty()) {
obj.insert(QLatin1String("path"), GeoJson::writeLineString(section.path()));
}
return obj;
}
......
......@@ -26,8 +26,10 @@ class KPUBLICTRANSPORT_EXPORT PathSection
KPUBLICTRANSPORT_GADGET(PathSection)
/** The geo coordinate poly-line followed by this path section. */
KPUBLICTRANSPORT_PROPERTY(QPolygonF, path, setPath)
/** Human-readable description of this path segment. */
KPUBLICTRANSPORT_PROPERTY(QString, description, setDescription)
// TODO add more properties: maneuver instructions, human-readable path description, floor level
// TODO add more properties: maneuver instructions, floor level
/** The length of this path section in meters. */
Q_PROPERTY(int distance READ distance STORED false)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment