From 808d853a9fee403389c27685241474499c4e340a Mon Sep 17 00:00:00 2001 From: Volker Krause Date: Sun, 3 Mar 2024 13:35:43 +0100 Subject: [PATCH] Normalize geo coordinate Place properties Similar to what we do for string-based address properties, move those to the geo property instead. Allows importing from osmcal.org for example (once https://github.com/thomersch/openstreetmap-calendar/pull/158 is deployed there at least to fix the missing @type for the location property). --- .../place-coordinate-propagation.in.json | 18 ++++++++++++++++ .../place-coordinate-propagation.out.json | 21 +++++++++++++++++++ src/lib/json/jsonldimportfilter.cpp | 16 ++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 autotests/jsonlddata/place-coordinate-propagation.in.json create mode 100644 autotests/jsonlddata/place-coordinate-propagation.out.json diff --git a/autotests/jsonlddata/place-coordinate-propagation.in.json b/autotests/jsonlddata/place-coordinate-propagation.in.json new file mode 100644 index 00000000..22d45c18 --- /dev/null +++ b/autotests/jsonlddata/place-coordinate-propagation.in.json @@ -0,0 +1,18 @@ +[ + { + "@context": "https://schema.org", + "@type": "Event", + "endDate": "2024-03-11T21:30:00+08:00", + "eventStatus": "https://schema.org/EventScheduled", + "location": { + "@type": "Place", + "address": "MozSpace Taipei, 94, Section 1, Bade Road, Zhongzheng District, Huashan, Taipei, Taiwan", + "latitude": 25.044068, + "longitude": 121.532182 + }, + "modifiedTime": "2024-03-03T00:00:00", + "name": "OpenStreetMap x Wikidata Taipei #62", + "startDate": "2024-03-11T19:30:00+08:00" + } +] + diff --git a/autotests/jsonlddata/place-coordinate-propagation.out.json b/autotests/jsonlddata/place-coordinate-propagation.out.json new file mode 100644 index 00000000..669818eb --- /dev/null +++ b/autotests/jsonlddata/place-coordinate-propagation.out.json @@ -0,0 +1,21 @@ +[ + { + "@context": "http://schema.org", + "@type": "Event", + "endDate": "2024-03-11T21:30:00+08:00", + "location": { + "@type": "Place", + "address": { + "@type": "PostalAddress", + "streetAddress": "MozSpace Taipei, 94, Section 1, Bade Road, Zhongzheng District, Huashan, Taipei, Taiwan" + }, + "geo": { + "@type": "GeoCoordinates", + "latitude": 25.0440673828125, + "longitude": 25.0440673828125 + } + }, + "name": "OpenStreetMap x Wikidata Taipei #62", + "startDate": "2024-03-11T19:30:00+08:00" + } +] diff --git a/src/lib/json/jsonldimportfilter.cpp b/src/lib/json/jsonldimportfilter.cpp index 8b06888f..b0ca383e 100644 --- a/src/lib/json/jsonldimportfilter.cpp +++ b/src/lib/json/jsonldimportfilter.cpp @@ -121,6 +121,22 @@ static void filterPlace(QJsonObject &obj) {"streetAddress"_L1, addr.toString()}, }); } + // same for geo coordinates + const auto lat = obj.value("latitude"_L1); + const auto lon = obj.value("longitude"_L1); + if (lat.isDouble() && lon.isDouble()) { + auto geo = obj.value("geo"_L1).toObject(); + if (!geo.contains("@type"_L1)) { + geo.insert("@type"_L1, "GeoCoordinates"_L1); + } + if (!geo.contains("latitude"_L1)) { + geo.insert("latitude"_L1, lat); + } + if (!geo.contains("longitude"_L1)) { + geo.insert("longitude"_L1, lat); + } + obj.insert("geo"_L1, geo); + } } static void filterFlight(QJsonObject &res)