Skip to content

Commit b9208c5

Browse files
committed
Update landuse lines layer - filter only tree_row
1 parent 7f35631 commit b9208c5

File tree

5 files changed

+82
-21
lines changed

5 files changed

+82
-21
lines changed

DOC-VTILES.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ TODO: fix according to schema
137137

138138
# Land Use - Lines (landuse_lines)
139139

140-
TODO: fix according to schema
141-
142-
143-
| MView | Zoom Levels | Simplification (m) | Min Area (m²) | Function | Notes |
140+
- Filtering only tree_row, since this is the only one used in the mapstyles
141+
142+
| MView | Zoom Levels | Simplification (m) | Min Length (m) | Function | Notes |
144143
|-------|-------------|-------------------|---------------|---------|-------|
145-
| `mv_landuse_lines_z14_20` | 14-20 ⚠️ | - | - | create_generic_mview | Should be z14_15 + z16_20 |
144+
| `mv_landuse_lines_z16_20` | 16-20 | 5 | 0 | create_lines_mview | Filter: type IN ('tree_row') |
145+
| `mv_landuse_lines_z14_15` | 14-15 | 5 | - | create_mview_line_from_mview | Derived from z16_20 |
146146

147147
# Transport - Areas (transport_areas)
148148

images/tiler-imposm/queries/ohm_mviews/landuse.sql

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,40 @@ SELECT create_points_centroids_mview(
119119
);
120120

121121

122+
123+
-- Parameters:
124+
-- source_table TEXT - Name of the source table or materialized view
125+
-- view_name TEXT - Name of the materialized view to create
126+
-- simplify_tol DOUBLE PRECISION - Simplification tolerance (0 = no simplification)
127+
-- min_length DOUBLE PRECISION - Minimum length in m to include (0 = no filter)
128+
-- unique_columns TEXT - Comma-separated columns for unique index (default: 'id, osm_id, type')
129+
-- where_filter TEXT - Optional WHERE clause filter (e.g., "highway != 'abandoned'"). NULL = no filter
130+
--
131+
-- Notes:
132+
-- - Creates the materialized view using a temporary swap mechanism
133+
-- - Adds a spatial index (GiST) on geometry and a unique index on unique_columns
134+
-- - Useful for creating views at different zoom levels with variable simplification
135+
-- - where_filter is appended to WHERE clause with AND
136+
-- -- ============================================================================
137+
-- DROP FUNCTION IF EXISTS create_lines_mview(TEXT, TEXT, DOUBLE PRECISION, DOUBLE PRECISION, TEXT, TEXT);
138+
139+
-- CREATE OR REPLACE FUNCTION create_lines_mview(
140+
-- source_table TEXT,
141+
-- view_name TEXT,
142+
-- simplify_tol DOUBLE PRECISION DEFAULT 0,
143+
-- min_length DOUBLE PRECISION DEFAULT 0,
144+
-- unique_columns TEXT DEFAULT 'id, osm_id, type',
145+
-- where_filter TEXT DEFAULT NULL
146+
-- )
147+
148+
122149
-- ============================================================================
123-
-- Create materialized views for landuse lines, TODO fix right zoom to the standard
150+
-- Create materialized views for landuse lines,
151+
-- Only tree_row type is used in the map style
124152
-- ============================================================================
125-
SELECT create_generic_mview(
126-
'osm_landuse_lines',
127-
'mv_landuse_lines_z14_20',
128-
ARRAY['osm_id', 'type', 'class']
129-
);
153+
SELECT create_lines_mview('osm_landuse_lines', 'mv_landuse_lines_z16_20', 5, 0, 'id, osm_id, type', 'type IN (''tree_row'')');
154+
SELECT create_mview_line_from_mview('mv_landuse_lines_z16_20', 'mv_landuse_lines_z14_15', 5, NULL);
155+
130156

131157
-- Refresh areas views
132158
-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_landuse_areas_z16_20;

