]> git.openstreetmap.org Git - nominatim.git/blob - lib/ClassTypes.php
Merge pull request #1809 from lonvia/fix-display-names
[nominatim.git] / lib / ClassTypes.php
1 <?php
2
3 namespace Nominatim\ClassTypes;
4
5 /**
6  * Create a label tag for the given place that can be used as an XML name.
7  *
8  * @param array[] $aPlace  Information about the place to label.
9  *
10  * A label tag groups various object types together under a common
11  * label. The returned value is lower case and has no spaces
12  */
13 function getLabelTag($aPlace, $sCountry = null)
14 {
15     $iRank = (int) ($aPlace['rank_address'] ?? 30);
16     $sLabel;
17     if (isset($aPlace['place_type'])) {
18         $sLabel = $aPlace['place_type'];
19     } elseif ($aPlace['class'] == 'boundary' && $aPlace['type'] == 'administrative') {
20         $sLabel = getBoundaryLabel($iRank/2, $sCountry);
21     } elseif ($iRank < 26) {
22         $sLabel = $aPlace['type'];
23     } elseif ($iRank < 28) {
24         $sLabel = 'road';
25     } elseif ($aPlace['class'] == 'place'
26             && ($aPlace['type'] == 'house_number' ||
27                 $aPlace['type'] == 'house_name' ||
28                 $aPlace['type'] == 'country_code')
29     ) {
30         $sLabel = $aPlace['type'];
31     } else {
32         $sLabel = $aPlace['class'];
33     }
34
35     return strtolower(str_replace(' ', '_', $sLabel));
36 }
37
38 /**
39  * Create a label for the given place.
40  *
41  * @param array[] $aPlace  Information about the place to label.
42  */
43 function getLabel($aPlace, $sCountry = null)
44 {
45     if (isset($aPlace['place_type'])) {
46         return ucwords(str_replace('_', ' ', $aPlace['place_type']));
47     }
48
49     if ($aPlace['class'] == 'boundary' && $aPlace['type'] == 'administrative') {
50         return getBoundaryLabel(($aPlace['rank_address'] ?? 30)/2, $sCountry ?? null);
51     }
52
53     // Return a label only for 'important' class/type combinations
54     if (getImportance($aPlace) !== null) {
55         return ucwords(str_replace('_', ' ', $aPlace['type']));
56     }
57
58     return null;
59 }
60
61
62 /**
63  * Return a simple label for an administrative boundary for the given country.
64  *
65  * @param int $iAdminLevel   Content of admin_level tag.
66  * @param string $sCountry   Country code of the country where the object is
67  *                           in. May be null, in which case a world-wide
68  *                           fallback is used.
69  * @param string $sFallback  String to return if no explicit string is listed.
70  *
71  * @return string
72  */
73 function getBoundaryLabel($iAdminLevel, $sCountry, $sFallback = 'Administrative')
74 {
75     static $aBoundaryList = array (
76                              'default' => array (
77                                            1 => 'Continent',
78                                            2 => 'Country',
79                                            3 => 'Region',
80                                            4 => 'State',
81                                            5 => 'State District',
82                                            6 => 'County',
83                                            7 => 'Municipality',
84                                            8 => 'City',
85                                            9 => 'City District',
86                                            10 => 'Suburb',
87                                            11 => 'Neighbourhood'
88                                           ),
89                              'no' => array (
90                                       3 => 'State',
91                                       4 => 'County'
92                                      ),
93                              'se' => array (
94                                       3 => 'State',
95                                       4 => 'County'
96                                      )
97             );
98
99     if (isset($aBoundaryList[$sCountry])
100         && isset($aBoundaryList[$sCountry][$iAdminLevel])
101     ) {
102         return $aBoundaryList[$sCountry][$iAdminLevel];
103     }
104
105     return $aBoundaryList['default'][$iAdminLevel] ?? $sFallback;
106 }
107
108 /**
109  * Return an estimated radius of how far the object node extends.
110  *
111  * @param array[] $aPlace  Information about the place. This must be a node
112  *                         feature.
113  *
114  * @return float  The radius around the feature in degrees.
115  */
116 function getDefRadius($aPlace)
117 {
118     $aSpecialRadius = array(
119                        'place:continent' => 25,
120                        'place:country' => 7,
121                        'place:state' => 2.6,
122                        'place:province' => 2.6,
123                        'place:region' => 1.0,
124                        'place:county' => 0.7,
125                        'place:city' => 0.16,
126                        'place:municipality' => 0.16,
127                        'place:island' => 0.32,
128                        'place:postcode' => 0.16,
129                        'place:town' => 0.04,
130                        'place:village' => 0.02,
131                        'place:hamlet' => 0.02,
132                        'place:district' => 0.02,
133                        'place:borough' => 0.02,
134                        'place:suburb' => 0.02,
135                        'place:locality' => 0.01,
136                        'place:neighbourhood'=> 0.01,
137                        'place:quarter' => 0.01,
138                        'place:city_block' => 0.01,
139                        'landuse:farm' => 0.01,
140                        'place:farm' => 0.01,
141                        'place:airport' => 0.015,
142                        'aeroway:aerodrome' => 0.015,
143                        'railway:station' => 0.005
144            );
145
146     $sClassPlace = $aPlace['class'].':'.$aPlace['type'];
147
148     return $aSpecialRadius[$sClassPlace] ?? 0.00005;
149 }
150
151 /**
152  * Get the icon to use with the given object.
153  */
154 function getIcon($aPlace)
155 {
156     $aIcons = array(
157                'boundary:administrative' => 'poi_boundary_administrative',
158                'place:city' => 'poi_place_city',
159                'place:town' => 'poi_place_town',
160                'place:village' => 'poi_place_village',
161                'place:hamlet' => 'poi_place_village',
162                'place:suburb' => 'poi_place_village',
163                'place:locality' => 'poi_place_village',
164                'place:airport' => 'transport_airport2',
165                'aeroway:aerodrome' => 'transport_airport2',
166                'railway:station' => 'transport_train_station2',
167                'amenity:place_of_worship' => 'place_of_worship_unknown3',
168                'amenity:pub' => 'food_pub',
169                'amenity:bar' => 'food_bar',
170                'amenity:university' => 'education_university',
171                'tourism:museum' => 'tourist_museum',
172                'amenity:arts_centre' => 'tourist_art_gallery2',
173                'tourism:zoo' => 'tourist_zoo',
174                'tourism:theme_park' => 'poi_point_of_interest',
175                'tourism:attraction' => 'poi_point_of_interest',
176                'leisure:golf_course' => 'sport_golf',
177                'historic:castle' => 'tourist_castle',
178                'amenity:hospital' => 'health_hospital',
179                'amenity:school' => 'education_school',
180                'amenity:theatre' => 'tourist_theatre',
181                'amenity:library' => 'amenity_library',
182                'amenity:fire_station' => 'amenity_firestation3',
183                'amenity:police' => 'amenity_police2',
184                'amenity:bank' => 'money_bank2',
185                'amenity:post_office' => 'amenity_post_office',
186                'tourism:hotel' => 'accommodation_hotel2',
187                'amenity:cinema' => 'tourist_cinema',
188                'tourism:artwork' => 'tourist_art_gallery2',
189                'historic:archaeological_site' => 'tourist_archaeological2',
190                'amenity:doctors' => 'health_doctors',
191                'leisure:sports_centre' => 'sport_leisure_centre',
192                'leisure:swimming_pool' => 'sport_swimming_outdoor',
193                'shop:supermarket' => 'shopping_supermarket',
194                'shop:convenience' => 'shopping_convenience',
195                'amenity:restaurant' => 'food_restaurant',
196                'amenity:fast_food' => 'food_fastfood',
197                'amenity:cafe' => 'food_cafe',
198                'tourism:guest_house' => 'accommodation_bed_and_breakfast',
199                'amenity:pharmacy' => 'health_pharmacy_dispensing',
200                'amenity:fuel' => 'transport_fuel',
201                'natural:peak' => 'poi_peak',
202                'natural:wood' => 'landuse_coniferous_and_deciduous',
203                'shop:bicycle' => 'shopping_bicycle',
204                'shop:clothes' => 'shopping_clothes',
205                'shop:hairdresser' => 'shopping_hairdresser',
206                'shop:doityourself' => 'shopping_diy',
207                'shop:estate_agent' => 'shopping_estateagent2',
208                'shop:car' => 'shopping_car',
209                'shop:garden_centre' => 'shopping_garden_centre',
210                'shop:car_repair' => 'shopping_car_repair',
211                'shop:bakery' => 'shopping_bakery',
212                'shop:butcher' => 'shopping_butcher',
213                'shop:apparel' => 'shopping_clothes',
214                'shop:laundry' => 'shopping_laundrette',
215                'shop:beverages' => 'shopping_alcohol',
216                'shop:alcohol' => 'shopping_alcohol',
217                'shop:optician' => 'health_opticians',
218                'shop:chemist' => 'health_pharmacy',
219                'shop:gallery' => 'tourist_art_gallery2',
220                'shop:jewelry' => 'shopping_jewelry',
221                'tourism:information' => 'amenity_information',
222                'historic:ruins' => 'tourist_ruin',
223                'amenity:college' => 'education_school',
224                'historic:monument' => 'tourist_monument',
225                'historic:memorial' => 'tourist_monument',
226                'historic:mine' => 'poi_mine',
227                'tourism:caravan_site' => 'accommodation_caravan_park',
228                'amenity:bus_station' => 'transport_bus_station',
229                'amenity:atm' => 'money_atm2',
230                'tourism:viewpoint' => 'tourist_view_point',
231                'tourism:guesthouse' => 'accommodation_bed_and_breakfast',
232                'railway:tram' => 'transport_tram_stop',
233                'amenity:courthouse' => 'amenity_court',
234                'amenity:recycling' => 'amenity_recycling',
235                'amenity:dentist' => 'health_dentist',
236                'natural:beach' => 'tourist_beach',
237                'railway:tram_stop' => 'transport_tram_stop',
238                'amenity:prison' => 'amenity_prison',
239                'highway:bus_stop' => 'transport_bus_stop2'
240     );
241
242     $sClassPlace = $aPlace['class'].':'.$aPlace['type'];
243
244     return $aIcons[$sClassPlace] ?? null;
245 }
246
247 /**
248  * Get an icon for the given object with its full URL.
249  */
250 function getIconFile($aPlace)
251 {
252     $sIcon = getIcon($aPlace);
253
254     if (!isset($sIcon)) {
255         return null;
256     }
257
258     return CONST_Website_BaseURL.'images/mapicons/'.$sIcon.'.p.20.png';
259 }
260
261 /**
262  * Return a class importance value for the given place.
263  *
264  * @param array[] $aPlace  Information about the place.
265  *
266  * @return int  An importance value. The lower the value, the more
267  *              important the class.
268  */
269 function getImportance($aPlace)
270 {
271     static $aWithImportance = null;
272
273     if ($aWithImportance === null) {
274         $aWithImportance = array_flip(array(
275                                            'place:country',
276                                            'place:state',
277                                            'place:province',
278                                            'place:county',
279                                            'place:city',
280                                            'place:region',
281                                            'place:island',
282                                            'place:town',
283                                            'place:village',
284                                            'place:hamlet',
285                                            'place:suburb',
286                                            'place:locality',
287                                            'landuse:farm',
288                                            'place:farm',
289                                            'highway:motorway_junction',
290                                            'highway:motorway',
291                                            'highway:trunk',
292                                            'highway:primary',
293                                            'highway:secondary',
294                                            'highway:tertiary',
295                                            'highway:residential',
296                                            'highway:unclassified',
297                                            'highway:living_street',
298                                            'highway:service',
299                                            'highway:track',
300                                            'highway:road',
301                                            'highway:byway',
302                                            'highway:bridleway',
303                                            'highway:cycleway',
304                                            'highway:pedestrian',
305                                            'highway:footway',
306                                            'highway:steps',
307                                            'highway:motorway_link',
308                                            'highway:trunk_link',
309                                            'highway:primary_link',
310                                            'landuse:industrial',
311                                            'landuse:residential',
312                                            'landuse:retail',
313                                            'landuse:commercial',
314                                            'place:airport',
315                                            'aeroway:aerodrome',
316                                            'railway:station',
317                                            'amenity:place_of_worship',
318                                            'amenity:pub',
319                                            'amenity:bar',
320                                            'amenity:university',
321                                            'tourism:museum',
322                                            'amenity:arts_centre',
323                                            'tourism:zoo',
324                                            'tourism:theme_park',
325                                            'tourism:attraction',
326                                            'leisure:golf_course',
327                                            'historic:castle',
328                                            'amenity:hospital',
329                                            'amenity:school',
330                                            'amenity:theatre',
331                                            'amenity:public_building',
332                                            'amenity:library',
333                                            'amenity:townhall',
334                                            'amenity:community_centre',
335                                            'amenity:fire_station',
336                                            'amenity:police',
337                                            'amenity:bank',
338                                            'amenity:post_office',
339                                            'leisure:park',
340                                            'amenity:park',
341                                            'landuse:park',
342                                            'landuse:recreation_ground',
343                                            'tourism:hotel',
344                                            'tourism:motel',
345                                            'amenity:cinema',
346                                            'tourism:artwork',
347                                            'historic:archaeological_site',
348                                            'amenity:doctors',
349                                            'leisure:sports_centre',
350                                            'leisure:swimming_pool',
351                                            'shop:supermarket',
352                                            'shop:convenience',
353                                            'amenity:restaurant',
354                                            'amenity:fast_food',
355                                            'amenity:cafe',
356                                            'tourism:guest_house',
357                                            'amenity:pharmacy',
358                                            'amenity:fuel',
359                                            'natural:peak',
360                                            'waterway:waterfall',
361                                            'natural:wood',
362                                            'natural:water',
363                                            'landuse:forest',
364                                            'landuse:cemetery',
365                                            'landuse:allotments',
366                                            'landuse:farmyard',
367                                            'railway:rail',
368                                            'waterway:canal',
369                                            'waterway:river',
370                                            'waterway:stream',
371                                            'shop:bicycle',
372                                            'shop:clothes',
373                                            'shop:hairdresser',
374                                            'shop:doityourself',
375                                            'shop:estate_agent',
376                                            'shop:car',
377                                            'shop:garden_centre',
378                                            'shop:car_repair',
379                                            'shop:newsagent',
380                                            'shop:bakery',
381                                            'shop:furniture',
382                                            'shop:butcher',
383                                            'shop:apparel',
384                                            'shop:electronics',
385                                            'shop:department_store',
386                                            'shop:books',
387                                            'shop:yes',
388                                            'shop:outdoor',
389                                            'shop:mall',
390                                            'shop:florist',
391                                            'shop:charity',
392                                            'shop:hardware',
393                                            'shop:laundry',
394                                            'shop:shoes',
395                                            'shop:beverages',
396                                            'shop:dry_cleaning',
397                                            'shop:carpet',
398                                            'shop:computer',
399                                            'shop:alcohol',
400                                            'shop:optician',
401                                            'shop:chemist',
402                                            'shop:gallery',
403                                            'shop:mobile_phone',
404                                            'shop:sports',
405                                            'shop:jewelry',
406                                            'shop:pet',
407                                            'shop:beauty',
408                                            'shop:stationery',
409                                            'shop:shopping_centre',
410                                            'shop:general',
411                                            'shop:electrical',
412                                            'shop:toys',
413                                            'shop:jeweller',
414                                            'shop:betting',
415                                            'shop:household',
416                                            'shop:travel_agency',
417                                            'shop:hifi',
418                                            'amenity:shop',
419                                            'tourism:information',
420                                            'place:house',
421                                            'place:house_name',
422                                            'place:house_number',
423                                            'place:country_code',
424                                            'leisure:pitch',
425                                            'highway:unsurfaced',
426                                            'historic:ruins',
427                                            'amenity:college',
428                                            'historic:monument',
429                                            'railway:subway',
430                                            'historic:memorial',
431                                            'leisure:nature_reserve',
432                                            'leisure:common',
433                                            'waterway:lock_gate',
434                                            'natural:fell',
435                                            'amenity:nightclub',
436                                            'highway:path',
437                                            'leisure:garden',
438                                            'landuse:reservoir',
439                                            'leisure:playground',
440                                            'leisure:stadium',
441                                            'historic:mine',
442                                            'natural:cliff',
443                                            'tourism:caravan_site',
444                                            'amenity:bus_station',
445                                            'amenity:kindergarten',
446                                            'highway:construction',
447                                            'amenity:atm',
448                                            'amenity:emergency_phone',
449                                            'waterway:lock',
450                                            'waterway:riverbank',
451                                            'natural:coastline',
452                                            'tourism:viewpoint',
453                                            'tourism:hostel',
454                                            'tourism:bed_and_breakfast',
455                                            'railway:halt',
456                                            'railway:platform',
457                                            'railway:tram',
458                                            'amenity:courthouse',
459                                            'amenity:recycling',
460                                            'amenity:dentist',
461                                            'natural:beach',
462                                            'place:moor',
463                                            'amenity:grave_yard',
464                                            'waterway:drain',
465                                            'landuse:grass',
466                                            'landuse:village_green',
467                                            'natural:bay',
468                                            'railway:tram_stop',
469                                            'leisure:marina',
470                                            'highway:stile',
471                                            'natural:moor',
472                                            'railway:light_rail',
473                                            'railway:narrow_gauge',
474                                            'natural:land',
475                                            'amenity:village_hall',
476                                            'waterway:dock',
477                                            'amenity:veterinary',
478                                            'landuse:brownfield',
479                                            'leisure:track',
480                                            'railway:historic_station',
481                                            'landuse:construction',
482                                            'amenity:prison',
483                                            'landuse:quarry',
484                                            'amenity:telephone',
485                                            'highway:traffic_signals',
486                                            'natural:heath',
487                                            'historic:house',
488                                            'amenity:social_club',
489                                            'landuse:military',
490                                            'amenity:health_centre',
491                                            'historic:building',
492                                            'amenity:clinic',
493                                            'highway:services',
494                                            'amenity:ferry_terminal',
495                                            'natural:marsh',
496                                            'natural:hill',
497                                            'highway:raceway',
498                                            'amenity:taxi',
499                                            'amenity:take_away',
500                                            'amenity:car_rental',
501                                            'place:islet',
502                                            'amenity:nursery',
503                                            'amenity:nursing_home',
504                                            'amenity:toilets',
505                                            'amenity:hall',
506                                            'waterway:boatyard',
507                                            'highway:mini_roundabout',
508                                            'historic:manor',
509                                            'tourism:chalet',
510                                            'amenity:bicycle_parking',
511                                            'amenity:hotel',
512                                            'waterway:weir',
513                                            'natural:wetland',
514                                            'natural:cave_entrance',
515                                            'amenity:crematorium',
516                                            'tourism:picnic_site',
517                                            'landuse:wood',
518                                            'landuse:basin',
519                                            'natural:tree',
520                                            'leisure:slipway',
521                                            'landuse:meadow',
522                                            'landuse:piste',
523                                            'amenity:care_home',
524                                            'amenity:club',
525                                            'amenity:medical_centre',
526                                            'historic:roman_road',
527                                            'historic:fort',
528                                            'railway:subway_entrance',
529                                            'historic:yes',
530                                            'highway:gate',
531                                            'leisure:fishing',
532                                            'historic:museum',
533                                            'amenity:car_wash',
534                                            'railway:level_crossing',
535                                            'leisure:bird_hide',
536                                            'natural:headland',
537                                            'tourism:apartments',
538                                            'amenity:shopping',
539                                            'natural:scrub',
540                                            'natural:fen',
541                                            'building:yes',
542                                            'mountain_pass:yes',
543                                            'amenity:parking',
544                                            'highway:bus_stop',
545                                            'place:postcode',
546                                            'amenity:post_box',
547                                            'place:houses',
548                                            'railway:preserved',
549                                            'waterway:derelict_canal',
550                                            'amenity:dead_pub',
551                                            'railway:disused_station',
552                                            'railway:abandoned',
553                                            'railway:disused'
554                 ));
555     }
556
557     $sClassPlace = $aPlace['class'].':'.$aPlace['type'];
558
559     return $aWithImportance[$sClassPlace] ?? null;
560 }