add _add_admin_level helper function to helpers.py

This commit is contained in:
Sri Charan Chittineni
2026-03-09 04:59:20 +00:00
parent 11e458ca47
commit b195550c07

View File

@@ -12,10 +12,20 @@ from typing import Tuple, Optional, Any, Dict, Iterable
from itertools import chain from itertools import chain
import re import re
from ..results import SearchResults, SourceTable from ..results import SearchResults, SourceTable, BaseResult
from ..types import SearchDetails, GeometryFormat 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 REVERSE_MAX_RANKS = [2, 2, 2, # 0-2 Continent/Sea
4, 4, # 3-4 Country 4, 4, # 3-4 Country
8, # 5 State 8, # 5 State