forked from spencerrecneps/pfb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlanes.sql
168 lines (166 loc) · 8.21 KB
/
lanes.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
----------------------------------------
-- INPUTS
-- location: neighborhood
----------------------------------------
UPDATE neighborhood_ways
SET ft_lanes = NULL, tf_lanes = NULL, ft_cross_lanes = NULL, tf_cross_lanes = NULL;
UPDATE neighborhood_ways
SET ft_lanes =
CASE WHEN osm."turn:lanes:forward" IS NOT NULL
THEN array_length(
regexp_split_to_array(
osm."turn:lanes:forward",
'\|'
),
1 -- only one dimension
)
WHEN osm."turn:lanes" IS NOT NULL AND one_way = 'ft'
THEN array_length(
regexp_split_to_array(
osm."turn:lanes",
'\|'
),
1 -- only one dimension
)
WHEN osm."lanes:forward" IS NOT NULL
THEN substring(osm."lanes:forward" FROM '\d+')::INT
WHEN osm."lanes" IS NOT NULL AND one_way = 'ft'
THEN substring(osm."lanes" FROM '\d+')::INT
WHEN osm."lanes" IS NOT NULL
THEN ceil(substring(osm."lanes" FROM '\d+')::FLOAT / 2)
END,
tf_lanes =
CASE WHEN osm."turn:lanes:backward" IS NOT NULL
THEN array_length(
regexp_split_to_array(
osm."turn:lanes:backward",
'\|'
),
1 -- only one dimension
)
WHEN osm."turn:lanes" IS NOT NULL AND one_way = 'tf'
THEN array_length(
regexp_split_to_array(
osm."turn:lanes",
'\|'
),
1 -- only one dimension
)
WHEN osm."lanes:backward" IS NOT NULL
THEN substring(osm."lanes:backward" FROM '\d+')::INT
WHEN osm."lanes" IS NOT NULL AND one_way = 'tf'
THEN substring(osm."lanes" FROM '\d+')::INT
WHEN osm."lanes" IS NOT NULL
THEN ceil(substring(osm."lanes" FROM '\d+')::FLOAT / 2)
END,
ft_cross_lanes =
CASE WHEN osm."turn:lanes:forward" IS NOT NULL
THEN array_length(
array_remove(
regexp_split_to_array(
osm."turn:lanes:forward",
'\|'
),
'right' -- don't consider right-only lanes for crossing stress
),
1 -- only one dimension
)
WHEN osm."turn:lanes" IS NOT NULL AND one_way = 'ft'
THEN array_length(
array_remove(
regexp_split_to_array(
osm."turn:lanes",
'\|'
),
'right' -- don't consider right-only lanes for crossing stress
),
1 -- only one dimension
)
WHEN osm."lanes:forward" IS NOT NULL
THEN substring(osm."lanes:forward" FROM '\d+')::INT
WHEN osm."lanes" IS NOT NULL AND one_way = 'ft'
THEN substring(osm."lanes" FROM '\d+')::INT
WHEN osm."lanes" IS NOT NULL
THEN ceil(substring(osm."lanes" FROM '\d+')::FLOAT / 2)
END,
tf_cross_lanes =
CASE WHEN osm."turn:lanes:backward" IS NOT NULL
THEN array_length(
array_remove(
regexp_split_to_array(
osm."turn:lanes:backward",
'\|'
),
'right' -- don't consider right-only lanes for crossing stress
),
1 -- only one dimension
)
WHEN osm."turn:lanes" IS NOT NULL AND one_way = 'tf'
THEN array_length(
array_remove(
regexp_split_to_array(
osm."turn:lanes",
'\|'
),
'right' -- don't consider right-only lanes for crossing stress
),
1 -- only one dimension
)
WHEN osm."lanes:backward" IS NOT NULL
THEN substring(osm."lanes:backward" FROM '\d+')::INT
WHEN osm."lanes" IS NOT NULL AND one_way = 'tf'
THEN substring(osm."lanes" FROM '\d+')::INT
WHEN osm."lanes" IS NOT NULL
THEN ceil(substring(osm."lanes" FROM '\d+')::FLOAT / 2)
END,
twltl_cross_lanes =
CASE WHEN osm."lanes:both_ways" IS NOT NULL THEN 1
WHEN osm."turn:lanes:both_ways" IS NOT NULL THEN 1
ELSE NULL
END
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id;
-- -- forward
-- UPDATE neighborhood_ways
-- SET ft_lanes = substring(osm."lanes:forward" FROM '\d+')::INT
-- FROM neighborhood_osm_full_line osm
-- WHERE neighborhood_ways.osm_id = osm.osm_id
-- AND ft_lanes IS NULL
-- AND osm."lanes:forward" IS NOT NULL;
--
-- -- backward
-- UPDATE neighborhood_ways
-- SET tf_lanes = substring(osm."lanes:backward" FROM '\d+')::INT
-- FROM neighborhood_osm_full_line osm
-- WHERE neighborhood_ways.osm_id = osm.osm_id
-- AND tf_lanes IS NULL
-- AND osm."lanes:backward" IS NOT NULL;
--
-- -- all lanes (no direction given)
-- -- two way
-- UPDATE neighborhood_ways
-- SET ft_lanes = floor(substring(osm.lanes FROM '\d+')::FLOAT / 2),
-- tf_lanes = floor(substring(osm.lanes FROM '\d+')::FLOAT / 2)
-- FROM neighborhood_osm_full_line osm
-- WHERE neighborhood_ways.osm_id = osm.osm_id
-- AND tf_lanes IS NULL
-- AND ft_lanes IS NULL
-- AND one_way_car NOT IN ('ft','tf')
-- AND osm.lanes IS NOT NULL;
--
-- -- all lanes (no direction given)
-- -- one way
-- UPDATE neighborhood_ways
-- SET ft_lanes = substring(osm.lanes FROM '\d+')::INT
-- FROM neighborhood_osm_full_line osm
-- WHERE neighborhood_ways.osm_id = osm.osm_id
-- AND one_way_car = 'ft'
-- AND ft_lanes IS NULL
-- AND osm.lanes IS NOT NULL;
-- UPDATE neighborhood_ways
-- SET tf_lanes = substring(osm.lanes FROM '\d+')::INT
-- FROM neighborhood_osm_full_line osm
-- WHERE neighborhood_ways.osm_id = osm.osm_id
-- AND one_way_car = 'tf'
-- AND tf_lanes IS NULL
-- AND osm.lanes IS NOT NULL;