images/tiler-imposm/queries/ohm_mviews/transport_lines.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,16 @@ $$ LANGUAGE plpgsql;
164164
-- ============================================================================
165165
-- Create materialized views for transport lines
166166
-- ============================================================================
167-
DROP FUNCTION IF EXISTS mv_transport_lines_z16_20;
167+
DROP MATERIALIZED VIEW IF EXISTS mv_transport_lines_z16_20 CASCADE;
168168
SELECT create_transport_lines_mview('mv_transport_lines_z16_20', 0, ARRAY['*'], ARRAY['railway','route']);
169-
SELECT create_mview_line_from_mview('mv_transport_lines_z16_20', 'mv_transport_lines_z13_15', 5, 'type IN (''motorway'', ''motorway_link'', ''trunk'', ''trunk_link'', ''construction'', ''primary'', ''primary_link'', ''rail'', ''secondary'', ''secondary_link'', ''tertiary'', ''tertiary_link'', ''miniature'', ''narrow_gauge'', ''dismantled'', ''abandoned'', ''disused'', ''razed'', ''light_rail'', ''preserved'', ''proposed'', ''tram'', ''funicular'', ''monorail'', ''taxiway'', ''runway'', ''raceway'', ''residential'', ''service'', ''unclassified'') AND class IN (''railway'')');
170-
SELECT create_mview_line_from_mview('mv_transport_lines_z13_15', 'mv_transport_lines_z10_12', 20, 'type IN (''motorway'', ''motorway_link'', ''trunk'', ''trunk_link'', ''construction'', ''primary'', ''primary_link'', ''rail'', ''secondary'', ''secondary_link'', ''tertiary'', ''tertiary_link'', ''miniature'', ''narrow_gauge'', ''dismantled'', ''abandoned'', ''disused'', ''razed'', ''light_rail'', ''preserved'', ''proposed'', ''tram'', ''funicular'', ''monorail'', ''taxiway'', ''runway'') AND class IN (''railway'')');
169+
SELECT create_mview_line_from_mview('mv_transport_lines_z16_20', 'mv_transport_lines_z13_15', 5, 'type IN (''motorway'', ''motorway_link'', ''trunk'', ''trunk_link'', ''construction'', ''primary'', ''primary_link'', ''rail'', ''secondary'', ''secondary_link'', ''tertiary'', ''tertiary_link'', ''miniature'', ''narrow_gauge'', ''dismantled'', ''abandoned'', ''disused'', ''razed'', ''light_rail'', ''preserved'', ''proposed'', ''tram'', ''funicular'', ''monorail'', ''taxiway'', ''runway'', ''raceway'', ''residential'', ''service'', ''unclassified'') OR class IN (''railway'')');
170+
SELECT create_mview_line_from_mview('mv_transport_lines_z13_15', 'mv_transport_lines_z10_12', 20, 'type IN (''motorway'', ''motorway_link'', ''trunk'', ''trunk_link'', ''construction'', ''primary'', ''primary_link'', ''rail'', ''secondary'', ''secondary_link'', ''tertiary'', ''tertiary_link'', ''miniature'', ''narrow_gauge'', ''dismantled'', ''abandoned'', ''disused'', ''razed'', ''light_rail'', ''preserved'', ''proposed'', ''tram'', ''funicular'', ''monorail'', ''taxiway'', ''runway'') OR class IN (''railway'')');
171171
SELECT create_mview_line_from_mview('mv_transport_lines_z10_12', 'mv_transport_lines_z8_9', 100, NULL);
172-
SELECT create_mview_line_from_mview('mv_transport_lines_z8_9', 'mv_transport_lines_z6_7', 200 , 'type IN (''motorway'', ''motorway_link'', ''trunk'', ''trunk_link'', ''construction'', ''primary'', ''primary_link'', ''rail'', ''secondary'', ''secondary_link'') AND class IN (''railway'')');
172+
SELECT create_mview_line_from_mview('mv_transport_lines_z8_9', 'mv_transport_lines_z6_7', 200 , 'type IN (''motorway'', ''motorway_link'', ''trunk'', ''trunk_link'', ''construction'', ''primary'', ''primary_link'', ''rail'', ''secondary'', ''secondary_link'') OR class IN (''railway'')');
173173
SELECT create_mview_line_from_mview('mv_transport_lines_z6_7', 'mv_transport_lines_z5', 1000 , NULL);
174174

