Commit 1604fe5c authored by Volker Krause's avatar Volker Krause
Browse files

Use coverage polygons from OTP backends rather than bounding boxes

This gives us better results, especially since there is more room for
cleaning up bogus outliers in there. There's probably more we can do here,
there's still a few operators getting weirdly extended coverage polygons.
parent 714b93c3
Pipeline #58939 passed with stage
in 25 seconds
......@@ -49,25 +49,57 @@
"area": {
"coordinates": [
[
[
21.3681720361,
59.7865148075
],
[
19.9279975891,
60.0924550185
],
[
19.5364379883,
66.5802673946
60.225493147
],
[
29.5712215851,
21.177114932,
62.943923943
],
[
27.9145080397,
66.5802673946
],
[
27.9226453285,
66.5787411706
],
[
29.3256332363,
63.278332436
],
[
29.5712215851,
59.7865148075
62.3942113263
],
[
19.5364379883,
59.7865148075
29.0676342699,
61.6835689482
],
[
19.5364379883,
66.5802673946
28.610516,
61.248426
],
[
27.1864048519,
60.2860075713
],
[
24.391172,
59.9328744
],
[
21.3681720361,
59.7865148075
]
]
],
......
......@@ -43,24 +43,84 @@
"coordinates": [
[
[
19.3167101,
70.1383835
21.3700125,
59.7751839
],
[
31.5841445,
19.9865581,
59.9968658
],
[
19.546371800000003,
60.148079300000006
],
[
19.5423981,
60.1497262
],
[
19.5188148,
60.171725200000004
],
[
19.4761585,
60.237121300000005
],
[
19.4746336,
60.240131000000005
],
[
20.368804,
68.9742184
],
[
20.502584000000002,
69.07364940000001
],
[
21.264036,
69.3080254
],
[
26.4202443,
69.9730842
],
[
28.164667,
70.1383835
],
[
29.191561,
69.68586900000001
],
[
29.980184700000002,
67.7666998
],
[
31.5863544,
63.004734500000005
],
[
31.5841445,
59.723203000000005
62.908447900000006
],
[
19.3167101,
59.723203000000005
31.474939600000003,
62.5658898
],
[
19.3167101,
70.1383835
31.252660600000002,
62.000880300000006
],
[
30.179616300000003,
59.7907839
],
[
21.3700125,
59.7751839
]
]
],
......
......@@ -42,24 +42,84 @@
"coordinates": [
[
[
0,
46.468669600000005
11.247359,
43.776881
],
[
11.276394,
46.468669600000005
7.623938,
43.789494
],
[
11.276394,
-6.927976224346821e-05
6.9987129,
44.2262585
],
[
0,
-6.927976224346821e-05
6.9536924,
44.267431800000004
],
[
6.8787962,
44.336094800000005
],
[
6.605899900000001,
45.1108161
],
[
6.606974,
45.120643
],
[
6.610964500000001,
45.1323955
],
[
6.6584399,
45.193577
],
[
7.029065900000001,
45.522739200000004
],
[
8.2736453,
46.4377173
],
[
8.3684022,
46.469769500000005
],
[
8.4454118,
46.471977200000005
],
[
8.471048900000001,
46.470783100000006
],
[
10.166827,
46.215083
],
[
10.329482,
46.177007
],
[
10.351353,
46.163355
],
[
10.9827,
45.428666
],
[
11.276394,
43.777492
],
[
0,
46.468669600000005
11.247359,
43.776881
]
]
],
......
......@@ -42,24 +42,48 @@
"coordinates": [
[
[
6.63299,
46.11542
11.247359,
43.776881
],
[
11.276394,
46.11542
7.623938,
43.789494
],
[
11.276394,
43.776881
6.93822,
44.39601
],
[
6.63299,
43.776881
6.6381177000000005,
45.104098900000004
],
[
6.6395527,
45.1112849
],
[
6.657883,
45.192791
],
[
6.63299,
7.325321,
45.734711
],
[
8.2964,
46.11542
],
[
10.9827,
45.428666
],
[
11.276394,
43.777492
],
[
11.247359,
43.776881
]
]
],
......
......@@ -5,8 +5,11 @@ add_executable(endpointprobe endpointprobe.cpp)
target_link_libraries(endpointprobe Qt5::Network)
add_custom_target(run-endpoint-probe COMMAND endpointprobe ${CMAKE_SOURCE_DIR}/src/lib/networks)
add_executable(otpprobe otpprobe.cpp)
target_link_libraries(otpprobe Qt5::Network)
add_executable(otpprobe
otpprobe.cpp
../lib/geo/geojson.cpp
)
target_link_libraries(otpprobe Qt5::Gui Qt5::Network)
add_custom_target(run-otp-probe COMMAND otpprobe ${CMAKE_SOURCE_DIR}/src/lib/networks)
add_executable(gbfsprobe gbfsprobe.cpp)
......
......@@ -4,6 +4,8 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "../lib/geo/geojson_p.h"
#include <QCoreApplication>
#include <QDebug>
#include <QDirIterator>
......@@ -13,6 +15,7 @@
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QPolygonF>
#include <QRectF>
#include <iostream>
......@@ -20,25 +23,23 @@
static void fillNetworkConfig(QNetworkReply *reply, QJsonObject &obj)
{
const auto desc = QJsonDocument::fromJson(reply->readAll()).object();
QRectF boundingBox;
boundingBox.setBottom(desc.value(QLatin1String("lowerLeftLatitude")).toDouble());
boundingBox.setLeft(desc.value(QLatin1String("lowerLeftLongitude")).toDouble());
boundingBox.setTop(desc.value(QLatin1String("upperRightLatitude")).toDouble());
boundingBox.setRight(desc.value(QLatin1String("upperRightLongitude")).toDouble());
QJsonArray coords;
for (const auto &point : {boundingBox.topLeft(), boundingBox.topRight(), boundingBox.bottomRight(), boundingBox.bottomLeft(), boundingBox.topLeft()}) {
QJsonArray p;
p.push_back(point.x());
p.push_back(point.y());
coords.push_back(p);
// clean up the coverage polygon we get, that often contains bogus outliers
using namespace KPublicTransport;
auto poly = GeoJson::readOuterPolygon(desc.value(QLatin1String("polygon")).toObject());
// TODO: more elaborate outlier detection, null points is just one of the problems
poly.erase(std::remove_if(poly.begin(), poly.end(), [](auto p) { return p.isNull(); }), poly.end());
if (poly.empty()) {
return;
}
QJsonObject area;
area.insert(QLatin1String("type"), QLatin1String("Polygon"));
area.insert(QLatin1String("coordinates"), QJsonArray({coords}));
if (!poly.isClosed()) {
poly.push_back(poly.front());
}
auto coverage = obj.value(QLatin1String("coverage")).toObject();
auto anyCoverage = coverage.value(QLatin1String("anyCoverage")).toObject();
anyCoverage.insert(QLatin1String("area"), area);
coverage.insert(QLatin1String("anyCoverage"), anyCoverage);
auto rtCoverage = coverage.value(QLatin1String("realtimeCoverage")).toObject();
rtCoverage.insert(QLatin1String("area"), GeoJson::writePolygon(poly));
coverage.insert(QLatin1String("realtimeCoverage"), rtCoverage);
obj.insert(QLatin1String("coverage"), coverage);
}
......
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