-
Notifications
You must be signed in to change notification settings - Fork 44
/
views.sql
497 lines (492 loc) · 31.6 KB
/
views.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
DROP VIEW IF EXISTS cyclosm_ways;
CREATE VIEW cyclosm_ways AS
SELECT
way,
COALESCE(
CASE
WHEN highway='raceway' THEN 'track' -- render raceways as tracks
WHEN highway='trunk' THEN 'motorway' -- trunk as motorway, check can_bicycle if cyclable
WHEN highway='trunk_link' THEN 'motorway_link' -- trunk as motorway
WHEN highway='busway' THEN 'service' -- busway as service
WHEN highway='footway' AND (bicycle='yes' OR bicycle='designated' OR bicycle='permissive') THEN 'path'
WHEN highway='bridleway' AND (bicycle='yes' OR bicycle='designated' OR bicycle='permissive') THEN 'path'
WHEN highway!='bus_guideway' THEN highway
ELSE NULL
END,
CASE
WHEN railway IN ('light_rail', 'subway', 'narrow_gauge', 'rail', 'tram') THEN 'railway'
ELSE NULL
END
) AS type,
access,
layer,
CASE
WHEN tags->'maxspeed'~E'^\\d+$' THEN (tags->'maxspeed')::integer
WHEN tags->'maxspeed'~E'^\\d+ mph$' THEN REPLACE(tags->'maxspeed', ' mph', '')::integer * 1.609344
WHEN tags->'maxspeed'~E'^\\d+ knots$' THEN REPLACE(tags->'maxspeed', ' knots', '')::integer * 1.852
WHEN tags->'maxspeed'='walk' THEN 5
ELSE NULL
END AS maxspeed_kmh,
bicycle,
CASE
WHEN COALESCE(motorcar, tags->'motor_vehicle', tags->'vehicle', access, 'yes') NOT IN ('no', 'private', 'destination', 'agricultural', 'forestry') THEN 'yes'
-- goods and hgv don't need COALESCE chains, because the next step would be motorcar, which is checked above
WHEN tags->'goods' NOT IN ('no', 'private') THEN 'yes'
WHEN tags->'hgv' NOT IN ('no', 'private') THEN 'yes'
-- moped and mofa are not checked, since most countries that have separate access controls for them treat them as quasi-bicycles
WHEN COALESCE(tags->'motorcycle', tags->'motor_vehicle', tags->'vehicle', access, 'yes') NOT IN ('no', 'private', 'destination', 'agricultural', 'forestry') THEN 'yes'
-- TODO: style psv-only roads slightly differently
-- bus only needs to have its COALESCE chain go up to psv, because the next step would be motorcar, which is checked above
WHEN COALESCE(tags->'bus', tags->'psv') NOT IN ('no', 'private') THEN 'psv'
WHEN tags->'taxi' NOT IN ('no', 'private') THEN 'psv'
ELSE 'no'
END AS motor_vehicle,
CASE
WHEN tags->'cyclestreet' IN ('yes') THEN 'yes'
WHEN tags->'bicycle_road' IN ('yes') THEN 'yes'
ELSE 'no'
END AS cyclestreet,
CASE
WHEN oneway IN ('yes', '-1') THEN oneway
WHEN junction IN ('roundabout') AND (oneway IS NULL OR oneway NOT IN ('no', 'reversible')) THEN 'yes'
ELSE 'no'
END AS oneway,
CASE
WHEN tags->'cycleway:left' IN ('track', 'opposite_track')
AND COALESCE(tags->'cycleway:left:segregated',tags->'cycleway:both:segregated', tags->'cycleway:segregated') = 'no'
THEN 'shared_track'
WHEN tags->'cycleway:left' IN ('track', 'opposite_track') THEN 'track'
WHEN tags->'sidewalk:left:bicycle' != 'no' AND tags->'sidewalk:left:segregated' = 'yes' THEN 'track'
WHEN tags->'cycleway:left' IN ('lane', 'opposite_lane') THEN 'lane'
WHEN tags->'sidewalk:left:bicycle' IN ('designated', 'yes') THEN 'sidewalk'
WHEN tags->'cycleway:left' IN ('share_busway', 'opposite_share_busway', 'shoulder', 'shared_lane') THEN 'busway'
WHEN tags->'cycleway:both' IN ('track', 'opposite_track')
AND COALESCE(tags->'cycleway:left:segregated',tags->'cycleway:both:segregated', tags->'cycleway:segregated') = 'no'
THEN 'shared_track'
WHEN tags->'cycleway:both' IN ('track', 'opposite_track') THEN 'track'
WHEN tags->'sidewalk:both:bicycle' != 'no' AND tags->'sidewalk:left:segregated' = 'yes' THEN 'track'
WHEN tags->'cycleway:both' IN ('lane', 'opposite_lane') THEN 'lane'
WHEN tags->'sidewalk:both:bicycle' IN ('designated', 'yes') THEN 'sidewalk'
WHEN tags->'cycleway:both' IN ('share_busway', 'opposite_share_busway', 'shoulder', 'shared_lane') THEN 'busway'
WHEN tags->'cycleway' IN ('track', 'opposite_track')
AND COALESCE(tags->'cycleway:left:segregated',tags->'cycleway:both:segregated', tags->'cycleway:segregated') = 'no'
THEN 'shared_track'
WHEN tags->'cycleway' IN ('track', 'opposite_track') THEN 'track'
WHEN tags->'cycleway' IN ('lane', 'opposite_lane') THEN 'lane'
WHEN tags->'cycleway' IN ('share_busway', 'opposite_share_busway', 'shoulder', 'shared_lane') THEN 'busway'
ELSE NULL
END AS cycleway_left_render,
CASE
WHEN tags->'cycleway:right' IN ('track', 'opposite_track')
AND COALESCE(tags->'cycleway:right:segregated',tags->'cycleway:both:segregated', tags->'cycleway:segregated') = 'no'
THEN 'shared_track'
WHEN tags->'cycleway:right' IN ('track', 'opposite_track') THEN 'track'
WHEN tags->'sidewalk:right:bicycle' != 'no' AND tags->'sidewalk:left:segregated' = 'yes' THEN 'track'
WHEN tags->'cycleway:right' IN ('lane', 'opposite_lane') THEN 'lane'
WHEN tags->'sidewalk:right:bicycle' IN ('designated', 'yes') THEN 'sidewalk'
WHEN tags->'cycleway:right' IN ('share_busway', 'opposite_share_busway', 'shoulder', 'shared_lane') THEN 'busway'
WHEN tags->'cycleway:both' IN ('track', 'opposite_track')
AND COALESCE(tags->'cycleway:right:segregated',tags->'cycleway:both:segregated', tags->'cycleway:segregated') = 'no'
THEN 'shared_track'
WHEN tags->'cycleway:both' IN ('track', 'opposite_track') THEN 'track'
WHEN tags->'sidewalk:both:bicycle' != 'no' AND tags->'sidewalk:left:segregated' = 'yes' THEN 'track'
WHEN tags->'cycleway:both' IN ('lane', 'opposite_lane') THEN 'lane'
WHEN tags->'sidewalk:both:bicycle' IN ('designated', 'yes') THEN 'sidewalk'
WHEN tags->'cycleway:both' IN ('share_busway', 'opposite_share_busway', 'shoulder', 'shared_lane') THEN 'busway'
WHEN tags->'cycleway' IN ('track', 'opposite_track')
AND COALESCE(tags->'cycleway:right:segregated',tags->'cycleway:both:segregated', tags->'cycleway:segregated') = 'no'
THEN 'shared_track'
WHEN tags->'cycleway' IN ('track', 'opposite_track') THEN 'track'
WHEN tags->'cycleway' IN ('lane', 'opposite_lane') THEN 'lane'
WHEN tags->'cycleway' IN ('share_busway', 'opposite_share_busway', 'shoulder', 'shared_lane') THEN 'busway'
ELSE NULL
END AS cycleway_right_render,
CASE
WHEN tags->'cycleway:left:oneway' IS NOT NULL THEN tags->'cycleway:left:oneway'
WHEN tags->'cycleway:left' IN ('opposite_lane', 'opposite_track', 'opposite_share_busway') THEN '-1'
WHEN tags->'cycleway' IN ('opposite_lane', 'opposite_track', 'opposite_share_busway') THEN '-1'
ELSE NULL
END AS cycleway_left_oneway,
CASE
WHEN tags->'cycleway:right:oneway' IS NOT NULL THEN tags->'cycleway:right:oneway'
WHEN tags->'cycleway:right' IN ('opposite_lane', 'opposite_track', 'opposite_share_busway') THEN '-1'
WHEN tags->'cycleway' IN ('opposite_lane', 'opposite_track', 'opposite_share_busway') THEN '-1'
ELSE NULL
END AS cycleway_right_oneway,
CASE
WHEN bicycle IN ('no', 'private', 'use_sidepath') THEN 'no'
WHEN bicycle IS NOT NULL THEN bicycle
WHEN tags->'motorroad' IN ('yes') THEN 'no'
WHEN highway IN ('motorway', 'motorway_link', 'busway') THEN 'no'
WHEN tags->'vehicle' IN ('no', 'private') THEN 'no'
WHEN tags->'vehicle' IS NOT NULL THEN tags->'vehicle'
WHEN access IN ('no', 'private') THEN 'no'
WHEN access IS NOT NULL THEN access
ELSE NULL
END AS can_bicycle,
CASE
WHEN tags->'segregated' IN ('yes') THEN 'yes'
ELSE 'no'
END AS segregated,
CASE
WHEN tags->'oneway:bicycle' IS NOT NULL THEN tags->'oneway:bicycle'
WHEN tags->'cycleway' IN ('opposite', 'opposite_lane', 'opposite_track', 'opposite_share_busway')
OR tags->'cycleway:both' IN ('opposite', 'opposite_lane', 'opposite_track', 'opposite_share_busway')
OR tags->'cycleway:left' IN ('opposite', 'opposite_lane', 'opposite_track', 'opposite_share_busway')
OR tags->'cycleway:right' IN ('opposite', 'opposite_lane', 'opposite_track', 'opposite_share_busway')
OR tags->'cycleway:left:oneway'='-1' OR tags->'cycleway:right:oneway'='-1'
THEN 'no'
WHEN oneway IN ('yes', '-1') THEN oneway
WHEN junction IN ('roundabout') AND (oneway IS NULL OR oneway NOT IN ('no', 'reversible')) THEN 'yes'
ELSE 'no'
END AS oneway_bicycle,
COALESCE(
tags->'ramp:bicycle',
tags->'ramp:stroller',
tags->'ramp:wheelchair',
tags->'ramp:luggage'
) AS has_ramp,
CASE
-- From best tag to less precise quality surface tag (smoothness > track > surface).
WHEN tags->'smoothness' IS NULL AND tracktype IS NULL AND surface IS NULL
THEN 'unknown'
WHEN tags->'smoothness' IN ('horrible', 'very_horrible', 'impassable')
THEN 'mtb'
WHEN tags->'smoothness' IN ('bad', 'very_bad')
THEN 'cyclocross'
WHEN tags->'smoothness' IN ('excellent', 'good', 'intermediate')
THEN 'road'
WHEN tracktype IN ('grade4', 'grade5')
THEN 'mtb'
WHEN tracktype IN ('grade2', 'grade3')
THEN 'cyclocross'
WHEN tracktype IN ('grade1')
THEN 'road'
WHEN surface IN ('pebblestone', 'dirt', 'earth', 'grass', 'grass_paver', 'gravel_turf', 'ground', 'mud', 'sand')
THEN 'mtb'
WHEN surface IN ('concrete:lanes', 'concrete:plates', 'gravel', 'sett', 'unhewn_cobblestone', 'cobblestone', 'wood', 'compacted', 'fine_gravel', 'woodchips')
THEN 'cyclocross'
WHEN surface IN ('paved', 'asphalt', 'concrete', 'paving_stones')
THEN 'road'
ELSE 'unknown'
END AS surface_type,
CASE
WHEN service in ('parking_aisle', 'drive-through', 'driveway', 'spur', 'siding', 'yard') THEN 'minor'
ELSE service
END AS service,
CASE
WHEN tags->'mtb:scale'~E'^\\d+[+-]?$' THEN REPLACE(REPLACE(tags->'mtb:scale', '+', ''), '-', '')::integer
ELSE NULL
END AS mtb_scale,
CASE
WHEN tags->'mtb:scale:imba'~E'^\\d+$' THEN (tags->'mtb:scale:imba')::integer
ELSE NULL
END AS mtb_scale_imba,
name,
osm_id,
CASE
WHEN highway='cycleway' OR (highway IN ('path', 'footway', 'pedestrian', 'bridleway') AND bicycle IN ('yes', 'designated', 'permissive')) THEN CASE WHEN layer~E'^\\d+$' THEN 100*layer::integer+199 ELSE 199 END
WHEN highway IN ('path', 'footway', 'pedestrian', 'bridleway') THEN CASE WHEN layer~E'^\\d+$' THEN 100*layer::integer+198 ELSE 198 END
ELSE z_order
END AS z_order,
bridge,
COALESCE(
tunnel,
covered,
tags->'indoor'
) AS tunnel
FROM planet_osm_line
WHERE railway IN ('light_rail', 'subway', 'narrow_gauge', 'rail', 'tram')
OR highway IS NOT NULL
ORDER BY z_order ASC;
----------------------------------------------------------------------
DROP VIEW IF EXISTS cyclosm_amenities_point;
CREATE VIEW cyclosm_amenities_point AS
SELECT
access,
bicycle,
tags->'mtb' AS mtb,
covered,
tags->'shelter' AS shelter,
way,
name,
COALESCE( -- order is important here
'aeroway_' || CASE WHEN aeroway IN ('helipad', 'aerodrome') THEN aeroway ELSE NULL END,
'tourism_' || CASE WHEN tourism IN ('artwork', 'alpine_hut', 'camp_site', 'caravan_site', 'chalet', 'wilderness_hut', 'guest_house', 'apartment', 'hostel', 'hotel', 'motel', 'information', 'museum', 'viewpoint', 'picnic_site', 'gallery') THEN tourism ELSE NULL END,
'shop_' || CASE WHEN shop IN ('bicycle', 'bakery', 'beverage', 'convenience', 'convenience;gas', 'doityourself', 'gas', 'greengrocer', 'supermarket', 'pastry', 'sports') THEN shop ELSE NULL END,
'amenity_' || CASE WHEN amenity IN ('atm', 'bank', 'bar', 'bench', 'bicycle_rental', 'bicycle_parking', 'bicycle_repair_station', 'biergarten', 'cafe', 'car_wash', 'compressed_air', 'community_centre', 'clinic', 'doctors', 'drinking_water', 'fast_food', 'ferry_terminal', 'food_court', 'fountain', 'fuel', 'hospital', 'ice_cream', 'internet_cafe', 'parking', 'pharmacy', 'place_of_worship', 'police', 'post_office', 'post_box', 'pub', 'public_bath', 'restaurant', 'shelter', 'shower', 'toilets', 'water_point', 'cinema', 'theatre', 'bureau_de_change', 'casino', 'library', 'motorcycle_parking', 'charging_station', 'vending_machine') THEN amenity ELSE NULL END,
'shop_' || CASE WHEN tags->'service:bicycle:retail'='yes' OR tags->'service:bicycle:repair'='yes' OR tags->'service:bicycle:rental'='yes' THEN 'bicycle' ELSE NULL END,
'emergency_' || CASE WHEN tags->'emergency' IS NOT NULL THEN tags->'emergency' ELSE NULL END,
'healthcare_' || CASE WHEN tags->'healthcare' IN ('clinic', 'hospital') THEN tags->'healthcare' ELSE NULL END,
'leisure_' || CASE WHEN leisure IN ('picnic_table', 'sports_centre') THEN leisure ELSE NULL END,
'man_made_' || CASE WHEN man_made IN ('mast', 'tower', 'water_tower', 'lighthouse', 'windmill', 'cross', 'obelisk', 'communications_tower', 'telescope', 'chimney', 'crane', 'storage_tank', 'silo', 'water_tap', 'monitoring_station') THEN man_made ELSE NULL END,
CASE WHEN tags->'mountain_pass' = 'yes' THEN 'mountain_pass' ELSE NULL END,
'natural_' || CASE WHEN "natural" IN ('peak', 'volcano', 'saddle', 'spring', 'cave_entrance') THEN "natural" ELSE NULL END,
'place_' || CASE WHEN place IN ('island', 'islet') THEN place END,
'waterway_' || CASE WHEN waterway IN ('waterfall') THEN waterway ELSE NULL END,
'historic_' || CASE WHEN historic IN ('memorial', 'monument', 'archaeological_site', 'wayside_cross', 'fort', 'wayside_shrine', 'castle', 'manor', 'city_gate') THEN historic ELSE NULL END,
'military_'|| CASE WHEN military IN ('bunker') THEN military ELSE NULL END,
'highway_'|| CASE WHEN highway IN ('bus_stop', 'elevator', 'traffic_signals') THEN highway ELSE NULL END,
'highway_' || CASE WHEN tags @> 'ford=>yes' OR tags @> 'ford=>stepping_stones' THEN 'ford' END,
'power_' || power,
'xmas_' || CASE WHEN tags->'xmas:feature' IN ('tree', 'market') AND (EXTRACT(MONTH FROM CURRENT_DATE) = '12') AND (EXTRACT(DAY FROM CURRENT_DATE) >= '1') THEN tags->'xmas:feature' ELSE NULL END
) AS feature,
CASE
WHEN tags->'capacity'~E'^\\d+$' THEN (tags->'capacity')::integer
ELSE NULL
END AS capacity,
religion,
tags->'denomination' AS denomination,
tags->'compressed_air' AS compressed_air,
tags->'service:bicycle:pump' AS service_bicycle_pump,
tags->'service:bicycle:diy' AS service_bicycle_diy,
CASE
WHEN tags->'service:bicycle:retail'='yes' OR tags->'service:bicycle:repair'='yes' OR tags->'service:bicycle:rental'='yes' THEN 'yes' ELSE NULL
END AS service_bicycle_retail_repair_rental,
tags->'car_wash' as car_wash,
tags->'drinking_water' AS drinking_water,
tags->'location' AS location,
tags->'memorial' AS memorial,
tags->'castle_type' AS castle_type,
tags->'information' AS information,
tags->'artwork_type' as artwork_type,
tags->'icao' as icao,
tags->'iata' as iata,
"generator:source",
tags->'supervised' as supervised,
tags->'bicycle_parking' as bicycle_parking,
tags->'vending' as vending,
tags->'automated' as automated,
CASE
WHEN "natural" IN ('peak', 'volcano', 'saddle')
OR tags->'mountain_pass' = 'yes' THEN
CASE
WHEN ele ~ '^-?\d{1,4}(\.\d+)?$' THEN ele::NUMERIC
ELSE NULL
END
WHEN "waterway" IN ('waterfall') THEN
CASE
WHEN tags->'height' ~ '^\d{1,3}(\.\d+)?( m)?$' THEN (SUBSTRING(tags->'height', '^(\d{1,3}(\.\d+)?)( m)?$'))::NUMERIC
ELSE NULL
END
WHEN tags->'capacity'~E'^\\d+$' THEN (tags->'capacity')::integer
ELSE NULL
END AS score,
CASE
WHEN "natural" IN ('peak', 'volcano', 'saddle')
OR tourism = 'alpine_hut' OR (tourism = 'information' AND tags->'information' = 'guidepost')
OR amenity = 'shelter'
OR tags->'mountain_pass' = 'yes'
THEN
CASE
WHEN ele ~ '^-?\d{1,4}(\.\d+)?$' THEN ele::NUMERIC
ELSE NULL
END
ELSE NULL
END AS elevation,
CASE
WHEN (man_made IN ('mast', 'tower', 'chimney', 'crane') AND (tags->'location' NOT IN ('roof', 'rooftop') OR (tags->'location') IS NULL)) OR waterway IN ('waterfall') THEN
CASE
WHEN tags->'height' ~ '^\d{1,3}(\.\d+)?( m)?$' THEN (SUBSTRING(tags->'height', '^(\d{1,3}(\.\d+)?)( m)?$'))::NUMERIC
ELSE NULL
END
ELSE NULL
END AS height
FROM planet_osm_point
WHERE aeroway IN ('helipad', 'aerodrome')
OR tourism IN ('artwork', 'alpine_hut', 'camp_site', 'caravan_site', 'chalet', 'wilderness_hut', 'guest_house', 'apartment', 'hostel',
'hotel', 'motel', 'information', 'museum', 'viewpoint', 'picnic_site', 'gallery')
OR amenity IN ('atm', 'bank', 'bar', 'bench', 'bicycle_rental', 'bicycle_parking', 'bicycle_repair_station',
'biergarten', 'cafe', 'car_wash', 'compressed_air', 'community_centre', 'clinic', 'doctors', 'drinking_water', 'fast_food',
'ferry_terminal', 'food_court', 'fountain', 'fuel', 'hospital', 'ice_cream', 'internet_cafe',
'parking', 'pharmacy', 'place_of_worship', 'police', 'post_office', 'post_box', 'pub', 'public_bath',
'restaurant', 'shelter', 'shower', 'toilets', 'water_point', 'cinema', 'theatre',
'bureau_de_change', 'casino', 'library')
OR tags->'car_wash'='yes'
OR (amenity='motorcycle_parking' AND (bicycle='yes' OR bicycle='designated'))
OR (amenity='charging_station' AND (bicycle='yes' OR bicycle='designated'))
OR (amenity='vending_machine' AND tags->'vending'='bicycle_tube')
OR shop IN ('bicycle', 'bakery', 'beverage', 'convenience', 'convenience;gas', 'doityourself', 'gas', 'greengrocer', 'supermarket', 'pastry', 'sports')
OR tags->'healthcare' IN ('clinic', 'hospital')
OR leisure='picnic_table'
OR (leisure='sports_centre' AND sport='swimming')
OR (
man_made IN ('mast', 'tower', 'water_tower', 'lighthouse', 'windmill', 'cross', 'obelisk', 'communications_tower', 'telescope', 'chimney', 'crane', 'storage_tank', 'silo')
AND (tags->'location' NOT IN ('roof', 'rooftop') OR (tags->'location') IS NULL)
)
OR man_made IN ('water_tap')
OR man_made IN ('monitoring_station') AND tags->'monitoring:bicycle'='yes'
OR "natural" IN ('peak', 'volcano', 'saddle', 'spring', 'cave_entrance')
OR place IN ('island', 'islet')
OR tags->'mountain_pass' = 'yes'
OR waterway IN ('waterfall')
OR historic IN ('memorial', 'monument', 'archaeological_site', 'wayside_cross', 'fort', 'wayside_shrine', 'castle', 'manor', 'city_gate')
OR military IN ('bunker')
OR tags->'emergency' IN ('defibrillator', 'phone')
OR highway IN ('elevator', 'traffic_signals')
OR ((highway='bus_stop' OR public_transport='platform') AND (tags->'shelter'='yes' OR covered='yes'))
OR (power = 'generator' AND "generator:source"='wind')
OR tags->'ford' IS NOT NULL
OR tags->'xmas:feature' IN ('tree', 'market')
OR tags->'service:bicycle:retail'='yes' OR tags->'service:bicycle:repair'='yes' OR tags->'service:bicycle:rental'='yes'
ORDER BY
CASE
-- Bike amenities
WHEN shop IN ('bicycle', 'sports') THEN 0
WHEN amenity IN ('bicycle_rental') Then 10
-- Emergency
WHEN tags->'healthcare' IS NOT NULL OR tags->'emergency' IN ('defibrillator', 'phone') OR amenity IN ('hospital', 'clinic', 'doctors', 'pharmacy') THEN 20
-- Other emergency-related amenities
WHEN amenity IN ('bicycle_repair_station', 'compressed_air', 'drinking_water', 'police', 'toilets',
'water_point', 'charging_station') THEN 21
WHEN tags->'compressed_air'='yes' THEN 22
--- Parkings
WHEN amenity IN ('bicycle_parking', 'motorcycle_parking') THEN 32
-- Supermarkets
WHEN shop='supermarket' THEN 40
-- Convenience
WHEN shop='convenience' OR shop='convenience;gas' THEN 50
-- Food
WHEN shop IS NOT NULL OR amenity IN ('bar', 'biergarten', 'cafe', 'fast_food', 'food_court', 'pub', 'restaurant') THEN 60
-- Everything else
ELSE NULL
END ASC NULLS LAST,
feature,
score DESC NULLS LAST;
----------------------------------------------------------------------
DROP VIEW IF EXISTS cyclosm_amenities_poly;
CREATE VIEW cyclosm_amenities_poly AS
SELECT
access,
bicycle,
tags->'mtb' AS mtb,
covered,
tags->'shelter' AS shelter,
way,
way_area AS area,
name,
COALESCE( -- order is important here
'aeroway_' || CASE WHEN aeroway IN ('helipad', 'aerodrome') THEN aeroway ELSE NULL END,
'tourism_' || CASE WHEN tourism IN ('artwork', 'alpine_hut', 'camp_site', 'caravan_site', 'chalet', 'wilderness_hut', 'guest_house', 'apartment', 'hostel', 'hotel', 'motel', 'information', 'museum', 'viewpoint', 'picnic_site', 'gallery') THEN tourism ELSE NULL END,
'shop_' || CASE WHEN shop IN ('bicycle', 'bakery', 'beverage', 'convenience', 'convenience;gas', 'doityourself', 'gas', 'greengrocer', 'supermarket', 'pastry', 'sports') THEN shop ELSE NULL END,
'amenity_' || CASE WHEN amenity IN ('atm', 'bank', 'bar', 'bench', 'bicycle_rental', 'bicycle_parking', 'bicycle_repair_station', 'biergarten', 'cafe', 'car_wash', 'compressed_air', 'community_centre', 'clinic', 'doctors', 'drinking_water', 'fast_food', 'ferry_terminal', 'food_court', 'fountain', 'fuel', 'hospital', 'ice_cream', 'internet_cafe', 'parking', 'pharmacy', 'place_of_worship', 'police', 'post_office', 'post_box', 'pub', 'public_bath', 'restaurant', 'shelter', 'shower', 'toilets', 'water_point', 'cinema', 'theatre', 'bureau_de_change', 'casino', 'library', 'motorcycle_parking', 'charging_station', 'vending_machine') THEN amenity ELSE NULL END,
'shop_' || CASE WHEN tags->'service:bicycle:retail'='yes' OR tags->'service:bicycle:repair'='yes' OR tags->'service:bicycle:rental'='yes' THEN 'bicycle' ELSE NULL END,
'emergency_' || CASE WHEN tags->'emergency' IS NOT NULL THEN tags->'emergency' ELSE NULL END,
'healthcare_' || CASE WHEN tags->'healthcare' IN ('clinic', 'hospital') THEN tags->'healthcare' ELSE NULL END,
'leisure_' || CASE WHEN leisure IN ('picnic_table', 'sports_centre') THEN leisure ELSE NULL END,
'man_made_' || CASE WHEN man_made IN ('mast', 'tower', 'water_tower', 'lighthouse', 'windmill', 'cross', 'obelisk', 'communications_tower', 'telescope', 'chimney', 'crane', 'storage_tank', 'silo', 'water_tap', 'monitoring_station') THEN man_made ELSE NULL END,
CASE WHEN tags->'mountain_pass' = 'yes' THEN 'mountain_pass' ELSE NULL END,
'natural_' || CASE WHEN "natural" IN ('peak', 'volcano', 'saddle', 'spring', 'cave_entrance') THEN "natural" ELSE NULL END,
'place_' || CASE WHEN place IN ('island', 'islet') THEN place END,
'waterway_' || CASE WHEN waterway IN ('waterfall') THEN waterway ELSE NULL END,
'historic_' || CASE WHEN historic IN ('memorial', 'monument', 'archaeological_site', 'wayside_cross', 'fort', 'wayside_shrine', 'castle', 'manor', 'city_gate') THEN historic ELSE NULL END,
'military_'|| CASE WHEN military IN ('bunker') THEN military ELSE NULL END,
'highway_'|| CASE WHEN highway IN ('bus_stop', 'elevator', 'traffic_signals') THEN highway ELSE NULL END,
'power_' || power,
'xmas_' || CASE WHEN tags->'xmas:feature' IN ('tree', 'market') AND (EXTRACT(MONTH FROM CURRENT_DATE) = '12') AND (EXTRACT(DAY FROM CURRENT_DATE) >= '1') THEN tags->'xmas:feature' ELSE NULL END
) AS feature,
CASE
WHEN tags->'capacity'~E'^\\d+$' THEN (tags->'capacity')::integer
ELSE NULL
END AS capacity,
religion,
tags->'denomination' AS denomination,
tags->'compressed_air' AS compressed_air,
tags->'service:bicycle:pump' AS service_bicycle_pump,
tags->'service:bicycle:diy' AS service_bicycle_diy,
CASE
WHEN tags->'service:bicycle:retail'='yes' OR tags->'service:bicycle:repair'='yes' OR tags->'service:bicycle:rental'='yes' THEN 'yes' ELSE NULL
END AS service_bicycle_retail_repair_rental,
tags->'car_wash' as car_wash,
tags->'drinking_water' AS drinking_water,
tags->'location' AS location,
tags->'memorial' AS memorial,
tags->'castle_type' AS castle_type,
tags->'information' AS information,
tags->'artwork_type' as artwork_type,
tags->'icao' as icao,
tags->'iata' as iata,
"generator:source",
tags->'supervised' as supervised,
tags->'bicycle_parking' as bicycle_parking,
tags->'vending' as vending,
tags->'automated' as automated,
CASE
WHEN "natural" IN ('peak', 'volcano', 'saddle') THEN NULL
WHEN "waterway" IN ('waterfall') THEN
CASE
WHEN tags->'height' ~ '^\d{1,3}(\.\d+)?( m)?$' THEN (SUBSTRING(tags->'height', '^(\d{1,3}(\.\d+)?)( m)?$'))::NUMERIC
ELSE NULL
END
WHEN tags->'capacity'~E'^\\d+$' THEN (tags->'capacity')::integer
ELSE NULL
END AS score,
CASE
WHEN (man_made IN ('mast', 'tower', 'chimney', 'crane') AND (tags->'location' NOT IN ('roof', 'rooftop') OR (tags->'location') IS NULL)) OR waterway IN ('waterfall') THEN
CASE
WHEN tags->'height' ~ '^\d{1,3}(\.\d+)?( m)?$' THEN (SUBSTRING(tags->'height', '^(\d{1,3}(\.\d+)?)( m)?$'))::NUMERIC
ELSE NULL
END
ELSE NULL
END AS height,
way_area
FROM planet_osm_polygon
WHERE aeroway IN ('helipad', 'aerodrome')
OR tourism IN ('artwork', 'alpine_hut', 'camp_site', 'caravan_site', 'chalet', 'wilderness_hut', 'guest_house', 'apartment', 'hostel',
'hotel', 'motel', 'information', 'museum', 'viewpoint', 'picnic_site', 'gallery')
OR amenity IN ('atm', 'bank', 'bar', 'bench', 'bicycle_rental', 'bicycle_parking', 'bicycle_repair_station',
'biergarten', 'cafe', 'car_wash', 'compressed_air', 'community_centre', 'clinic', 'doctors', 'drinking_water', 'fast_food',
'ferry_terminal', 'food_court', 'fountain', 'fuel', 'hospital', 'ice_cream', 'internet_cafe',
'parking', 'pharmacy', 'place_of_worship', 'police', 'post_office', 'post_box', 'pub', 'public_bath',
'restaurant', 'shelter', 'shower', 'toilets', 'water_point', 'cinema', 'theatre',
'bureau_de_change', 'casino', 'library')
OR tags->'car_wash'='yes'
OR (amenity='motorcycle_parking' AND (bicycle='yes' OR bicycle='designated'))
OR (amenity='charging_station' AND (bicycle='yes' OR bicycle='designated'))
OR (amenity='vending_machine' AND tags->'vending'='bicycle_tube')
OR shop IN ('bicycle', 'bakery', 'beverage', 'convenience', 'convenience;gas', 'doityourself', 'gas', 'greengrocer', 'supermarket', 'pastry', 'sports')
OR tags->'healthcare' IN ('clinic', 'hospital')
OR leisure='picnic_table'
OR (leisure='sports_centre' AND sport='swimming')
OR (
man_made IN ('mast', 'tower', 'water_tower', 'lighthouse', 'windmill', 'cross', 'obelisk', 'communications_tower', 'telescope', 'chimney', 'crane', 'storage_tank', 'silo')
AND (tags->'location' NOT IN ('roof', 'rooftop') OR (tags->'location') IS NULL)
)
OR man_made IN ('water_tap')
OR man_made IN ('monitoring_station') AND tags->'monitoring:bicycle'='yes'
OR "natural" IN ('peak', 'volcano', 'saddle', 'spring', 'cave_entrance')
OR place IN ('island', 'islet')
OR tags->'mountain_pass' = 'yes'
OR waterway IN ('waterfall')
OR historic IN ('memorial', 'monument', 'archaeological_site', 'wayside_cross', 'fort', 'wayside_shrine', 'castle', 'manor', 'city_gate')
OR military IN ('bunker')
OR tags->'emergency' IN ('defibrillator', 'phone')
OR highway IN ('elevator', 'traffic_signals')
OR ((highway='bus_stop' OR public_transport='platform') AND (tags->'shelter'='yes' OR covered='yes'))
OR (power = 'generator' AND "generator:source"='wind')
OR tags->'xmas:feature' IN ('tree', 'market')
OR tags->'service:bicycle:retail'='yes' OR tags->'service:bicycle:repair'='yes' OR tags->'service:bicycle:rental'='yes'
ORDER BY
CASE
-- Bike amenities
WHEN shop IN ('bicycle', 'sports') THEN 0
WHEN amenity IN ('bicycle_rental') Then 10
-- Emergency
WHEN tags->'healthcare' IS NOT NULL OR tags->'emergency'IN ('defibrillator', 'phone') OR amenity IN ('hospital', 'clinic', 'doctors', 'pharmacy') THEN 20
-- Other emergency-related amenities
WHEN amenity IN ('bicycle_repair_station', 'compressed_air', 'drinking_water', 'police', 'toilets',
'water_point', 'charging_station') THEN 21
WHEN tags->'compressed_air'='yes' THEN 22
--- Parkings
WHEN amenity IN ('bicycle_parking', 'motorcycle_parking') THEN 32
-- Supermarkets
WHEN shop='supermarket' THEN 40
-- Convenience
WHEN shop='convenience' OR shop='convenience;gas' THEN 50
-- Food
WHEN shop IS NOT NULL OR amenity IN ('bar', 'biergarten', 'cafe', 'fast_food', 'food_court', 'pub', 'restaurant') THEN 60
-- Everything else
ELSE NULL
END ASC NULLS LAST,
feature,
score DESC NULLS LAST