]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/api/v1/format_json.py
Merge pull request #3384 from mtmail/geocodejson-admin-levels-only-boundaries
[nominatim.git] / nominatim / api / v1 / format_json.py
index 0907c95526b25d4d9b47238dad008d2ad1bc54fa..1c17a032c586c6308023da8927dcbb0c8edef407 100644 (file)
@@ -54,7 +54,10 @@ def _write_geocodejson_address(out: JsonWriter,
                 out.keyval('housenumber', line.local_name)
             elif (obj_place_id is None or obj_place_id != line.place_id) \
                  and line.rank_address >= 4 and line.rank_address < 28:
-                extra[GEOCODEJSON_RANKS[line.rank_address]] = line.local_name
+                rank_name = GEOCODEJSON_RANKS[line.rank_address]
+                if rank_name not in extra:
+                    extra[rank_name] = line.local_name
+
 
     for k, v in extra.items():
         out.keyval(k, v)
@@ -83,8 +86,8 @@ def format_base_json(results: Union[napi.ReverseResults, napi.SearchResults],
 
         _write_osm_id(out, result.osm_object)
 
-        out.keyval('lat', result.centroid.lat)\
-             .keyval('lon', result.centroid.lon)\
+        out.keyval('lat', f"{result.centroid.lat}")\
+             .keyval('lon', f"{result.centroid.lon}")\
              .keyval(class_label, result.category[0])\
              .keyval('type', result.category[1])\
              .keyval('place_rank', result.rank_search)\
@@ -244,7 +247,8 @@ def format_base_geocodejson(results: Union[napi.ReverseResults, napi.SearchResul
             out.key('admin').start_object()
             if result.address_rows:
                 for line in result.address_rows:
-                    if line.isaddress and (line.admin_level or 15) < 15 and line.local_name:
+                    if line.isaddress and (line.admin_level or 15) < 15 and line.local_name \
+                       and line.category[0] == 'boundary' and line.category[1] == 'administrative':
                         out.keyval(f"level{line.admin_level}", line.local_name)
             out.end_object().next()