Commit 573776e1 authored by Volker Krause's avatar Volker Krause
Browse files

Parse journey section paths in the compact EFA response format too

parent dfef43a4
......@@ -120,6 +120,33 @@
"notes": [
"Some construction works. More info on some website."
],
"path": {
"sections": [
{
"path": {
"coordinates": [
[
11.08222,
49.44706
],
[
11.0822,
49.44706
],
[
11.08167,
49.44639
],
[
11.08165,
49.44639
]
],
"type": "LineString"
}
}
]
},
"route": {
"direction": "Röthenbach",
"line": {
......@@ -155,6 +182,33 @@
"name": "Nürnberg Hbf"
},
"mode": "PublicTransport",
"path": {
"sections": [
{
"path": {
"coordinates": [
[
11.08165,
49.44639
],
[
11.08177,
49.44616
],
[
11.11446,
49.41586
],
[
11.11467,
49.41588
]
],
"type": "LineString"
}
}
]
},
"route": {
"direction": "Langwasser Süd",
"line": {
......
......@@ -126,7 +126,7 @@
<stateless>van:01002: :R:j19</stateless>
</dv>
</m>
<pt>...</pt>
<pt>11.07907,49.49386 11.08092,49.49368 11.08679,49.45258 11.08222,49.44705</pt>
<pss>
<s>3001391;N&#252;rnberg Flughafen;20191111;2126;11.07908:49.49388:WGS84[DD.ddddd];0;11;2;20191111;2126;0;-1;de:09564:1391;de:09564:1391:11:2;</s>
<s>3001320;N&#252;rnberg Ziegelstein;20191111;2128;11.10504:49.48533:WGS84[DD.ddddd];0;11;1;00;00;0;-1;de:09564:1320;de:09564:1320:11:1;</s>
......@@ -141,7 +141,7 @@
<interchange>
<de>Nürnberg Hbf</de>
<d>2</d>
<pt>...</pt>
<pt>11.08222,49.44706 11.08220,49.44706 11.08167,49.44639 11.08165,49.44639</pt>
</interchange>
<ns>
<no>
......@@ -248,7 +248,7 @@
<stateless>van:01001: :H:j19</stateless>
</dv>
</m>
<pt>...</pt>
<pt>11.08165,49.44639 11.08177,49.44616 11.11446,49.41586 11.11467,49.41588</pt>
<pss>...</pss>
<ns/>
<fq/>
......
......@@ -337,6 +337,8 @@ JourneySection EfaCompactParser::parseTripSection(ScopedXmlStreamReader &&reader
stops.erase(stops.begin());
}
section.setIntermediateStops(std::move(stops));
} else if (reader.name() == QLatin1String("pt")) {
section.setPath(parsePathCoordinatesElement(reader));
}
// TODO interchange tag - should we turn this into transfer sections?
}
......
......@@ -6,6 +6,9 @@
#include "efaparser.h"
#include "logging.h"
#include "scopedxmlstreamreader.h"
#include <KPublicTransport/Path>
using namespace KPublicTransport;
......@@ -56,3 +59,23 @@ Line::Mode EfaParser::motTypeToLineMode(int mot)
qCDebug(Log) << "Unknown means ot transport: " << mot;
return Line::Unknown;
}
Path EfaParser::parsePathCoordinatesElement(ScopedXmlStreamReader &reader)
{
QPolygonF poly;
// TODO do we need to support the format attributes, or is this always the same anyway?
const auto coords = reader.readElementText().split(QLatin1Char(' '), Qt::SkipEmptyParts);
poly.reserve(coords.size());
for (const auto &coord : coords) {
const auto p = coord.split(QLatin1Char(','));
if (p.size() == 2) {
poly.push_back({p[0].toDouble(), p[1].toDouble()});
}
}
PathSection section;
section.setPath(poly);
Path path;
path.setSections({section});
return path;
}
......@@ -18,13 +18,14 @@
#include <vector>
class QByteArray;
class QXmlStreamReader;
namespace KPublicTransport {
class Journey;
class JourneySection;
class Location;
class Path;
class ScopedXmlStreamReader;
class Stopover;
/** Base class for parsers for responses from EFA services.
......@@ -51,6 +52,9 @@ protected:
*/
static Line::Mode motTypeToLineMode(int mot);
/** Parse path encoded as a space separated string of coordinate pairs. */
static Path parsePathCoordinatesElement(ScopedXmlStreamReader &reader);
QString m_locationIdentifierType;
mutable QString m_errorMsg;
mutable Reply::Error m_error = Reply::NoError;
......
......@@ -247,29 +247,6 @@ std::vector<Stopover> EfaXmlParser::parsePartialTripStopSequence(ScopedXmlStream
return stops;
}
static Path parsePathCoordinates(ScopedXmlStreamReader &&reader)
{
QPolygonF poly;
while (reader.readNextSibling()) {
if (reader.name() == QLatin1String("itdCoordinateString")) {
// TODO do we need to support the format attributes, or is this always the same anyway?
const auto coords = reader.readElementText().split(QLatin1Char(' '), Qt::SkipEmptyParts);
poly.reserve(coords.size());
for (const auto &coord : coords) {
const auto p = coord.split(QLatin1Char(','));
if (p.size() == 2) {
poly.push_back({p[0].toDouble(), p[1].toDouble()});
}
}
}
}
PathSection section;
section.setPath(poly);
Path path;
path.setSections({section});
return path;
}
struct {
int type;
JourneySection::Mode mode;
......@@ -372,3 +349,13 @@ QStringList EfaXmlParser::parseInfoLink(ScopedXmlStreamReader &&reader) const
}
return l;
}
Path EfaXmlParser::parsePathCoordinates(ScopedXmlStreamReader &&reader) const
{
while (reader.readNextSibling()) {
if (reader.name() == QLatin1String("itdCoordinateString")) {
return parsePathCoordinatesElement(reader);
}
}
return {};
}
......@@ -37,6 +37,7 @@ private:
JourneySection parseTripPartialRoute(ScopedXmlStreamReader &&reader) const;
Journey parseTripRoute(ScopedXmlStreamReader &&reader) const;
QStringList parseInfoLink(ScopedXmlStreamReader &&reader) const;
Path parsePathCoordinates(ScopedXmlStreamReader &&reader) const;
mutable QHash<QString, Location> m_locations;
};
......
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