forked from azavea/pfb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bike_infra.sql
152 lines (142 loc) · 7.37 KB
/
bike_infra.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
----------------------------------------
-- INPUTS
-- location: neighborhood
----------------------------------------
UPDATE neighborhood_ways SET ft_bike_infra = NULL, tf_bike_infra = NULL;
----------------------
-- ft direction
----------------------
-- sharrow
UPDATE neighborhood_ways
SET ft_bike_infra = 'sharrow'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND (
osm."cycleway:both" = 'shared_lane'
OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'shared_lane')
OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'shared_lane')
OR (one_way_car = 'ft' AND osm."cycleway:left" = 'shared_lane')
);
-- lane
UPDATE neighborhood_ways
SET ft_bike_infra = 'lane'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND (
osm."cycleway:both" = 'lane'
OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'lane')
OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'lane')
OR (one_way_car = 'ft' AND osm."cycleway:left" = 'lane')
OR (one_way_car = 'tf' AND osm.cycleway = 'opposite_lane')
OR (one_way_car = 'tf' AND osm."cycleway:left" = 'opposite_lane')
);
-- buffered lane
UPDATE neighborhood_ways
SET ft_bike_infra = 'buffered_lane'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND (
osm."cycleway:both" = 'buffered_lane'
OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'buffered_lane')
OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'buffered_lane')
OR (COALESCE(one_way_car,'ft') = 'ft' AND osm.cycleway = 'lane' AND osm."cycleway:buffer" IN ('yes','both','right','left'))
OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'lane' AND osm."cycleway:buffer" IN ('yes','both','right','left'))
OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'lane' AND osm."cycleway:right:buffer" IN ('yes','both','right','left'))
OR (one_way_car = 'ft' AND osm."cycleway:left" = 'lane' AND osm."cycleway:buffer" IN ('yes','both','right','left'))
OR (one_way_car = 'ft' AND osm."cycleway:left" = 'lane' AND osm."cycleway:left:buffer" IN ('yes','both','right','left'))
OR (one_way_car = 'tf' AND osm.cycleway = 'opposite_lane' AND osm."cycleway:buffer" IN ('yes','both','right','left'))
OR (one_way_car = 'tf' AND osm."cycleway:left" = 'opposite_lane' AND osm."cycleway:buffer" IN ('yes','both','right','left'))
OR (one_way_car = 'tf' AND osm."cycleway:left" = 'opposite_lane' AND osm."cycleway:left:buffer" IN ('yes','both','right','left'))
);
-- track
UPDATE neighborhood_ways
SET ft_bike_infra = 'track'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND (
osm."cycleway:both" = 'track'
OR (osm."cycleway:right" = 'track' AND osm."oneway:bicycle" = 'no')
OR (osm."cycleway:left" = 'track' AND osm."oneway:bicycle" = 'no')
OR (osm.cycleway = 'track' AND osm."oneway:bicycle" = 'no')
OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway" = 'track')
OR (COALESCE(one_way_car,'ft') = 'ft' AND osm."cycleway:right" = 'track')
OR (one_way_car = 'tf' AND osm."cycleway" = 'opposite_track')
OR (one_way_car = 'tf' AND osm."cycleway:left" = 'opposite_track')
OR (one_way_car = 'tf' AND osm."cycleway:right" = 'opposite_track')
);
----------------------
-- tf direction
----------------------
-- sharrow
UPDATE neighborhood_ways
SET tf_bike_infra = 'sharrow'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND (
osm."cycleway:both" = 'shared_lane'
OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'shared_lane')
OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'shared_lane')
OR (one_way_car = 'tf' AND osm."cycleway:right" = 'shared_lane')
);
-- lane
UPDATE neighborhood_ways
SET tf_bike_infra = 'lane'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND (
osm."cycleway:both" = 'lane'
OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'lane')
OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'lane')
OR (one_way_car = 'tf' AND osm."cycleway:right" = 'lane')
OR (one_way_car = 'ft' AND osm.cycleway = 'opposite_lane')
OR (one_way_car = 'ft' AND osm."cycleway:right" = 'opposite_lane')
);
-- buffered lane
UPDATE neighborhood_ways
SET tf_bike_infra = 'buffered_lane'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND (
osm."cycleway:both" = 'buffered_lane'
OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'buffered_lane')
OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'buffered_lane')
OR (COALESCE(one_way_car,'tf') = 'tf' AND osm.cycleway = 'lane' AND osm."cycleway:buffer" IN ('yes','both','right','left'))
OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'lane' AND osm."cycleway:buffer" IN ('yes','both','right','left'))
OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'lane' AND osm."cycleway:left:buffer" IN ('yes','both','right','left'))
OR (one_way_car = 'tf' AND osm."cycleway:right" = 'lane' AND osm."cycleway:buffer" IN ('yes','both','right','left'))
OR (one_way_car = 'tf' AND osm."cycleway:right" = 'lane' AND osm."cycleway:right:buffer" IN ('yes','both','right','left'))
OR (one_way_car = 'ft' AND osm.cycleway = 'opposite_lane' AND osm."cycleway:buffer" IN ('yes','both','right','left'))
OR (one_way_car = 'ft' AND osm."cycleway:right" = 'opposite_lane' AND osm."cycleway:buffer" IN ('yes','both','right','left'))
OR (one_way_car = 'ft' AND osm."cycleway:right" = 'opposite_lane' AND osm."cycleway:right:buffer" IN ('yes','both','right','left'))
);
-- track
UPDATE neighborhood_ways
SET tf_bike_infra = 'track'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND (
osm."cycleway:both" = 'track'
OR (osm."cycleway:left" = 'track' AND osm."oneway:bicycle" = 'no')
OR (osm."cycleway:right" = 'track' AND osm."oneway:bicycle" = 'no')
OR (osm.cycleway = 'track' AND osm."oneway:bicycle" = 'no')
OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway" = 'track')
OR (COALESCE(one_way_car,'tf') = 'tf' AND osm."cycleway:left" = 'track')
OR (one_way_car = 'ft' AND osm."cycleway" = 'opposite_track')
OR (one_way_car = 'ft' AND osm."cycleway:left" = 'opposite_track')
OR (one_way_car = 'ft' AND osm."cycleway:right" = 'opposite_track')
);
-- update one_way based on bike infra
UPDATE neighborhood_ways
SET one_way = NULL;
UPDATE neighborhood_ways
SET one_way = one_way_car
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND one_way_car = 'ft'
AND NOT (tf_bike_infra IS NOT NULL OR COALESCE(osm."oneway:bicycle",'yes') = 'no');
UPDATE neighborhood_ways
SET one_way = one_way_car
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND one_way_car = 'tf'
AND NOT (ft_bike_infra IS NOT NULL OR COALESCE(osm."oneway:bicycle",'yes') = 'no');