]> git.openstreetmap.org Git - nominatim.git/blob - lib/ClassTypes.php
utils/check_import_finished: skip some checks when setup ran with --drop
[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     if (CONST_MapIcon_URL === false) {
256         return null;
257     }
258
259     $sIcon = getIcon($aPlace);
260
261     if (!isset($sIcon)) {
262         return null;
263     }
264
265     return CONST_MapIcon_URL.'/'.$sIcon.'.p.20.png';
266 }
267
268 /**
269  * Return a class importance value for the given place.
270  *
271  * @param array[] $aPlace  Information about the place.
272  *
273  * @return int  An importance value. The lower the value, the more
274  *              important the class.
275  */
276 function getImportance($aPlace)
277 {
278     static $aWithImportance = null;
279
280     if ($aWithImportance === null) {
281         $aWithImportance = array_flip(array(
282                                            'boundary:administrative',
283                                            'place:country',
284                                            'place:state',
285                                            'place:province',
286                                            'place:county',
287                                            'place:city',
288                                            'place:region',
289                                            'place:island',
290                                            'place:town',
291                                            'place:village',
292                                            'place:hamlet',
293                                            'place:suburb',
294                                            'place:locality',
295                                            'landuse:farm',
296                                            'place:farm',
297                                            'highway:motorway_junction',
298                                            'highway:motorway',
299                                            'highway:trunk',
300                                            'highway:primary',
301                                            'highway:secondary',
302                                            'highway:tertiary',
303                                            'highway:residential',
304                                            'highway:unclassified',
305                                            'highway:living_street',
306                                            'highway:service',
307                                            'highway:track',
308                                            'highway:road',
309                                            'highway:byway',
310                                            'highway:bridleway',
311                                            'highway:cycleway',
312                                            'highway:pedestrian',
313                                            'highway:footway',
314                                            'highway:steps',
315                                            'highway:motorway_link',
316                                            'highway:trunk_link',
317                                            'highway:primary_link',
318                                            'landuse:industrial',
319                                            'landuse:residential',
320                                            'landuse:retail',
321                                            'landuse:commercial',
322                                            'place:airport',
323                                            'aeroway:aerodrome',
324                                            'railway:station',
325                                            'amenity:place_of_worship',
326                                            'amenity:pub',
327                                            'amenity:bar',
328                                            'amenity:university',
329                                            'tourism:museum',
330                                            'amenity:arts_centre',
331                                            'tourism:zoo',
332                                            'tourism:theme_park',
333                                            'tourism:attraction',
334                                            'leisure:golf_course',
335                                            'historic:castle',
336                                            'amenity:hospital',
337                                            'amenity:school',
338                                            'amenity:theatre',
339                                            'amenity:public_building',
340                                            'amenity:library',
341                                            'amenity:townhall',
342                                            'amenity:community_centre',
343                                            'amenity:fire_station',
344                                            'amenity:police',
345                                            'amenity:bank',
346                                            'amenity:post_office',
347                                            'leisure:park',
348                                            'amenity:park',
349                                            'landuse:park',
350                                            'landuse:recreation_ground',
351                                            'tourism:hotel',
352                                            'tourism:motel',
353                                            'amenity:cinema',
354                                            'tourism:artwork',
355                                            'historic:archaeological_site',
356                                            'amenity:doctors',
357                                            'leisure:sports_centre',
358                                            'leisure:swimming_pool',
359                                            'shop:supermarket',
360                                            'shop:convenience',
361                                            'amenity:restaurant',
362                                            'amenity:fast_food',
363                                            'amenity:cafe',
364                                            'tourism:guest_house',
365                                            'amenity:pharmacy',
366                                            'amenity:fuel',
367                                            'natural:peak',
368                                            'waterway:waterfall',
369                                            'natural:wood',
370                                            'natural:water',
371                                            'landuse:forest',
372                                            'landuse:cemetery',
373                                            'landuse:allotments',
374                                            'landuse:farmyard',
375                                            'railway:rail',
376                                            'waterway:canal',
377                                            'waterway:river',
378                                            'waterway:stream',
379                                            'shop:bicycle',
380                                            'shop:clothes',
381                                            'shop:hairdresser',
382                                            'shop:doityourself',
383                                            'shop:estate_agent',
384                                            'shop:car',
385                                            'shop:garden_centre',
386                                            'shop:car_repair',
387                                            'shop:newsagent',
388                                            'shop:bakery',
389                                            'shop:furniture',
390                                            'shop:butcher',
391                                            'shop:apparel',
392                                            'shop:electronics',
393                                            'shop:department_store',
394                                            'shop:books',
395                                            'shop:yes',
396                                            'shop:outdoor',
397                                            'shop:mall',
398                                            'shop:florist',
399                                            'shop:charity',
400                                            'shop:hardware',
401                                            'shop:laundry',
402                                            'shop:shoes',
403                                            'shop:beverages',
404                                            'shop:dry_cleaning',
405                                            'shop:carpet',
406                                            'shop:computer',
407                                            'shop:alcohol',
408                                            'shop:optician',
409                                            'shop:chemist',
410                                            'shop:gallery',
411                                            'shop:mobile_phone',
412                                            'shop:sports',
413                                            'shop:jewelry',
414                                            'shop:pet',
415                                            'shop:beauty',
416                                            'shop:stationery',
417                                            'shop:shopping_centre',
418                                            'shop:general',
419                                            'shop:electrical',
420                                            'shop:toys',
421                                            'shop:jeweller',
422                                            'shop:betting',
423                                            'shop:household',
424                                            'shop:travel_agency',
425                                            'shop:hifi',
426                                            'amenity:shop',
427                                            'tourism:information',
428                                            'place:house',
429                                            'place:house_name',
430                                            'place:house_number',
431                                            'place:country_code',
432                                            'leisure:pitch',
433                                            'highway:unsurfaced',
434                                            'historic:ruins',
435                                            'amenity:college',
436                                            'historic:monument',
437                                            'railway:subway',
438                                            'historic:memorial',
439                                            'leisure:nature_reserve',
440                                            'leisure:common',
441                                            'waterway:lock_gate',
442                                            'natural:fell',
443                                            'amenity:nightclub',
444                                            'highway:path',
445                                            'leisure:garden',
446                                            'landuse:reservoir',
447                                            'leisure:playground',
448                                            'leisure:stadium',
449                                            'historic:mine',
450                                            'natural:cliff',
451                                            'tourism:caravan_site',
452                                            'amenity:bus_station',
453                                            'amenity:kindergarten',
454                                            'highway:construction',
455                                            'amenity:atm',
456                                            'amenity:emergency_phone',
457                                            'waterway:lock',
458                                            'waterway:riverbank',
459                                            'natural:coastline',
460                                            'tourism:viewpoint',
461                                            'tourism:hostel',
462                                            'tourism:bed_and_breakfast',
463                                            'railway:halt',
464                                            'railway:platform',
465                                            'railway:tram',
466                                            'amenity:courthouse',
467                                            'amenity:recycling',
468                                            'amenity:dentist',
469                                            'natural:beach',
470                                            'place:moor',
471                                            'amenity:grave_yard',
472                                            'waterway:drain',
473                                            'landuse:grass',
474                                            'landuse:village_green',
475                                            'natural:bay',
476                                            'railway:tram_stop',
477                                            'leisure:marina',
478                                            'highway:stile',
479                                            'natural:moor',
480                                            'railway:light_rail',
481                                            'railway:narrow_gauge',
482                                            'natural:land',
483                                            'amenity:village_hall',
484                                            'waterway:dock',
485                                            'amenity:veterinary',
486                                            'landuse:brownfield',
487                                            'leisure:track',
488                                            'railway:historic_station',
489                                            'landuse:construction',
490                                            'amenity:prison',
491                                            'landuse:quarry',
492                                            'amenity:telephone',
493                                            'highway:traffic_signals',
494                                            'natural:heath',
495                                            'historic:house',
496                                            'amenity:social_club',
497                                            'landuse:military',
498                                            'amenity:health_centre',
499                                            'historic:building',
500                                            'amenity:clinic',
501                                            'highway:services',
502                                            'amenity:ferry_terminal',
503                                            'natural:marsh',
504                                            'natural:hill',
505                                            'highway:raceway',
506                                            'amenity:taxi',
507                                            'amenity:take_away',
508                                            'amenity:car_rental',
509                                            'place:islet',
510                                            'amenity:nursery',
511                                            'amenity:nursing_home',
512                                            'amenity:toilets',
513                                            'amenity:hall',
514                                            'waterway:boatyard',
515                                            'highway:mini_roundabout',
516                                            'historic:manor',
517                                            'tourism:chalet',
518                                            'amenity:bicycle_parking',
519                                            'amenity:hotel',
520                                            'waterway:weir',
521                                            'natural:wetland',
522                                            'natural:cave_entrance',
523                                            'amenity:crematorium',
524                                            'tourism:picnic_site',
525                                            'landuse:wood',
526                                            'landuse:basin',
527                                            'natural:tree',
528                                            'leisure:slipway',
529                                            'landuse:meadow',
530                                            'landuse:piste',
531                                            'amenity:care_home',
532                                            'amenity:club',
533                                            'amenity:medical_centre',
534                                            'historic:roman_road',
535                                            'historic:fort',
536                                            'railway:subway_entrance',
537                                            'historic:yes',
538                                            'highway:gate',
539                                            'leisure:fishing',
540                                            'historic:museum',
541                                            'amenity:car_wash',
542                                            'railway:level_crossing',
543                                            'leisure:bird_hide',
544                                            'natural:headland',
545                                            'tourism:apartments',
546                                            'amenity:shopping',
547                                            'natural:scrub',
548                                            'natural:fen',
549                                            'building:yes',
550                                            'mountain_pass:yes',
551                                            'amenity:parking',
552                                            'highway:bus_stop',
553                                            'place:postcode',
554                                            'amenity:post_box',
555                                            'place:houses',
556                                            'railway:preserved',
557                                            'waterway:derelict_canal',
558                                            'amenity:dead_pub',
559                                            'railway:disused_station',
560                                            'railway:abandoned',
561                                            'railway:disused'
562                 ));
563     }
564
565     $sClassPlace = $aPlace['class'].':'.$aPlace['type'];
566
567     return $aWithImportance[$sClassPlace] ?? null;
568 }