Skip to content

Commit

Permalink
Normalize geo coordinate Place properties
Browse files Browse the repository at this point in the history
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
thomersch/openstreetmap-calendar#158 is deployed
there at least to fix the missing @type for the location property).
  • Loading branch information
vkrause committed Mar 3, 2024
1 parent 3f41032 commit 808d853
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
18 changes: 18 additions & 0 deletions autotests/jsonlddata/place-coordinate-propagation.in.json
Original file line number Diff line number Diff line change
@@ -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"
}
]

21 changes: 21 additions & 0 deletions autotests/jsonlddata/place-coordinate-propagation.out.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
16 changes: 16 additions & 0 deletions src/lib/json/jsonldimportfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 808d853

Please sign in to comment.