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