]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/api/v1/helpers.py
Merge pull request #3063 from lonvia/variable-parameters
[nominatim.git] / nominatim / api / v1 / helpers.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2023 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Helper function for parsing parameters and and outputting data
9 specifically for the v1 version of the API.
10 """
11
12 REVERSE_MAX_RANKS = [2, 2, 2,   # 0-2   Continent/Sea
13                      4, 4,      # 3-4   Country
14                      8,         # 5     State
15                      10, 10,    # 6-7   Region
16                      12, 12,    # 8-9   County
17                      16, 17,    # 10-11 City
18                      18,        # 12    Town
19                      19,        # 13    Village/Suburb
20                      22,        # 14    Hamlet/Neighbourhood
21                      25,        # 15    Localities
22                      26,        # 16    Major Streets
23                      27,        # 17    Minor Streets
24                      30         # 18    Building
25                     ]
26
27
28 def zoom_to_rank(zoom: int) -> int:
29     """ Convert a zoom parameter into a rank according to the v1 API spec.
30     """
31     return REVERSE_MAX_RANKS[max(0, min(18, zoom))]