forked from azavea/pfb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functional_class.sql
100 lines (89 loc) · 3.15 KB
/
functional_class.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
----------------------------------------
-- INPUTS
-- location: neighborhood
----------------------------------------
UPDATE neighborhood_ways SET functional_class = NULL;
UPDATE neighborhood_ways
SET functional_class = osm.highway
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND osm.highway IN (
'motorway',
'tertiary',
'trunk',
'tertiary_link',
'motorway_link',
'secondary_link',
'primary_link',
'trunk_link',
'residential',
'secondary',
'primary',
'living_street'
); -- note that we're leaving out "road"
UPDATE neighborhood_ways
SET functional_class = 'tertiary'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND osm.highway = 'unclassified';
UPDATE neighborhood_ways
SET functional_class = 'track'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND osm.highway = 'track'
AND osm.tracktype = 'grade1';
UPDATE neighborhood_ways
SET functional_class = 'path'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND osm.highway IN ('cycleway','path');
UPDATE neighborhood_ways
SET functional_class = 'path'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND osm.highway = 'footway'
AND osm.footway = 'crossing';
UPDATE neighborhood_ways
SET functional_class = 'path'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND osm.highway = 'footway'
AND osm.bicycle = 'designated'
AND (osm.access IS NULL OR osm.access NOT IN ('no','private'))
AND COALESCE(width_ft,0) >= 8;
UPDATE neighborhood_ways
SET functional_class = 'path'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND osm.highway='service'
AND osm.bicycle='designated';
UPDATE neighborhood_ways
SET functional_class = 'living_street'
FROM neighborhood_osm_full_line osm
WHERE neighborhood_ways.osm_id = osm.osm_id
AND osm.highway = 'pedestrian'
AND osm.bicycle IN ('yes','permissive', 'designated')
AND (osm.access IS NULL OR osm.access NOT IN ('no','private'));
-- remove stuff that we don't want to route over
DELETE FROM neighborhood_ways WHERE functional_class IS NULL;
-- remove orphans
DELETE FROM neighborhood_ways
WHERE NOT EXISTS (
SELECT 1
FROM neighborhood_ways w
WHERE neighborhood_ways.intersection_to IN (w.intersection_to,w.intersection_from)
AND w.road_id != neighborhood_ways.road_id
)
AND NOT EXISTS (
SELECT 1
FROM neighborhood_ways w
WHERE neighborhood_ways.intersection_from IN (w.intersection_to,w.intersection_from)
AND w.road_id != neighborhood_ways.road_id
);
-- remove obsolete intersections
DELETE FROM neighborhood_ways_intersections
WHERE NOT EXISTS (
SELECT 1
FROM neighborhood_ways w
WHERE int_id IN (w.intersection_to,w.intersection_from)
);