X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/c314a3092c5b51c7782015f6fa9ac093b46fa174..e1dc4379e0cd100200ac53752442143ca4846fc5:/src/nominatim_api/v1/helpers.py diff --git a/src/nominatim_api/v1/helpers.py b/src/nominatim_api/v1/helpers.py index 9c220834..2c6ddc99 100644 --- a/src/nominatim_api/v1/helpers.py +++ b/src/nominatim_api/v1/helpers.py @@ -15,6 +15,7 @@ import re from ..results import SearchResult, SearchResults, SourceTable from ..types import SearchDetails, GeometryFormat + REVERSE_MAX_RANKS = [2, 2, 2, # 0-2 Continent/Sea 4, 4, # 3-4 Country 8, # 5 State @@ -28,7 +29,7 @@ REVERSE_MAX_RANKS = [2, 2, 2, # 0-2 Continent/Sea 26, # 16 Major Streets 27, # 17 Minor Streets 30 # 18 Building - ] + ] def zoom_to_rank(zoom: int) -> int: @@ -52,7 +53,6 @@ def feature_type_to_rank(feature_type: Optional[str]) -> Tuple[int, int]: return FEATURE_TYPE_TO_RANK.get(feature_type, (0, 30)) -#pylint: disable=too-many-arguments,too-many-branches def extend_query_parts(queryparts: Dict[str, Any], details: Dict[str, Any], feature_type: Optional[str], namedetails: bool, extratags: bool, @@ -62,13 +62,13 @@ def extend_query_parts(queryparts: Dict[str, Any], details: Dict[str, Any], """ parsed = SearchDetails.from_kwargs(details) if parsed.geometry_output != GeometryFormat.NONE: - if GeometryFormat.GEOJSON in parsed.geometry_output: + if GeometryFormat.GEOJSON & parsed.geometry_output: queryparts['polygon_geojson'] = '1' - if GeometryFormat.KML in parsed.geometry_output: + if GeometryFormat.KML & parsed.geometry_output: queryparts['polygon_kml'] = '1' - if GeometryFormat.SVG in parsed.geometry_output: + if GeometryFormat.SVG & parsed.geometry_output: queryparts['polygon_svg'] = '1' - if GeometryFormat.TEXT in parsed.geometry_output: + if GeometryFormat.TEXT & parsed.geometry_output: queryparts['polygon_text'] = '1' if parsed.address_details: queryparts['addressdetails'] = '1' @@ -135,15 +135,18 @@ def _is_postcode_relation_for(result: SearchResult, postcode: str) -> bool: and result.names.get('ref') == postcode -def _deg(axis:str) -> str: +def _deg(axis: str) -> str: return f"(?P<{axis}_deg>\\d+\\.\\d+)°?" + def _deg_min(axis: str) -> str: return f"(?P<{axis}_deg>\\d+)[°\\s]+(?P<{axis}_min>[\\d.]+)[′']*" + def _deg_min_sec(axis: str) -> str: return f"(?P<{axis}_deg>\\d+)[°\\s]+(?P<{axis}_min>\\d+)[′'\\s]+(?P<{axis}_sec>[\\d.]+)[\"″]*" + COORD_REGEX = [re.compile(r'(?:(?P
.*?)\s+)??' + r + r'(?:\s+(?P.*))?') for r in (
     r"(?P[NS])\s*" + _deg('lat') + r"[\s,]+" + r"(?P[EW])\s*" + _deg('lon'),
     _deg('lat') + r"\s*(?P[NS])[\s,]+" + _deg('lon') + r"\s*(?P[EW])",
@@ -154,6 +157,7 @@ COORD_REGEX = [re.compile(r'(?:(?P
.*?)\s+)??' + r + r'(?:\s+(?P.*))?'
     r"\[?(?P[+-]?\d+\.\d+)[\s,]+(?P[+-]?\d+\.\d+)\]?"
 )]
 
+
 def extract_coords_from_query(query: str) -> Tuple[str, Optional[float], Optional[float]]:
     """ Look for something that is formatted like a coordinate at the
         beginning or end of the query. If found, extract the coordinate and
@@ -185,6 +189,7 @@ def extract_coords_from_query(query: str) -> Tuple[str, Optional[float], Optiona
 
 CATEGORY_REGEX = re.compile(r'(?P
.*?)\[(?P[a-zA-Z_]+)=(?P[a-zA-Z_]+)\](?P.*)')
 
+
 def extract_category_from_query(query: str) -> Tuple[str, Optional[str], Optional[str]]:
     """ Extract a hidden category specification of the form '[key=value]' from
         the query. If found, extract key and value  and