]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/api/v1/classtypes.py
273fe2f5bf97ec39fb8bfa8dd5861779a8e429cd
[nominatim.git] / nominatim / api / v1 / classtypes.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 Hard-coded information about tag catagories.
9
10 These tables have been copied verbatim from the old PHP code. For future
11 version a more flexible formatting is required.
12 """
13 from typing import Tuple, Optional, Mapping, Union
14
15 import nominatim.api as napi
16
17 def get_label_tag(category: Tuple[str, str], extratags: Optional[Mapping[str, str]],
18                   rank: int, country: Optional[str]) -> str:
19     """ Create a label tag for the given place that can be used as an XML name.
20     """
21     if rank < 26 and extratags and 'place' in extratags:
22         label = extratags['place']
23     elif rank < 26 and extratags and 'linked_place' in extratags:
24         label = extratags['linked_place']
25     elif category == ('boundary', 'administrative'):
26         label = ADMIN_LABELS.get((country or '', int(rank/2)))\
27                 or ADMIN_LABELS.get(('', int(rank/2)))\
28                 or 'Administrative'
29     elif category[1] == 'postal_code':
30         label = 'postcode'
31     elif rank < 26:
32         label = category[1] if category[1] != 'yes' else category[0]
33     elif rank < 28:
34         label = 'road'
35     elif category[0] == 'place'\
36          and category[1] in ('house_number', 'house_name', 'country_code'):
37         label = category[1]
38     else:
39         label = category[0]
40
41     return label.lower().replace(' ', '_')
42
43
44 def bbox_from_result(result: Union[napi.ReverseResult, napi.SearchResult]) -> napi.Bbox:
45     """ Compute a bounding box for the result. For ways and relations
46         a given boundingbox is used. For all other object, a box is computed
47         around the centroid according to dimensions dereived from the
48         search rank.
49     """
50     if (result.osm_object and result.osm_object[0] == 'N') or result.bbox is None:
51         extent = NODE_EXTENT.get(result.category, 0.00005)
52         return napi.Bbox.from_point(result.centroid, extent)
53
54     return result.bbox
55
56
57 # pylint: disable=line-too-long
58 OSM_ATTRIBUTION = 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright'
59
60
61 OSM_TYPE_NAME = {
62     'N': 'node',
63     'W': 'way',
64     'R': 'relation'
65 }
66
67
68 ADMIN_LABELS = {
69   ('', 1): 'Continent',
70   ('', 2): 'Country',
71   ('', 3): 'Region',
72   ('', 4): 'State',
73   ('', 5): 'State District',
74   ('', 6): 'County',
75   ('', 7): 'Municipality',
76   ('', 8): 'City',
77   ('', 9): 'City District',
78   ('', 10): 'Suburb',
79   ('', 11): 'Neighbourhood',
80   ('', 12): 'City Block',
81   ('no', 3): 'State',
82   ('no', 4): 'County',
83   ('se', 3): 'State',
84   ('se', 4): 'County'
85 }
86
87
88 ICONS = {
89     ('boundary', 'administrative'): 'poi_boundary_administrative',
90     ('place', 'city'): 'poi_place_city',
91     ('place', 'town'): 'poi_place_town',
92     ('place', 'village'): 'poi_place_village',
93     ('place', 'hamlet'): 'poi_place_village',
94     ('place', 'suburb'): 'poi_place_village',
95     ('place', 'locality'): 'poi_place_village',
96     ('place', 'airport'): 'transport_airport2',
97     ('aeroway', 'aerodrome'): 'transport_airport2',
98     ('railway', 'station'): 'transport_train_station2',
99     ('amenity', 'place_of_worship'): 'place_of_worship_unknown3',
100     ('amenity', 'pub'): 'food_pub',
101     ('amenity', 'bar'): 'food_bar',
102     ('amenity', 'university'): 'education_university',
103     ('tourism', 'museum'): 'tourist_museum',
104     ('amenity', 'arts_centre'): 'tourist_art_gallery2',
105     ('tourism', 'zoo'): 'tourist_zoo',
106     ('tourism', 'theme_park'): 'poi_point_of_interest',
107     ('tourism', 'attraction'): 'poi_point_of_interest',
108     ('leisure', 'golf_course'): 'sport_golf',
109     ('historic', 'castle'): 'tourist_castle',
110     ('amenity', 'hospital'): 'health_hospital',
111     ('amenity', 'school'): 'education_school',
112     ('amenity', 'theatre'): 'tourist_theatre',
113     ('amenity', 'library'): 'amenity_library',
114     ('amenity', 'fire_station'): 'amenity_firestation3',
115     ('amenity', 'police'): 'amenity_police2',
116     ('amenity', 'bank'): 'money_bank2',
117     ('amenity', 'post_office'): 'amenity_post_office',
118     ('tourism', 'hotel'): 'accommodation_hotel2',
119     ('amenity', 'cinema'): 'tourist_cinema',
120     ('tourism', 'artwork'): 'tourist_art_gallery2',
121     ('historic', 'archaeological_site'): 'tourist_archaeological2',
122     ('amenity', 'doctors'): 'health_doctors',
123     ('leisure', 'sports_centre'): 'sport_leisure_centre',
124     ('leisure', 'swimming_pool'): 'sport_swimming_outdoor',
125     ('shop', 'supermarket'): 'shopping_supermarket',
126     ('shop', 'convenience'): 'shopping_convenience',
127     ('amenity', 'restaurant'): 'food_restaurant',
128     ('amenity', 'fast_food'): 'food_fastfood',
129     ('amenity', 'cafe'): 'food_cafe',
130     ('tourism', 'guest_house'): 'accommodation_bed_and_breakfast',
131     ('amenity', 'pharmacy'): 'health_pharmacy_dispensing',
132     ('amenity', 'fuel'): 'transport_fuel',
133     ('natural', 'peak'): 'poi_peak',
134     ('natural', 'wood'): 'landuse_coniferous_and_deciduous',
135     ('shop', 'bicycle'): 'shopping_bicycle',
136     ('shop', 'clothes'): 'shopping_clothes',
137     ('shop', 'hairdresser'): 'shopping_hairdresser',
138     ('shop', 'doityourself'): 'shopping_diy',
139     ('shop', 'estate_agent'): 'shopping_estateagent2',
140     ('shop', 'car'): 'shopping_car',
141     ('shop', 'garden_centre'): 'shopping_garden_centre',
142     ('shop', 'car_repair'): 'shopping_car_repair',
143     ('shop', 'bakery'): 'shopping_bakery',
144     ('shop', 'butcher'): 'shopping_butcher',
145     ('shop', 'apparel'): 'shopping_clothes',
146     ('shop', 'laundry'): 'shopping_laundrette',
147     ('shop', 'beverages'): 'shopping_alcohol',
148     ('shop', 'alcohol'): 'shopping_alcohol',
149     ('shop', 'optician'): 'health_opticians',
150     ('shop', 'chemist'): 'health_pharmacy',
151     ('shop', 'gallery'): 'tourist_art_gallery2',
152     ('shop', 'jewelry'): 'shopping_jewelry',
153     ('tourism', 'information'): 'amenity_information',
154     ('historic', 'ruins'): 'tourist_ruin',
155     ('amenity', 'college'): 'education_school',
156     ('historic', 'monument'): 'tourist_monument',
157     ('historic', 'memorial'): 'tourist_monument',
158     ('historic', 'mine'): 'poi_mine',
159     ('tourism', 'caravan_site'): 'accommodation_caravan_park',
160     ('amenity', 'bus_station'): 'transport_bus_station',
161     ('amenity', 'atm'): 'money_atm2',
162     ('tourism', 'viewpoint'): 'tourist_view_point',
163     ('tourism', 'guesthouse'): 'accommodation_bed_and_breakfast',
164     ('railway', 'tram'): 'transport_tram_stop',
165     ('amenity', 'courthouse'): 'amenity_court',
166     ('amenity', 'recycling'): 'amenity_recycling',
167     ('amenity', 'dentist'): 'health_dentist',
168     ('natural', 'beach'): 'tourist_beach',
169     ('railway', 'tram_stop'): 'transport_tram_stop',
170     ('amenity', 'prison'): 'amenity_prison',
171     ('highway', 'bus_stop'): 'transport_bus_stop2'
172 }
173
174 NODE_EXTENT = {
175     ('place', 'continent'): 25,
176     ('place', 'country'): 7,
177     ('place', 'state'): 2.6,
178     ('place', 'province'): 2.6,
179     ('place', 'region'): 1.0,
180     ('place', 'county'): 0.7,
181     ('place', 'city'): 0.16,
182     ('place', 'municipality'): 0.16,
183     ('place', 'island'): 0.32,
184     ('place', 'postcode'): 0.16,
185     ('place', 'town'): 0.04,
186     ('place', 'village'): 0.02,
187     ('place', 'hamlet'): 0.02,
188     ('place', 'district'): 0.02,
189     ('place', 'borough'): 0.02,
190     ('place', 'suburb'): 0.02,
191     ('place', 'locality'): 0.01,
192     ('place', 'neighbourhood'): 0.01,
193     ('place', 'quarter'): 0.01,
194     ('place', 'city_block'): 0.01,
195     ('landuse', 'farm'): 0.01,
196     ('place', 'farm'): 0.01,
197     ('place', 'airport'): 0.015,
198     ('aeroway', 'aerodrome'): 0.015,
199     ('railway', 'station'): 0.005
200 }