-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMaterialized view_belgium_bridges.sql
More file actions
38 lines (33 loc) · 1.21 KB
/
Materialized view_belgium_bridges.sql
File metadata and controls
38 lines (33 loc) · 1.21 KB
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
DROP MATERIALIZED VIEW IF EXISTS view_belgium_bridges_snapped_3857;
CREATE MATERIALIZED VIEW view_belgium_bridges_snapped_3857 AS
WITH snapped AS (
SELECT
highway,
ST_Snap(ST_Transform(way, 3857), ST_Collect(ST_Transform(way, 3857)), 1) AS snapped_way
FROM planet_osm_line
WHERE bridge NOT IN ('0','no','')
AND highway IN ('path','cycleway','footway','pedestrian','steps','bridleway','boardwalk')
GROUP BY highway, way
),
clusters AS (
SELECT
unnest(ST_ClusterIntersecting(snapped_way)) AS cluster_geom
FROM snapped
),
merged AS (
SELECT
row_number() OVER () AS geom_id,
ST_RemoveRepeatedPoints(
ST_LineMerge(ST_Union(cluster_geom)), 0.001
) AS geom_clean,
ST_Length(ST_LineMerge(ST_Union(cluster_geom))) AS length_way
FROM clusters
GROUP BY cluster_geom
)
SELECT
geom_id,
geom_clean::geometry(Geometry, 3857) AS geom,
length_way
FROM merged;
-- Index spatial
CREATE INDEX idx_be_bridges_snapped_geom ON view_belgium_bridges_snapped_3857 USING GIST (geom);