-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess_osm_db.sql
49 lines (35 loc) · 1.75 KB
/
preprocess_osm_db.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
-------------------------------------------------------------------------------
-- The following script creates a new table for the pgsql simple schema for
-- storing full way geometries.
-------------------------------------------------------------------------------
-- drop table if it exists
DROP TABLE IF EXISTS way_geometry;
-- create table
CREATE TABLE way_geometry(
way_id bigint NOT NULL
);
-- add PostGIS geometry column
SELECT AddGeometryColumn('', 'way_geometry', 'geom', 4326, 'GEOMETRY', 2);
-- add a linestring for every way (create a polyline)
INSERT INTO way_geometry select id, ( select ST_LineFromMultiPoint( ST_Collect(nodes.geom) ) from nodes
left join way_nodes on nodes.id=way_nodes.node_id where way_nodes.way_id=ways.id ) FROM ways
where ways.tags -> 'highway' <> '';
-- create index on way_geometry
CREATE INDEX idx_way_geometry_way_id ON way_geometry USING btree (way_id);
CREATE INDEX idx_way_geometry_geom ON way_geometry USING gist (geom);
-- select count(*) from way_geometry;
-------------------------------------------------------------------------------
-- The following script creates a table for intersections of relevant barriers and highways --
-------------------------------------------------------------------------------
-- drop table if it exists
DROP TABLE IF EXISTS barrier_ways_intersection;
-- create table
CREATE TABLE barrier_ways_intersection(
way_id bigint NOT null,
barrier_id bigint not null
);
INSERT INTO barrier_ways_intersection SELECT way_geometry.way_id as way_id, nodes.id as barrier_id
FROM way_geometry, nodes
WHERE ST_INTERSECTS(way_geometry.geom, nodes.geom)
and nodes.tags -> 'barrier' IN ('bollard', 'block', 'cycle_barrier', 'kerb', 'lift_gate');
-- select count(*) from barrier_ways_intersection;