]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge pull request #2681 from lonvia/improve-geocodejson
authorSarah Hoffmann <lonvia@denofr.de>
Mon, 2 May 2022 14:05:02 +0000 (16:05 +0200)
committerGitHub <noreply@github.com>
Mon, 2 May 2022 14:05:02 +0000 (16:05 +0200)
Fix 'type' field in the geocodejson response

docs/admin/Migration.md
docs/api/Output.md
lib-php/lib.php
lib-php/template/search-geocodejson.php

index bc6499183c4b84e63efc2fc7d5778a9353777ee2..11ee7f0558c37406599d681334b602524492f363 100644 (file)
@@ -15,6 +15,15 @@ breaking changes. **Please read them before running the migration.**
     If you are migrating from a version <3.6, then you still have to follow
     the manual migration steps up to 3.6.
 
+## 4.0.0 -> master
+
+### geocodejson output changed
+
+The `type` field of the geocodejson output has changed. It now contains
+the address class of the object instead of the value of the OSM tag. If
+your client has used the `type` field, switch them to read `osm_value`
+instead.
+
 ## 3.7.0 -> 4.0.0
 
 ### NOMINATIM_PHRASE_CONFIG removed
index 07525a985da7f475fcf1f0ad02c6c3d4f5be9587..d59f75dd5156dc334bfba818ce42ac24e7b37843 100644 (file)
@@ -98,7 +98,10 @@ The GeocodeJSON format follows the
 The following feature attributes are implemented:
 
  * `osm_type`, `osm_id` - reference to the OSM object (unofficial extension, [see notes](#osm-reference))
- * `type` - value of the main tag of the object (e.g. residential, restaurant, ...)
+ * `type` - the 'address level' of the object ('house', 'street', `district`, `city`,
+            `county`, `state`, `country`, `locality`)
+ * `osm_key`- key of the main tag of the OSM object (e.g. boundary, highway, amenity)
+ * `osm_value` - value of the main tag of the OSM object (e.g. residential, restaurant)
  * `label` - full comma-separated address
  * `name` - localised name of the place
  * `housenumber`, `street`, `locality`, `district`, `postcode`, `city`,
index 9babe5ed907ca91c290b967630f777510fe21df9..d17c9d72b8dacf0a97d9bd7c5e2a5ad3e2f42626 100644 (file)
@@ -206,6 +206,36 @@ function parseLatLon($sQuery)
     return array($sFound, $fQueryLat, $fQueryLon);
 }
 
+function addressRankToGeocodeJsonType($iAddressRank)
+{
+    if ($iAddressRank >= 29 && $iAddressRank <= 30) {
+        return 'house';
+    }
+    if ($iAddressRank >= 26 && $iAddressRank < 28) {
+        return 'street';
+    }
+    if ($iAddressRank >= 22 && $iAddressRank < 26) {
+        return 'locality';
+    }
+    if ($iAddressRank >= 17 && $iAddressRank < 22) {
+        return 'district';
+    }
+    if ($iAddressRank >= 13 && $iAddressRank < 17) {
+        return 'city';
+    }
+    if ($iAddressRank >= 10 && $iAddressRank < 13) {
+        return 'county';
+    }
+    if ($iAddressRank >= 5 && $iAddressRank < 10) {
+        return 'state';
+    }
+    if ($iAddressRank >= 4 && $iAddressRank < 5) {
+        return 'country';
+    }
+
+    return 'locality';
+}
+
 if (!function_exists('array_key_last')) {
     function array_key_last(array $array)
     {
index b8727719b19579b47a61a17b5f6e016fb7c5caed..5439e3cfe532e61140a3293701d8a1a5c6517926 100644 (file)
@@ -25,8 +25,10 @@ foreach ($aSearchResults as $iResNum => $aPointDetails) {
         $aPlace['properties']['geocoding']['osm_type'] = $sOSMType;
         $aPlace['properties']['geocoding']['osm_id'] = $aPointDetails['osm_id'];
     }
+    $aPlace['properties']['geocoding']['osm_key'] = $aPointDetails['class'];
+    $aPlace['properties']['geocoding']['osm_value'] = $aPointDetails['type'];
 
-    $aPlace['properties']['geocoding']['type'] = $aPointDetails['type'];
+    $aPlace['properties']['geocoding']['type'] = addressRankToGeocodeJsonType($aPointDetails['rank_address']);
 
     $aPlace['properties']['geocoding']['label'] = $aPointDetails['langaddress'];