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