Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Libraries
KPublicTransport
Commits
09d2c108
Commit
09d2c108
authored
Sep 02, 2021
by
Volker Krause
Browse files
Parse GBFS geofencing zones and use that for the ounding box computation
parent
1956156c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib/gbfs/gbfsjob.cpp
View file @
09d2c108
...
...
@@ -5,6 +5,7 @@
*/
#include
"gbfsjob.h"
#include
"geo/geojson_p.h"
#include
<KPublicTransport/Location>
...
...
@@ -12,6 +13,8 @@
#include
<QNetworkAccessManager>
#include
<QNetworkReply>
#include
<QNetworkReply>
#include
<QPolygonF>
#include
<QVersionNumber>
#include
<cassert>
#include
<cmath>
...
...
@@ -237,6 +240,8 @@ void GBFSJob::parseData(const QJsonDocument &doc, GBFS::FileType type)
case
GBFS
::
Versions
:
parseVersionData
(
doc
);
break
;
case
GBFS
::
GeofencingZones
:
parseGeofencingZones
(
doc
);
default:
break
;
}
...
...
@@ -367,11 +372,24 @@ void GBFSJob::parseVersionData(const QJsonDocument &doc)
}
}
void
GBFSJob
::
parseGeofencingZones
(
const
QJsonDocument
&
doc
)
{
const
auto
features
=
doc
.
object
().
value
(
QLatin1String
(
"data"
)).
toObject
()
.
value
(
QLatin1String
(
"geofencing_zones"
)).
toObject
()
.
value
(
QLatin1String
(
"features"
)).
toArray
();
for
(
const
auto
&
featureVal
:
features
)
{
const
auto
geo
=
featureVal
.
toObject
().
value
(
QLatin1String
(
"geometry"
)).
toObject
();
m_geofenceBoundingBox
|=
GeoJson
::
readOuterPolygon
(
geo
).
boundingRect
();
}
qDebug
()
<<
"geo fence bounding box:"
<<
m_geofenceBoundingBox
;
}
void
GBFSJob
::
finalize
()
{
if
(
m_maxLat
>
m_minLat
&&
m_maxLon
>
m_minLon
)
{
m_service
.
boundingBox
=
QRectF
(
QPointF
(
m_minLon
,
m_minLat
),
QPointF
(
m_maxLon
,
m_maxLat
));
}
m_service
.
boundingBox
|=
m_geofenceBoundingBox
;
GBFSServiceRepository
::
store
(
m_service
);
Q_EMIT
finished
();
}
src/lib/gbfs/gbfsjob.h
View file @
09d2c108
...
...
@@ -14,6 +14,7 @@
#include
<QJsonArray>
#include
<QJsonDocument>
#include
<QObject>
#include
<QRectF>
#include
<QUrl>
class
QNetworkAccessManager
;
...
...
@@ -63,6 +64,7 @@ private:
void
parseFreeBikeStatus
(
const
QJsonDocument
&
doc
);
void
computeBoundingBox
(
const
QJsonArray
&
array
);
void
parseVersionData
(
const
QJsonDocument
&
doc
);
void
parseGeofencingZones
(
const
QJsonDocument
&
doc
);
void
finalize
();
QNetworkAccessManager
*
m_nam
=
nullptr
;
...
...
@@ -72,6 +74,7 @@ private:
QJsonArray
m_feeds
;
double
m_minLat
=
90.0
,
m_maxLat
=
-
90.0
,
m_minLon
=
180.0
,
m_maxLon
=
-
180.0
;
QRectF
m_geofenceBoundingBox
;
QString
m_errorMsg
;
Error
m_error
=
NoError
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment