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