175175

176+
176177
-- Refresh lines views
177178
-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_transport_lines_z5;
178179
-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_transport_lines_z6_7;

images/tiler-imposm/queries/utils/create_mview_centroid_mview.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ DROP FUNCTION IF EXISTS create_mview_centroid_from_mview(TEXT, TEXT, TEXT);
44
* Creates a new materialized view with point centroids from an existing materialized view
55
* containing area geometries (polygons/multipolygons).
66
*
7-
* Converts area geometries to their centroid points, useful for point-based rendering
8-
* at lower zoom levels or when displaying areas as points.
7+
* Converts area geometries to their centroid points using ST_MaximumInscribedCircle,
8+
* which provides a better centroid position (center of the largest inscribed circle)
9+
* compared to ST_Centroid. Useful for point-based rendering at lower zoom levels
10+
* or when displaying areas as points.
911
*
1012
* Uses a temporary view pattern to avoid downtime: creates the new view with a _tmp suffix,
1113
* then atomically replaces the old view by dropping it and renaming the temporary one.
@@ -48,7 +50,7 @@ BEGIN
4850
-- 2) Build the CREATE MATERIALIZED VIEW statement
4951
sql := format(
5052
'CREATE MATERIALIZED VIEW %I AS
51-
SELECT %s, ST_Centroid(geometry) AS geometry
53+
SELECT %s, (ST_MaximumInscribedCircle(geometry)).center AS geometry
5254
FROM %I
5355
WHERE geometry IS NOT NULL
5456
AND ST_GeometryType(geometry) IN (''ST_Polygon'', ''ST_MultiPolygon'')',

images/tiler-server/config/providers/landuse_lines.toml

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[[providers.layers]]
2-
name = "landuse_lines"
2+
name = "landuse_lines_z14_15"
33
geometry_fieldname = "geometry"
44
geometry_type = "linestring"
55
id_fieldname = "osm_id"
@@ -16,13 +16,45 @@ SELECT
1616
end_decdate,
1717
{{LENGUAGES}}
1818
FROM
19-
mv_landuse_lines_z14_20
19+
mv_landuse_lines_z14_15
20+
WHERE
21+
geometry && !BBOX!
22+
"""
23+
24+
[[providers.layers]]
25+
name = "landuse_lines_z16_20"
26+
geometry_fieldname = "geometry"
27+
geometry_type = "linestring"
28+
id_fieldname = "osm_id"
29+
sql = """
30+
SELECT
31+
ST_AsMVTGeom(geometry, !BBOX!) AS geometry,
32+
osm_id,
33+
name,
34+
class,
35+
type,
36+
start_date,
37+
end_date,
38+
start_decdate,
39+
end_decdate,
40+
{{LENGUAGES}}
41+
FROM
42+
mv_landuse_lines_z16_20
2043
WHERE
2144
geometry && !BBOX!
2245
"""
2346
#######Maps
47+
2448
[[maps.layers]]
2549
name = "landuse_lines"
26-
provider_layer = "osm.landuse_lines"
50+
provider_layer = "osm.landuse_lines_z14_15"
2751
min_zoom = 14
52+
max_zoom = 15
53+
54+
[[maps.layers]]
55+
name = "landuse_lines"
56+
provider_layer = "osm.landuse_lines_z16_20"
57+
min_zoom = 16
2858
max_zoom = 20
59+
60+

0 commit comments

Comments
 (0)