mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-12 13:54:07 +00:00
Merge pull request #4020 from kad-link/fix/add-admin-level-in-extratags
fix: add admin_level in extratags for boundary=administrative
This commit is contained in:
@@ -19,6 +19,7 @@ from ..localization import Locales
|
||||
from ..result_formatting import FormatDispatcher
|
||||
from .classtypes import ICONS
|
||||
from . import format_json, format_xml
|
||||
from .helpers import _add_admin_level
|
||||
from .. import logging as loglib
|
||||
from ..server import content_types as ct
|
||||
|
||||
@@ -157,7 +158,7 @@ def _format_details_json(result: DetailedResult, options: Mapping[str, Any]) ->
|
||||
.keyval_not_none('indexed_date', result.indexed_date, lambda v: v.isoformat())\
|
||||
.keyval_not_none('importance', result.importance)\
|
||||
.keyval('calculated_importance', result.calculated_importance())\
|
||||
.keyval('extratags', result.extratags or {})\
|
||||
.keyval('extratags', _add_admin_level(result) or {})\
|
||||
.keyval_not_none('calculated_wikipedia', result.wikipedia)\
|
||||
.keyval('rank_address', result.rank_address)\
|
||||
.keyval('rank_search', result.rank_search)\
|
||||
|
||||
@@ -12,6 +12,7 @@ from typing import Mapping, Any, Optional, Tuple, Union, List
|
||||
from ..utils.json_writer import JsonWriter
|
||||
from ..results import AddressLines, ReverseResults, SearchResults
|
||||
from . import classtypes as cl
|
||||
from .helpers import _add_admin_level
|
||||
from ..types import EntranceDetails
|
||||
|
||||
|
||||
@@ -134,7 +135,7 @@ def format_base_json(results: Union[ReverseResults, SearchResults],
|
||||
write_entrances(out, result.entrances)
|
||||
|
||||
if options.get('extratags', False):
|
||||
out.keyval('extratags', result.extratags)
|
||||
out.keyval('extratags', _add_admin_level(result))
|
||||
|
||||
if options.get('namedetails', False):
|
||||
out.keyval('namedetails', result.names)
|
||||
@@ -210,7 +211,7 @@ def format_base_geojson(results: Union[ReverseResults, SearchResults],
|
||||
write_entrances(out, result.entrances)
|
||||
|
||||
if options.get('extratags', False):
|
||||
out.keyval('extratags', result.extratags)
|
||||
out.keyval('extratags', _add_admin_level(result))
|
||||
|
||||
if options.get('namedetails', False):
|
||||
out.keyval('namedetails', result.names)
|
||||
@@ -284,7 +285,7 @@ def format_base_geocodejson(results: Union[ReverseResults, SearchResults],
|
||||
write_entrances(out, result.entrances)
|
||||
|
||||
if options.get('extratags', False):
|
||||
out.keyval('extra', result.extratags)
|
||||
out.keyval('extra', _add_admin_level(result))
|
||||
|
||||
out.end_object().next().end_object().next()
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import xml.etree.ElementTree as ET
|
||||
from ..results import AddressLines, ReverseResult, ReverseResults, \
|
||||
SearchResult, SearchResults
|
||||
from . import classtypes as cl
|
||||
from .helpers import _add_admin_level
|
||||
from ..types import EntranceDetails
|
||||
|
||||
|
||||
@@ -125,8 +126,9 @@ def format_base_xml(results: Union[ReverseResults, SearchResults],
|
||||
|
||||
if options.get('extratags', False):
|
||||
eroot = ET.SubElement(root if simple else place, 'extratags')
|
||||
if result.extratags:
|
||||
for k, v in result.extratags.items():
|
||||
tags = _add_admin_level(result)
|
||||
if tags:
|
||||
for k, v in tags.items():
|
||||
ET.SubElement(eroot, 'tag', attrib={'key': k, 'value': v})
|
||||
|
||||
if options.get('namedetails', False):
|
||||
|
||||
@@ -12,10 +12,20 @@ from typing import Tuple, Optional, Any, Dict, Iterable
|
||||
from itertools import chain
|
||||
import re
|
||||
|
||||
from ..results import SearchResults, SourceTable
|
||||
from ..results import SearchResults, SourceTable, BaseResult
|
||||
from ..types import SearchDetails, GeometryFormat
|
||||
|
||||
|
||||
def _add_admin_level(result: BaseResult) -> Optional[Dict[str, str]]:
|
||||
""" Inject admin_level into extratags for boundary=administrative results.
|
||||
"""
|
||||
tags = result.extratags
|
||||
if result.category == ('boundary', 'administrative') and result.admin_level < 15:
|
||||
tags = dict(tags) if tags else {}
|
||||
tags['admin_level'] = str(result.admin_level)
|
||||
return tags
|
||||
|
||||
|
||||
REVERSE_MAX_RANKS = [2, 2, 2, # 0-2 Continent/Sea
|
||||
4, 4, # 3-4 Country
|
||||
8, # 5 State
|
||||
|
||||
Reference in New Issue
Block a user