diff --git a/.github/workflows/chartpress.yaml b/.github/workflows/chartpress.yaml index f6df8b8a..641595c8 100644 --- a/.github/workflows/chartpress.yaml +++ b/.github/workflows/chartpress.yaml @@ -5,7 +5,7 @@ on: - 'main' - 'staging' - 'staging_deploy' - - 'tiler_refresh' + - 'vtiles_admin' jobs: build: runs-on: ubuntu-22.04 diff --git a/DOC-VTILES.md b/DOC-VTILES.md new file mode 100644 index 00000000..cb150ed7 --- /dev/null +++ b/DOC-VTILES.md @@ -0,0 +1,260 @@ +# Tables and Zoom Levels for Tiler - Documentation and Standardization + +This document lists all materialized tables (mv_*) used in TOML configuration files and proposes a standard zoom level schema to unify the configuration. + + +### Standardize in gaps: 0‑2, 3‑5, 6‑7, 8‑9, 10‑12, 13‑15, 16‑20 + +### Simplification: + +### Large areas by zoom level + - 0‑2: 5000 + - 3‑5: 1000 + - 6‑7: 200 + - 8‑9: 100 + - 10‑12: 20 + - 13‑15: 5–10 (choose one and be consistent between water/admin) + - 16‑20: 0–1 (0 for clean polygons, 1 if there are very dense geometries) + + +### Transport lines / routes + - 0‑2: 5000 + - 3‑5: 1000 + - 6‑7: 200 + - 8‑9: 100 + - 10‑12: 20 + - 13‑15: 5 + - 16‑20: 0 + + +## Current MView Values by Category + +These tables document all current simplification values and area filters for each materialized view, extracted from SQL files in `/images/tiler-imposm/queries/ohm_mviews/`. + +**Legend:** +- `-` = Not applicable / No simplification / No area filter +- ⚠️ = Detected inconsistency that should be standardized +- **Derived** = View created from another mview (not directly from source table) + +# Water Areas (water_areas) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_water_areas_z16_20` | 16-20 | 0 | - | `osm_water_areas` | - | Base view | + | `mv_water_areas_z13_15` | 13-15 | 5 | - | `mv_water_areas_z16_20` | - | Derived | + | `mv_water_areas_z10_12` | 10-12 | 20 | 100 | `mv_water_areas_z13_15` | type IN ('water','pond','basin','canal','mill_pond','riverbank') | Derived | + | `mv_water_areas_z8_9` | 8-9 | 100 | 10,000 | `mv_water_areas_z10_12` | - | Derived | + | `mv_water_areas_z6_7` | 6-7 | 200 | 1,000,000 | `mv_water_areas_z8_9` | - | Derived | + | `mv_water_areas_z3_5` | 3-5 | 1000 | 50,000,000 | `mv_water_areas_z6_7` | - | Derived | + | `mv_water_areas_z0_2` | 0-2 | 5000 | 100,000,000 | `mv_water_areas_z3_5` | type IN ('water','riverbank') | Derived | + + +# Water Centroids (water_areas_centroids) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_water_areas_centroids_z16_20` | 16-20 | - | - | `mv_water_areas_z16_20` | name IS NOT NULL AND name <> '' | Derived | + | `mv_water_areas_centroids_z13_15` | 13-15 | - | - | `mv_water_areas_z13_15` | name IS NOT NULL AND name <> '' | Derived | + | `mv_water_areas_centroids_z10_12` | 10-12 | - | - | `mv_water_areas_z10_12` | name IS NOT NULL AND name <> '' | Derived | + | `mv_water_areas_centroids_z8_9` | 8-9 | - | - | `mv_water_areas_z8_9` | name IS NOT NULL AND name <> '' | Derived | + + +# Water Lines (water_lines) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_water_lines_z16_20` | 16-20 | 0 | - | `osm_water_lines` | type IN ('river','canal','cliff','dam','stream','ditch','drain') | Base view | + | `mv_water_lines_z13_15` | 13-15 | 5 | - | `mv_water_lines_z16_20` | type IN ('river','canal','cliff','dam','stream') | Derived | + | `mv_water_lines_z10_12` | 10-12 | 20 | - | `mv_water_lines_z13_15` | type IN ('river','canal','cliff','dam') | Derived | + | `mv_water_lines_z8_9` | 8-9 | 100 | - | `mv_water_lines_z10_12` | type IN ('river','canal') | Derived | + +# Administrative Boundaries - Areas (admin_boundaries_areas) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_admin_boundaries_areas_z16_20` | 16-20 | 1 | - | `osm_admin_areas` | admin_level IN (1,2,3,4,5,6,7,8,9,10,11) | Base view | + | `mv_admin_boundaries_areas_z13_15` | 13-15 | 5 | - | `mv_admin_boundaries_areas_z16_20` | no-filters | Derived | + | `mv_admin_boundaries_areas_z10_12` | 10-12 | 20 | - | `mv_admin_boundaries_areas_z13_15` | admin_level IN (1,2,3,4,5,6,7,8,9,10) | Derived | + | `mv_admin_boundaries_areas_z8_9` | 8-9 | 100 | - | `mv_admin_boundaries_areas_z10_12` | admin_level IN (1,2,3,4,5,6,7,8,9) | Derived | + | `mv_admin_boundaries_areas_z6_7` | 6-7 | 200 | - | `mv_admin_boundaries_areas_z8_9` | admin_level IN (1,2,3,4,5,6) | Derived | + | `mv_admin_boundaries_areas_z3_5` | 3-5 | 1000 | - | `mv_admin_boundaries_areas_z6_7` | admin_level IN (1,2,3,4) | Derived | + | `mv_admin_boundaries_areas_z0_2` | 0-2 | 5000 | - | `mv_admin_boundaries_areas_z3_5` | admin_level IN (1,2) | Derived | + +# Administrative Boundaries - Centroids (admin_boundaries_centroids) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_admin_boundaries_centroids_z16_20` | 16-20 | - | - | `mv_admin_boundaries_areas_z16_20` | name IS NOT NULL AND name <> '' | Derived | + | `mv_admin_boundaries_centroids_z13_15` | 13-15 | - | - | `mv_admin_boundaries_areas_z13_15` | name IS NOT NULL AND name <> '' | Derived | + | `mv_admin_boundaries_centroids_z10_12` | 10-12 | - | - | `mv_admin_boundaries_areas_z10_12` | name IS NOT NULL AND name <> '' | Derived | + | `mv_admin_boundaries_centroids_z8_9` | 8-9 | - | - | `mv_admin_boundaries_areas_z8_9` | name IS NOT NULL AND name <> '' | Derived | + | `mv_admin_boundaries_centroids_z6_7` | 6-7 | - | - | `mv_admin_boundaries_areas_z6_7` | name IS NOT NULL AND name <> '' | Derived | + | `mv_admin_boundaries_centroids_z3_5` | 3-5 | - | - | `mv_admin_boundaries_areas_z3_5` | name IS NOT NULL AND name <> '' | Derived | + | `mv_admin_boundaries_centroids_z0_2` | 0-2 | - | - | `mv_admin_boundaries_areas_z0_2` | name IS NOT NULL AND name <> '' | Derived | + +# Administrative Boundaries - Lines (admin_boundaries_lines) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_admin_boundaries_lines_z16_20` | 16-20 | 1 | - | `mv_admin_boundaries_relations_ways` | admin_level IN (1,2,3,4,5,6,7,8,9,10,11) | `mv_relation_members_boundaries` + `osm_admin_lines` | + | `mv_admin_boundaries_lines_z13_15` | 13-15 | 5 | - | `mv_admin_boundaries_lines_z16_20` | admin_level IN (1,2,3,4,5,6,7,8,9,10) | Derived | + | `mv_admin_boundaries_lines_z10_12` | 10-12 | 20 | - | `mv_admin_boundaries_lines_z13_15` | no-filters | Derived | + | `mv_admin_boundaries_lines_z8_9` | 8-9 | 100 | - | `mv_admin_boundaries_lines_z10_12` | admin_level IN (1,2,3,4,5,6,7,8,9) | Derived | + | `mv_admin_boundaries_lines_z6_7` | 6-7 | 200 | - | `mv_admin_boundaries_lines_z8_9` | admin_level IN (1,2,3,4,5,6) | Derived | + | `mv_admin_boundaries_lines_z3_5` | 3-5 | 1000 | - | `mv_admin_boundaries_lines_z6_7` | admin_level IN (1,2,3,4) | Derived | + | `mv_admin_boundaries_lines_z0_2` | 0-2 | 5000 | - | `mv_admin_boundaries_lines_z3_5` | admin_level IN (1,2) | Derived | + +# Administrative Boundaries - Maritime (admin_boundaries_maritime) + +TODO: fix according to schema + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_admin_maritime_lines_z0_5_v2` | 0-5 ⚠️ | 2000 | - | `osm_admin_lines` | maritime = 'yes' | Should be z0_2 + z3_5 | + | `mv_admin_maritime_lines_z6_9` | 6-9 ⚠️ | 500 | - | `osm_admin_lines` | maritime = 'yes' | Should be z6_7 + z8_9 | + | `mv_admin_maritime_lines_z10_15` | 10-15 ⚠️ | 10 | - | `osm_admin_lines` | maritime = 'yes' | Should be z10_12 + z13_15 | + + +# Land Use - Areas (landuse_areas) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_landuse_areas_z16_20` | 16-20 | 0 | - | `osm_landuse_areas` | NOT (type = 'water' AND class = 'natural') | Base view | + | `mv_landuse_areas_z13_15` | 13-15 | 5 | 10,000 | `mv_landuse_areas_z16_20` | - | Derived | + | `mv_landuse_areas_z10_12` | 10-12 | 20 | 50,000 | `mv_landuse_areas_z13_15` | - | Derived | + | `mv_landuse_areas_z8_9` | 8-9 | 100 | 1,000,000 | `mv_landuse_areas_z10_12` | - | Derived | + | `mv_landuse_areas_z6_7` | 6-7 | 200 | 10,000,000 | `mv_landuse_areas_z8_9` | - | Derived | + +# Land Use - Centroids (landuse_points_centroids) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_landuse_points_centroids_z16_20` | 16-20 | - | - | `mv_landuse_areas_z16_20` + `mv_landuse_points` | - | Derived (points from `osm_landuse_points`) | + | `mv_landuse_points_centroids_z13_15` | 13-15 | - | - | `mv_landuse_areas_z13_15` | - | Derived | + | `mv_landuse_points_centroids_z10_12` | 10-12 | - | - | `mv_landuse_areas_z10_12` | - | Derived | + | `mv_landuse_points_centroids_z8_9` | 8-9 | - | - | `mv_landuse_areas_z8_9` | - | Derived | + | `mv_landuse_points_centroids_z6_7` | 6-7 | - | - | `mv_landuse_areas_z6_7` + `mv_landuse_points` | - | Derived | + +# Land Use - Lines (landuse_lines) + + - Filtering only tree_row, since this is the only one used in the mapstyles + + | MView | Zoom Levels | Simplification (m) | Min Length (m) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_landuse_lines_z16_20` | 16-20 | 5 | 0 | `osm_landuse_lines` | type IN ('tree_row') | Base view | + | `mv_landuse_lines_z14_15` | 14-15 | 5 | - | `mv_landuse_lines_z16_20` | - | Derived | + +# Transport - Areas (transport_areas) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_transport_areas_z16_20` | 16-20 | 0 | - | `osm_transport_areas` | NOT (class = 'highway' AND type IN ('motorway','motorway_link','trunk','trunk_link','primary','primary_link','secondary','secondary_link','tertiary','tertiary_link','unclassified','residential','service','living_street','cycleway','bridleway')) | Base view | + | `mv_transport_areas_z13_15` | 13-15 | 5 | - | `mv_transport_areas_z16_20` | - | Derived | + | `mv_transport_areas_z10_12` | 10-12 | 20 | 100 | `mv_transport_areas_z13_15` | type IN ('aerodrome','apron','terminal') | Derived | + +# Transport - Centroids (transport_points_centroids) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_transport_points_centroids_z16_20` | 16-20 | - | - | `mv_transport_areas_z16_20` + `mv_transport_points` | - | Derived (points from `osm_transport_points`) | + | `mv_transport_points_centroids_z13_15` | 13-15 | - | - | `mv_transport_areas_z13_15` + `mv_transport_points` | - | Derived (points from `osm_transport_points`) | + | `mv_transport_points_centroids_z10_12` | 10-12 | - | - | `mv_transport_areas_z10_12` | - | Derived | + + +# Transport - Lines (transport_lines) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_transport_lines_z16_20` | 16-20 | 0 | - | `osm_transport_lines` + `osm_transport_multilines` | type = ANY(['*']) OR class IN ('railway','route') | Base view (merged) | + | `mv_transport_lines_z13_15` | 13-15 | 5 | - | `mv_transport_lines_z16_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','raceway','residential','service','unclassified') OR class IN ('railway') | Derived | + | `mv_transport_lines_z10_12` | 10-12 | 20 | - | `mv_transport_lines_z13_15` | 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') | Derived | + | `mv_transport_lines_z8_9` | 8-9 | 100 | - | `mv_transport_lines_z10_12` | - | Derived | + | `mv_transport_lines_z6_7` | 6-7 | 200 | - | `mv_transport_lines_z8_9` | type IN ('motorway','motorway_link','trunk','trunk_link','construction','primary','primary_link','rail','secondary','secondary_link') OR class IN ('railway') | Derived | + | `mv_transport_lines_z5` | 5 | 1000 | - | `mv_transport_lines_z6_7` | - | Derived | + + + +# Buildings - Areas (buildings_areas) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_buildings_areas_z16_20` | 16-20 | 0 | - | `osm_buildings` | - | Base view | + | `mv_buildings_areas_z14_15` | 14-15 | 5 | 5,000 | `osm_buildings` | - | Starts showing at zoom 14 | + + +# Buildings - Centroids (buildings_points_centroids) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_buildings_points_centroids_z16_20` | 16-20 | - | - | `mv_buildings_areas_z16_20` + `mv_buildings_points` | - | Derived (points from `osm_buildings_points`) | + | `mv_buildings_points_centroids_z14_15` | 14-15 | - | - | `mv_buildings_areas_z14_15` + `mv_buildings_points` | - | Derived (points from `osm_buildings_points`) | + +# Amenities - Areas (amenity_areas) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_amenity_areas_z16_20` | 16-20 | 0 | - | `osm_amenity_areas` | - | Base view | + | `mv_amenity_areas_z14_15` | 14-15 | 5 | 5,000 | `osm_amenity_areas` | - | Starts showing at zoom 14 | + +# Amenities - Centroids (amenity_points_centroids) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_amenity_points_centroids_z16_20` | 16-20 | - | - | `mv_amenity_areas_z16_20` + `mv_amenity_points` | - | Derived (points from `osm_amenity_points`) | + | `mv_amenity_points_centroids_z14_15` | 14-15 | - | - | `mv_amenity_areas_z14_15` + `mv_amenity_points` | - | Derived (points from `osm_amenity_points`) | + +# Other - Areas (other_areas) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_other_areas_z16_20` | 16-20 | 0 | - | `osm_other_areas` | - | Base view | + | `mv_other_areas_z13_15` | 13-15 | 5 | 5,000 | `osm_other_areas` | - | Base view | + | `mv_other_areas_z10_12` | 10-12 | 20 | 50,000 | `osm_other_areas` | - | Base view | + | `mv_other_areas_z8_9` | 8-9 | 100 | 1,000,000 | `osm_other_areas` | - | Base view | + +# Other - Centroids (other_points_centroids) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_other_points_centroids_z16_20` | 16-20 | - | - | `mv_other_areas_z16_20` + `mv_other_points` | - | Derived (points from `osm_other_points`) | + | `mv_other_points_centroids_z13_15` | 13-15 | - | - | `mv_other_areas_z13_15` + `mv_other_points` | - | Derived (points from `osm_other_points`) | + | `mv_other_points_centroids_z10_12` | 10-12 | - | - | `mv_other_areas_z10_12` | - | Derived | + | `mv_other_points_centroids_z8_9` | 8-9 | - | - | `mv_other_areas_z8_9` | - | Derived | + +# Other - Lines (other_lines) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_other_lines_z16_20` | 16-20 | 0 | - | `osm_other_lines` | - | Base view | + | `mv_other_lines_z14_15` | 14-15 | 5 | - | `mv_other_lines_z16_20` | - | Derived | + + +# Places - Areas (place_areas) + +TODO: fix according to schema + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_place_areas_z14_20` | 14-20 ⚠️ | - | - | `osm_place_areas` | type IN ('plot','square','islet') | Should be z14_15 + z16_20 | + +# Places - Centroids (place_points_centroids) +TODO: fix according to schema + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_place_points_centroids_z0_2` | 0-2 | - | - | `osm_place_areas` + `osm_place_points` | Areas: type IN ('island'); Points: type IN ('ocean','sea','archipelago','country','territory','unorganized territory') | Merged from areas and points | + | `mv_place_points_centroids_z3_5` | 3-5 | - | - | `osm_place_areas` + `osm_place_points` | Areas: type IN ('island'); Points: type IN ('ocean','sea','archipelago','country','territory','unorganized territory','state','province','region') | Merged from areas and points | + | `mv_place_points_centroids_z6_10` | 6-10 ⚠️ | - | - | `osm_place_areas` + `osm_place_points` | Areas: type IN ('island'); Points: type IN ('ocean','sea','archipelago','country','territory','unorganized territory','state','province','region','county','municipality','city','town') | Wide range - Merged from areas and points | + | `mv_place_points_centroids_z11_20` | 11-20 ⚠️ | - | - | `osm_place_areas` + `osm_place_points` | Areas: type IN ('plot','square','islet'); Points: type IN ('state','province','region','county','municipality','city','town','village','suburb','locality','hamlet','islet','neighbourhood','district','borough','quarter','isolated_dwelling','farm') | Very wide range - Merged from areas and points | + +# Routes - Lines (routes_indexed) + + | MView | Zoom Levels | Simplification (m) | Min Area (m²) | Source | Filters | Notes | + |-------|-------------|-------------------|---------------|--------|---------|-------| + | `mv_routes_indexed_z16_20` | 16-20 | 0 | - | `mv_routes_indexed` | - | Base view | + | `mv_routes_indexed_z13_15` | 13-15 | 5 | - | `mv_routes_indexed_z16_20` | - | Derived | + | `mv_routes_indexed_z10_12` | 10-12 | 20 | - | `mv_routes_indexed_z13_15` | - | Derived | + | `mv_routes_indexed_z8_9` | 8-9 | 100 | - | `mv_routes_indexed_z10_12` | - | Derived | + | `mv_routes_indexed_z6_7` | 6-7 | 200 | - | `mv_routes_indexed_z8_9` | - | Derived | + | `mv_routes_indexed_z5` | 5 | 1000 | - | `mv_routes_indexed_z6_7` | - | Derived | + diff --git a/hetzner/tiler/tiler.staging.yml b/hetzner/tiler/tiler.staging.yml index 50471a03..8415c315 100644 --- a/hetzner/tiler/tiler.staging.yml +++ b/hetzner/tiler/tiler.staging.yml @@ -21,7 +21,11 @@ services: imposm_staging: container_name: tiler_imposm_staging - image: ghcr.io/openhistoricalmap/tiler-imposm:0.0.1-0.dev.git.3183.h59d5a56 + # image: ghcr.io/openhistoricalmap/tiler-imposm:0.0.1-0.dev.git.3183.h59d5a56 + image: tiler-imposm:staging + build: + context: ../../images/tiler-imposm + dockerfile: Dockerfile volumes: - tiler_staging_imposmdata:/mnt/data command: @@ -35,7 +39,6 @@ services: networks: - ohm_network - tiler_server_staging: container_name: tiler_server_staging image: ghcr.io/openhistoricalmap/tiler-server:0.0.1-0.dev.git.3175.hbdd6021 @@ -106,10 +109,10 @@ services: volumes: tiler_staging_pgdata: driver: local - name: tiler_db_1212_v2 + name: tiler_db_05_01_v9 tiler_staging_imposmdata: driver: local - name: tiler_imposm_1212_v2 + name: tiler_imposm_05_01_v9 networks: ohm_network: diff --git a/images/tiler-db/Dockerfile b/images/tiler-db/Dockerfile index 4abe61dd..4bf70ca7 100644 --- a/images/tiler-db/Dockerfile +++ b/images/tiler-db/Dockerfile @@ -15,4 +15,4 @@ RUN git clone https://github.com/OpenHistoricalMap/DateFunctions-plpgsql.git . # Deploy improvements to negative year handling RUN git checkout d9f06a4ac0674881247c38b29ba58ff1d167b7bb -RUN cp datefunctions.sql /docker-entrypoint-initdb.d/datefunctions.sql +RUN cp datefunctions.sql /docker-entrypoint-initdb.d/datefunctions.sql \ No newline at end of file diff --git a/images/tiler-db/scripts/docker-entrypoint.sh b/images/tiler-db/scripts/docker-entrypoint.sh old mode 100755 new mode 100644 diff --git a/images/tiler-db/scripts/update_db.sh b/images/tiler-db/scripts/update_db.sh index 3e1ffdc6..64195af3 100644 --- a/images/tiler-db/scripts/update_db.sh +++ b/images/tiler-db/scripts/update_db.sh @@ -7,4 +7,4 @@ for DB in template_postgis "$POSTGRES_DB" "${@}"; do psql --dbname="$DB" -c " CREATE EXTENSION IF NOT EXISTS hstore; " -done +done \ No newline at end of file diff --git a/images/tiler-imposm/Dockerfile b/images/tiler-imposm/Dockerfile index 68726ffb..3e74fd02 100644 --- a/images/tiler-imposm/Dockerfile +++ b/images/tiler-imposm/Dockerfile @@ -1,4 +1,4 @@ -FROM osgeo/gdal:ubuntu-small-3.2.3 +FROM ghcr.io/osgeo/gdal:ubuntu-small-3.9.3 RUN apt-get -y update && apt-get install -y \ g++ \ @@ -18,21 +18,22 @@ RUN apt-get -y update && apt-get install -y \ curl \ wget \ unzip \ - software-properties-common && \ + ca-certificates \ + software-properties-common \ + python3-pip \ + postgresql-client && \ rm -rf /var/lib/apt/lists/* -RUN add-apt-repository ppa:deadsnakes/ppa && \ - apt-get update && \ - apt-get install -y python3.9 python3.9-dev python3-pip && \ - rm -rf /var/lib/apt/lists/* && \ - python3 -m pip install pip --upgrade && \ - python3 -m pip install wheel +RUN python3 -m pip install --no-cache-dir \ + --break-system-packages \ + awscli psycopg2-binary setuptools && \ + rm -rf /root/.cache /var/cache/apk/* RUN apt-get update && apt-get install -y postgresql-client && \ rm -rf /var/lib/apt/lists/* -RUN wget -c https://dl.google.com/go/go1.21.0.linux-amd64.tar.gz -O - | tar -xz -C /usr/local -ENV PATH $PATH:/usr/local/go/bin +RUN wget -c https://dl.google.com/go/go1.21.9.linux-amd64.tar.gz -O - | tar -xz -C /usr/local +ENV PATH="${PATH}:/usr/local/go/bin" ENV DATEFUNCTIONS_GITSHA=90d8d0f0daea4c8c5aa62edf440f26e9eb0ab950 RUN git clone https://github.com/OpenHistoricalMap/DateFunctions-plpgsql.git /usr/local/datefunctions && cd /usr/local/datefunctions && git checkout $DATEFUNCTIONS_GITSHA @@ -45,14 +46,11 @@ RUN git clone https://github.com/omniscale/imposm3.git $GOPATH/src/github.com/om WORKDIR $GOPATH/src/github.com/omniscale/imposm3 RUN git checkout v0.14.2 - # Apply fixes or patches (if necessary) RUN sed -i '/setMaxFileSize/d' cache/ldb_pre_121.go RUN go install github.com/omniscale/imposm3/cmd/imposm ENV PATH $PATH:$GOPATH/bin -# Install AWS CLI for downloading files -RUN pip3 install -U setuptools awscli psycopg2 WORKDIR /osm COPY . . CMD ["./start.sh"] diff --git a/images/tiler-imposm/config/imposm3.json b/images/tiler-imposm/config/imposm3.json index c35829ac..c1502c87 100644 --- a/images/tiler-imposm/config/imposm3.json +++ b/images/tiler-imposm/config/imposm3.json @@ -339,12 +339,9 @@ ], "type": "relation_member", "filters": { - "exclude_tags": [ - [ - "area", - "yes" - ] - ] + "reject": { + "area": ["yes"] + } }, "mappings": { "railway": { @@ -446,7 +443,7 @@ "key": "end_date" }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, @@ -557,12 +554,9 @@ ] }, "filters": { - "exclude_tags": [ - [ - "boundary", - "administrative" - ] - ] + "reject": { + "boundary": ["administrative"] + } } }, "water_areas": { @@ -588,7 +582,7 @@ "key": null }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, @@ -768,7 +762,7 @@ "key": "end_date" }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, @@ -995,7 +989,7 @@ "key": null }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, @@ -1172,7 +1166,7 @@ "key": "end_date" }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, @@ -1534,12 +1528,9 @@ ], "type": "linestring", "filters": { - "exclude_tags": [ - [ - "area", - "yes" - ] - ] + "reject": { + "area": ["yes"] + } }, "mappings": { "railway": { @@ -1590,7 +1581,7 @@ "key": "name" }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, @@ -1817,20 +1808,11 @@ ], "type": "linestring", "filters": { - "exclude_tags": [ - [ - "area", - "yes" - ], - [ - "natural", - "coastline" - ], - [ - "boundary", - "administrative" - ] - ] + "reject": { + "area": ["yes"], + "natural": ["coastline"], + "boundary": ["administrative"] + } }, "mappings": { "landuse": { @@ -1894,7 +1876,7 @@ "key": "end_date" }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, @@ -1955,7 +1937,7 @@ "key": null }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, @@ -2043,7 +2025,7 @@ "key": "end_date" }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, diff --git a/images/tiler-imposm/config/layers/admin_areas.json b/images/tiler-imposm/config/layers/admin_areas.json index 79c74631..3d2dbf26 100644 --- a/images/tiler-imposm/config/layers/admin_areas.json +++ b/images/tiler-imposm/config/layers/admin_areas.json @@ -7,47 +7,7 @@ "source:datetime" ] }, - "generalized_tables": { - "admin_areas_z0_2": { - "source": "admin_areas", - "tolerance": 5000, - "sql_filter": "admin_level IN (1,2)" - }, - - "admin_areas_z3_5": { - "source": "admin_areas", - "tolerance": 1000, - "sql_filter": "admin_level IN (1,2,3,4)" - }, - - "admin_areas_z6_7": { - "source": "admin_areas", - "tolerance": 200, - "sql_filter": "admin_level IN (1,2,3,4,5,6)" - }, - - "admin_areas_z8_9": { - "source": "admin_areas", - "tolerance": 100, - "sql_filter": "admin_level IN (1,2,3,4,5,6,7,8,9)" - }, - - "admin_areas_z10_12": { - "source": "admin_areas", - "tolerance": 20, - "sql_filter": "admin_level IN (1,2,3,4,5,6,7,8,9,10)" - }, - - "admin_areas_z13_15": { - "source": "admin_areas", - "tolerance": 5, - "sql_filter": "admin_level IN (1,2,3,4,5,6,7,8,9,10)" - }, - "admin_areas_z16_20": { - "source": "admin_areas", - "sql_filter": "admin_level IN (1,2,3,4,5,6,7,8,9,10)" - } - }, + "generalized_tables": {}, "tables": { "admin_areas": { "fields": [ @@ -92,7 +52,7 @@ "key": "end_date" }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, diff --git a/images/tiler-imposm/config/layers/admin_lines.json b/images/tiler-imposm/config/layers/admin_lines.json index 41c4cd20..3e35bb63 100644 --- a/images/tiler-imposm/config/layers/admin_lines.json +++ b/images/tiler-imposm/config/layers/admin_lines.json @@ -7,27 +7,7 @@ "source:datetime" ] }, - "generalized_tables": { - "admin_lines_z0_5": { - "source": "admin_lines_z6_9", - "sql_filter": "maritime='yes'", - "tolerance": 2000 - }, - "admin_lines_z6_9": { - "source": "admin_lines_z10_15", - "sql_filter": "maritime='yes'", - "tolerance": 500 - }, - "admin_lines_z10_15": { - "source": "admin_lines_z16_20", - "sql_filter": "maritime='yes'", - "tolerance": 10 - }, - "admin_lines_z16_20": { - "source": "admin_lines", - "sql_filter": "maritime='yes'" - } - }, + "generalized_tables": {}, "tables": { "admin_lines": { "fields": [ diff --git a/images/tiler-imposm/config/layers/amenity_areas.json b/images/tiler-imposm/config/layers/amenity_areas.json index 59d3861c..899a1476 100644 --- a/images/tiler-imposm/config/layers/amenity_areas.json +++ b/images/tiler-imposm/config/layers/amenity_areas.json @@ -47,7 +47,7 @@ "key": "end_date" }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, diff --git a/images/tiler-imposm/config/layers/buildings.json b/images/tiler-imposm/config/layers/buildings.json index 04a47d04..a018dd6a 100644 --- a/images/tiler-imposm/config/layers/buildings.json +++ b/images/tiler-imposm/config/layers/buildings.json @@ -52,7 +52,7 @@ "key": "end_date" }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, diff --git a/images/tiler-imposm/config/layers/landuse_areas.json b/images/tiler-imposm/config/layers/landuse_areas.json index 1d1528f4..a27a41f2 100644 --- a/images/tiler-imposm/config/layers/landuse_areas.json +++ b/images/tiler-imposm/config/layers/landuse_areas.json @@ -47,7 +47,7 @@ "key": "end_date" }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, diff --git a/images/tiler-imposm/config/layers/landuse_lines.json b/images/tiler-imposm/config/layers/landuse_lines.json index 4d81b34a..8a4f526e 100644 --- a/images/tiler-imposm/config/layers/landuse_lines.json +++ b/images/tiler-imposm/config/layers/landuse_lines.json @@ -54,20 +54,11 @@ ], "type": "linestring", "filters": { - "exclude_tags": [ - [ - "area", - "yes" - ], - [ - "natural", - "coastline" - ], - [ - "boundary", - "administrative" - ] - ] + "reject": { + "area": ["yes"], + "natural": ["coastline"], + "boundary": ["administrative"] + } }, "mappings": { "landuse": { diff --git a/images/tiler-imposm/config/layers/landuse_points.json b/images/tiler-imposm/config/layers/landuse_points.json index 89698457..2374ebff 100644 --- a/images/tiler-imposm/config/layers/landuse_points.json +++ b/images/tiler-imposm/config/layers/landuse_points.json @@ -32,7 +32,7 @@ "key": null }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, diff --git a/images/tiler-imposm/config/layers/other_areas.json b/images/tiler-imposm/config/layers/other_areas.json index 181bb568..22b4b313 100644 --- a/images/tiler-imposm/config/layers/other_areas.json +++ b/images/tiler-imposm/config/layers/other_areas.json @@ -37,7 +37,7 @@ "key": null }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, diff --git a/images/tiler-imposm/config/layers/place_areas.json b/images/tiler-imposm/config/layers/place_areas.json index 33f91c34..bed7f270 100644 --- a/images/tiler-imposm/config/layers/place_areas.json +++ b/images/tiler-imposm/config/layers/place_areas.json @@ -52,7 +52,7 @@ "key": "end_date" }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, diff --git a/images/tiler-imposm/config/layers/relations.json b/images/tiler-imposm/config/layers/relations.json index 6310a669..b3ad20e9 100644 --- a/images/tiler-imposm/config/layers/relations.json +++ b/images/tiler-imposm/config/layers/relations.json @@ -47,12 +47,9 @@ ] }, "filters": { - "exclude_tags": [ - [ - "boundary", - "administrative" - ] - ] + "reject": { + "boundary": ["administrative"] + } } } } diff --git a/images/tiler-imposm/config/layers/transport_areas.json b/images/tiler-imposm/config/layers/transport_areas.json index 87157e31..d5fcfd7b 100644 --- a/images/tiler-imposm/config/layers/transport_areas.json +++ b/images/tiler-imposm/config/layers/transport_areas.json @@ -27,7 +27,7 @@ "key": "name" }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, diff --git a/images/tiler-imposm/config/layers/transport_lines.json b/images/tiler-imposm/config/layers/transport_lines.json index b483c936..d5e6d105 100644 --- a/images/tiler-imposm/config/layers/transport_lines.json +++ b/images/tiler-imposm/config/layers/transport_lines.json @@ -129,12 +129,9 @@ ], "type": "linestring", "filters": { - "exclude_tags": [ - [ - "area", - "yes" - ] - ] + "reject": { + "area": ["yes"] + } }, "mappings": { "railway": { diff --git a/images/tiler-imposm/config/layers/transport_multilines.json b/images/tiler-imposm/config/layers/transport_multilines.json index 4f1968c8..fbd3d5ef 100644 --- a/images/tiler-imposm/config/layers/transport_multilines.json +++ b/images/tiler-imposm/config/layers/transport_multilines.json @@ -143,12 +143,9 @@ ], "type": "relation_member", "filters": { - "exclude_tags": [ - [ - "area", - "yes" - ] - ] + "reject": { + "area": ["yes"] + } }, "mappings": { "railway": { diff --git a/images/tiler-imposm/config/layers/water_areas.json b/images/tiler-imposm/config/layers/water_areas.json index 78e8a20e..50e4d0ac 100644 --- a/images/tiler-imposm/config/layers/water_areas.json +++ b/images/tiler-imposm/config/layers/water_areas.json @@ -7,38 +7,7 @@ "source:datetime" ] }, -"generalized_tables": { - "water_areas_z0_2": { - "source": "water_areas_z3_5", - "sql_filter": "type IN ('water', 'riverbank') AND area > 100000000", - "tolerance": 5000 - }, - "water_areas_z3_5": { - "source": "water_areas_z6_7", - "sql_filter": "area > 50000000", - "tolerance": 1000 - }, - "water_areas_z6_7": { - "source": "water_areas_z8_9", - "sql_filter": "area > 1000000", - "tolerance": 200 - }, - "water_areas_z8_9": { - "source": "water_areas_z10_12", - "sql_filter": "type IN ('water', 'pond', 'basin', 'canal', 'mill_pond', 'riverbank') AND area > 10000", - "tolerance": 100 - }, - "water_areas_z10_12": { - "source": "water_areas_z13_15", - "sql_filter": "type IN ('water', 'pond', 'basin', 'canal', 'mill_pond', 'riverbank')", - "tolerance": 20 - }, - "water_areas_z13_15": { - "source": "water_areas", - "sql_filter": "type IN ('water', 'pond', 'basin', 'canal', 'mill_pond', 'riverbank', 'dock')", - "tolerance": 5 - } -}, +"generalized_tables": {}, "tables": { "water_areas": { "fields": [ @@ -68,7 +37,7 @@ "key": null }, { - "type": "pseudoarea", + "type": "area", "name": "area", "key": null }, diff --git a/images/tiler-imposm/config/layers/water_lines.json b/images/tiler-imposm/config/layers/water_lines.json index 7d6f4ffd..2604360e 100644 --- a/images/tiler-imposm/config/layers/water_lines.json +++ b/images/tiler-imposm/config/layers/water_lines.json @@ -7,27 +7,7 @@ "source:datetime" ] }, - "generalized_tables": { - "water_lines_z8_9": { - "source": "water_lines", - "sql_filter": "type IN ('river', 'canal')", - "tolerance": 100 - }, - "water_lines_z10_12": { - "source": "water_lines", - "sql_filter": "type IN ('river', 'canal', 'cliff', 'dam')", - "tolerance": 20 - }, - "water_lines_z13_15": { - "source": "water_lines", - "sql_filter": "type IN ('river', 'canal', 'cliff', 'dam', 'stream')", - "tolerance": 5 - }, - "water_lines_z16_20": { - "source": "water_lines", - "sql_filter": "type IN ('river', 'canal', 'cliff', 'dam', 'stream', 'ditch', 'drain')" - } - }, + "generalized_tables": {}, "tables": { "water_lines": { "fields": [ diff --git a/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_areas.sql b/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_areas.sql index 4df95281..ac2b3dcc 100644 --- a/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_areas.sql +++ b/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_areas.sql @@ -1,69 +1,22 @@ -- ============================================================================ --- Function: create_admin_boundaries_areas_mview --- Description: --- Creates a materialized view from the specified source table. --- - Includes multilingual name columns using get_language_columns(). --- - Calculates area in km² (rounded to integer). --- - No filtering; all rows from the source table are included. --- --- Parameters: --- source_table TEXT - Name of the source table to read from. --- view_name TEXT - Name of the materialized view to be created. --- --- Notes: --- - Creates the materialized view using a temporary swap mechanism to avoid downtime. --- - Adds a spatial (GiST) index on geometry and a unique index on (osm_id, type, admin_level). --- - Includes temporal fields: start_date, end_date, and their decimal date equivalents. --- - Useful for rendering administrative boundaries at different zoom levels. +-- Create materialized views for admin boundaries areas -- ============================================================================ -DROP FUNCTION IF EXISTS create_admin_boundaries_areas_mview; +DROP FUNCTION MATERIALIZED VIEW IF EXISTS mv_admin_boundaries_areas_z16_20 CASCADE; -CREATE OR REPLACE FUNCTION create_admin_boundaries_areas_mview( - source_table TEXT, - view_name TEXT -) -RETURNS void AS $$ -DECLARE - lang_columns TEXT := get_language_columns(); - tmp_view_name TEXT := view_name || '_tmp'; - unique_columns TEXT := 'osm_id, type, admin_level'; - sql_create TEXT; -BEGIN - sql_create := format($sql$ - CREATE MATERIALIZED VIEW %I AS - SELECT - geometry, - ABS(osm_id) AS osm_id, - NULLIF(name, '') AS name, - type, - admin_level, - ROUND(CAST(area AS numeric) / 1000000)::integer AS area_km2, - NULLIF(start_date, '') AS start_date, - NULLIF(end_date, '') AS end_date, - isodatetodecimaldate(pad_date(start_date, 'start'), FALSE) AS start_decdate, - isodatetodecimaldate(pad_date(end_date, 'end'), FALSE) AS end_decdate, - area, - %s - FROM %I; - $sql$, tmp_view_name, lang_columns, source_table); +SELECT create_areas_mview( 'osm_admin_areas', 'mv_admin_boundaries_areas_z16_20', 1, 0, 'id, osm_id, type', 'admin_level IN (1,2,3,4,5,6,7,8,9,10,11)'); +SELECT create_area_mview_from_mview('mv_admin_boundaries_areas_z16_20','mv_admin_boundaries_areas_z13_15', 5, 0.0, NULL); +SELECT create_area_mview_from_mview('mv_admin_boundaries_areas_z13_15','mv_admin_boundaries_areas_z10_12', 20, 0.0, 'admin_level IN (1,2,3,4,5,6,7,8,9,10)'); +SELECT create_area_mview_from_mview('mv_admin_boundaries_areas_z10_12','mv_admin_boundaries_areas_z8_9', 100, 0.0, 'admin_level IN (1,2,3,4,5,6,7,8,9)'); +SELECT create_area_mview_from_mview('mv_admin_boundaries_areas_z8_9','mv_admin_boundaries_areas_z6_7', 200, 0.0, 'admin_level IN (1,2,3,4,5,6)'); +SELECT create_area_mview_from_mview('mv_admin_boundaries_areas_z6_7','mv_admin_boundaries_areas_z3_5', 1000, 0.0, 'admin_level IN (1,2,3,4)'); +SELECT create_area_mview_from_mview('mv_admin_boundaries_areas_z3_5','mv_admin_boundaries_areas_z0_2', 5000, 0.0, 'admin_level IN (1,2)'); - PERFORM finalize_materialized_view( - tmp_view_name, - view_name, - unique_columns, - sql_create - ); -END; -$$ LANGUAGE plpgsql; - --- ============================================================================ --- Create materialized views from osm_admin_boundaries_areas --- ============================================================================ -SELECT create_admin_boundaries_areas_mview('osm_admin_areas_z0_2', 'mv_admin_boundaries_areas_z0_2'); -SELECT create_admin_boundaries_areas_mview('osm_admin_areas_z3_5', 'mv_admin_boundaries_areas_z3_5'); -SELECT create_admin_boundaries_areas_mview('osm_admin_areas_z6_7', 'mv_admin_boundaries_areas_z6_7'); -SELECT create_admin_boundaries_areas_mview('osm_admin_areas_z8_9', 'mv_admin_boundaries_areas_z8_9'); -SELECT create_admin_boundaries_areas_mview('osm_admin_areas_z10_12', 'mv_admin_boundaries_areas_z10_12'); -SELECT create_admin_boundaries_areas_mview('osm_admin_areas_z13_15', 'mv_admin_boundaries_areas_z13_15'); -SELECT create_admin_boundaries_areas_mview('osm_admin_areas_z16_20', 'mv_admin_boundaries_areas_z16_20'); +-- Refresh areas views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_areas_z0_2; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_areas_z3_5; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_areas_z6_7; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_areas_z8_9; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_areas_z10_12; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_areas_z13_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_areas_z16_20; diff --git a/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_centroids.sql b/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_centroids.sql index ea2f248c..33668901 100644 --- a/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_centroids.sql +++ b/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_centroids.sql @@ -2,54 +2,80 @@ -- Function: create_admin_boundaries_centroids_mview -- Description: -- Creates a materialized view of admin boundary centroids using --- ST_MaximumInscribedCircle from polygons in the input table. +-- ST_MaximumInscribedCircle from polygons in the input materialized view. +-- Extracts all columns dynamically from the source materialized view and +-- converts the geometry to a centroid point. -- -- Parameters: --- input_table TEXT - Source table name (e.g., osm_admin_areas_z0_2). --- mview_name TEXT - Name of the final materialized view to create. +-- source_mview TEXT - Source materialized view name (e.g., mv_admin_boundaries_areas_z16_20). +-- mview_name TEXT - Name of the final materialized view to create. +-- unique_columns TEXT - Comma-separated list of columns for uniqueness +-- (default: 'id, osm_id, type'). +-- where_filter TEXT - Optional WHERE filter condition to apply +-- (e.g., 'admin_level IN (1,2)'). -- -- Notes: -- - Excludes boundaries with role='label' from centroid calculation. --- - Area is stored in square kilometers as integer. +-- - Extracts all columns dynamically from the source materialized view. +-- - Converts geometry to centroid using ST_MaximumInscribedCircle. -- - Geometry is indexed using GiST. --- - Uniqueness is enforced on osm_id. --- - Includes multilingual name columns via get_language_columns(). +-- - Uniqueness is enforced on the specified unique_columns. -- - Uses finalize_materialized_view() for atomic creation and renaming. -- ============================================================================ DROP FUNCTION IF EXISTS create_admin_boundaries_centroids_mview; CREATE OR REPLACE FUNCTION create_admin_boundaries_centroids_mview( - input_table TEXT, - mview_name TEXT + source_mview TEXT, + mview_name TEXT, + unique_columns TEXT DEFAULT 'id, osm_id, type', + where_filter TEXT DEFAULT NULL ) RETURNS void AS $$ DECLARE tmp_mview_name TEXT := mview_name || '_tmp'; sql_create TEXT; - lang_columns TEXT := get_language_columns(); - unique_columns TEXT := 'osm_id'; + all_cols TEXT; + custom_filter TEXT; BEGIN + -- Build custom WHERE filter (if provided) + -- Note: custom_filter includes leading space and AND, so it can be concatenated directly + IF where_filter IS NOT NULL AND where_filter <> '' THEN + custom_filter := format(' AND (%s)', where_filter); + ELSE + custom_filter := ''; + END IF; + + -- Get all columns from the source materialized view, replacing geometry with centroid + SELECT COALESCE(string_agg( + CASE + WHEN a.attname = 'geometry' THEN '(ST_MaximumInscribedCircle(geometry)).center AS geometry' + ELSE quote_ident(a.attname) + END, + ', ' ORDER BY a.attnum + ), '') + INTO all_cols + FROM pg_attribute a + JOIN pg_class c ON a.attrelid = c.oid + JOIN pg_namespace n ON c.relnamespace = n.oid + WHERE n.nspname = 'public' + AND c.relname = source_mview + AND a.attnum > 0 + AND NOT a.attisdropped; + + IF all_cols IS NULL THEN + RAISE EXCEPTION 'No columns found for %. Make sure the materialized view exists.', source_mview; + END IF; + sql_create := format($sql$ CREATE MATERIALIZED VIEW %I AS SELECT - ABS(osm_id) AS id, - osm_id, - NULLIF(name, '') AS name, - admin_level, - NULLIF(type, '') AS type, - (ST_MaximumInscribedCircle(geometry)).center AS geometry, - NULLIF(start_date, '') AS start_date, - NULLIF(end_date, '') AS end_date, - isodatetodecimaldate(pad_date(start_date, 'start'), FALSE) AS start_decdate, - isodatetodecimaldate(pad_date(end_date, 'end'), FALSE) AS end_decdate, - ROUND(CAST(area AS numeric) / 1000000)::integer AS area_km2, %s FROM %I WHERE name IS NOT NULL AND name <> '' AND osm_id NOT IN ( SELECT osm_id FROM osm_relation_members WHERE role = 'label' - ); - $sql$, tmp_mview_name, lang_columns, input_table); + )%s; + $sql$, tmp_mview_name, all_cols, source_mview, custom_filter); -- Finalize the materialized view and its indexes PERFORM finalize_materialized_view( @@ -64,10 +90,23 @@ $$ LANGUAGE plpgsql; -- ============================================================================ -- Execute force creation of all admin boundaries centroids materialized views -- ============================================================================ -SELECT create_admin_boundaries_centroids_mview('osm_admin_areas_z0_2', 'mv_admin_boundaries_centroids_z0_2'); -SELECT create_admin_boundaries_centroids_mview('osm_admin_areas_z3_5', 'mv_admin_boundaries_centroids_z3_5'); -SELECT create_admin_boundaries_centroids_mview('osm_admin_areas_z6_7', 'mv_admin_boundaries_centroids_z6_7'); -SELECT create_admin_boundaries_centroids_mview('osm_admin_areas_z8_9', 'mv_admin_boundaries_centroids_z8_9'); -SELECT create_admin_boundaries_centroids_mview('osm_admin_areas_z10_12', 'mv_admin_boundaries_centroids_z10_12'); -SELECT create_admin_boundaries_centroids_mview('osm_admin_areas_z13_15', 'mv_admin_boundaries_centroids_z13_15'); -SELECT create_admin_boundaries_centroids_mview('osm_admin_areas_z16_20', 'mv_admin_boundaries_centroids_z16_20'); +-- Create centroids from corresponding area materialized views +-- The where_filter is no longer needed as the area views already have the appropriate filters +SELECT create_admin_boundaries_centroids_mview('mv_admin_boundaries_areas_z0_2', 'mv_admin_boundaries_centroids_z0_2', 'id, osm_id, type', NULL); +SELECT create_admin_boundaries_centroids_mview('mv_admin_boundaries_areas_z3_5', 'mv_admin_boundaries_centroids_z3_5', 'id, osm_id, type', NULL); +SELECT create_admin_boundaries_centroids_mview('mv_admin_boundaries_areas_z6_7', 'mv_admin_boundaries_centroids_z6_7', 'id, osm_id, type', NULL); +SELECT create_admin_boundaries_centroids_mview('mv_admin_boundaries_areas_z8_9', 'mv_admin_boundaries_centroids_z8_9', 'id, osm_id, type', NULL); +SELECT create_admin_boundaries_centroids_mview('mv_admin_boundaries_areas_z10_12', 'mv_admin_boundaries_centroids_z10_12', 'id, osm_id, type', NULL); +SELECT create_admin_boundaries_centroids_mview('mv_admin_boundaries_areas_z13_15', 'mv_admin_boundaries_centroids_z13_15', 'id, osm_id, type', NULL); +SELECT create_admin_boundaries_centroids_mview('mv_admin_boundaries_areas_z16_20', 'mv_admin_boundaries_centroids_z16_20', 'id, osm_id, type', NULL); + +-- Refresh centroids views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_centroids_z0_2; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_centroids_z3_5; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_centroids_z6_7; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_centroids_z8_9; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_centroids_z10_12; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_centroids_z13_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_centroids_z16_20; + + diff --git a/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_lines.sql b/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_lines.sql index 5a914599..f663bb23 100644 --- a/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_lines.sql +++ b/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_lines.sql @@ -4,31 +4,84 @@ --STEP 1: Add New Columns in osm_relation_members_boundaries and osm_admin_lines -- ============================================================================ SELECT log_notice('STEP 1: Adding new columns in osm_relation_members_boundaries and osm_admin_lines table'); -ALTER TABLE osm_relation_members_boundaries -ADD COLUMN start_decdate DOUBLE PRECISION, -ADD COLUMN end_decdate DOUBLE PRECISION; -ALTER TABLE osm_admin_lines -ADD COLUMN start_decdate DOUBLE PRECISION, -ADD COLUMN end_decdate DOUBLE PRECISION; +-- osm_relation_members_boundaries +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'osm_relation_members_boundaries' + AND column_name = 'start_decdate' + ) THEN + ALTER TABLE osm_relation_members_boundaries ADD COLUMN start_decdate DOUBLE PRECISION; + END IF; + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'osm_relation_members_boundaries' + AND column_name = 'end_decdate' + ) THEN + ALTER TABLE osm_relation_members_boundaries ADD COLUMN end_decdate DOUBLE PRECISION; + END IF; +END $$; + +-- osm_admin_lines +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'osm_admin_lines' + AND column_name = 'start_decdate' + ) THEN + ALTER TABLE osm_admin_lines ADD COLUMN start_decdate DOUBLE PRECISION; + END IF; + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'osm_admin_lines' + AND column_name = 'end_decdate' + ) THEN + ALTER TABLE osm_admin_lines ADD COLUMN end_decdate DOUBLE PRECISION; + END IF; +END $$; -- ============================================================================ -- STEP 2: Create the Trigger, which will call the function above -- ============================================================================ SELECT log_notice('STEP 2: Create trigger to convert date to decimal for new/updated objects in osm_relation_members_boundaries and osm_admin_lines table'); -CREATE TRIGGER trigger_decimal_dates_osm_relation_members_boundaries -BEFORE INSERT OR UPDATE -ON osm_relation_members_boundaries -FOR EACH ROW -EXECUTE FUNCTION convert_dates_to_decimal(); - -CREATE TRIGGER trigger_decimal_dates_osm_admin_lines -BEFORE INSERT OR UPDATE -ON osm_admin_lines -FOR EACH ROW -EXECUTE FUNCTION convert_dates_to_decimal(); +-- osm_relation_members_boundaries trigger +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM pg_trigger + WHERE tgname = 'trigger_decimal_dates_osm_relation_members_boundaries' + ) THEN + CREATE TRIGGER trigger_decimal_dates_osm_relation_members_boundaries + BEFORE INSERT OR UPDATE + ON osm_relation_members_boundaries + FOR EACH ROW + EXECUTE FUNCTION convert_dates_to_decimal(); + END IF; +END $$; + +-- osm_admin_lines trigger +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM pg_trigger + WHERE tgname = 'trigger_decimal_dates_osm_admin_lines' + ) THEN + CREATE TRIGGER trigger_decimal_dates_osm_admin_lines + BEFORE INSERT OR UPDATE + ON osm_admin_lines + FOR EACH ROW + EXECUTE FUNCTION convert_dates_to_decimal(); + END IF; +END $$; -- ============================================================================ -- STEP 3: Backfill Existing Data, Set timeout to 40 minutes (2400000 milliseconds) for the current session, this takes quite a while, sincecurrnelty thrre are ~5 million rows in the table @@ -241,165 +294,16 @@ ON mv_admin_boundaries_relations_ways USING GIST (geometry); -- ============================================================================ SELECT log_notice('STEP 6: Create a materialized view for zoom levels'); --- ========================================== --- MViews for admin lines zoom 0-2 --- ========================================== -DROP MATERIALIZED VIEW IF EXISTS mv_admin_boundaries_lines_z0_2 CASCADE; -CREATE MATERIALIZED VIEW mv_admin_boundaries_lines_z0_2 AS -SELECT - type, - admin_level, - member, - ST_SimplifyPreserveTopology(geometry, 5000) AS geometry, - group_id, - start_decdate, - end_decdate, - start_date, - end_date -FROM mv_admin_boundaries_relations_ways -WHERE admin_level IN (1,2) -WITH DATA; - -CREATE UNIQUE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z0_2_idx -ON mv_admin_boundaries_lines_z0_2 (admin_level, member, group_id); - -CREATE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z0_2_geometry_idx -ON mv_admin_boundaries_lines_z0_2 USING GIST (geometry); - --- ========================================== --- MViews for admin lines zoom 3-5 --- ========================================== -DROP MATERIALIZED VIEW IF EXISTS mv_admin_boundaries_lines_z3_5 CASCADE; -CREATE MATERIALIZED VIEW mv_admin_boundaries_lines_z3_5 AS -SELECT - type, - admin_level, - member, - ST_SimplifyPreserveTopology(geometry, 1000) AS geometry, - group_id, - start_decdate, - end_decdate, - start_date, - end_date -FROM mv_admin_boundaries_relations_ways -WHERE admin_level IN (1,2,3,4) -WITH DATA; - -CREATE UNIQUE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z3_5_idx -ON mv_admin_boundaries_lines_z3_5 (admin_level, member, group_id); - -CREATE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z3_5_geometry_idx -ON mv_admin_boundaries_lines_z3_5 USING GIST (geometry); - --- ========================================== --- MViews for admin lines zoom 6-7 --- ========================================== -DROP MATERIALIZED VIEW IF EXISTS mv_admin_boundaries_lines_z6_7 CASCADE; -CREATE MATERIALIZED VIEW mv_admin_boundaries_lines_z6_7 AS -SELECT - type, - admin_level, - member, - ST_SimplifyPreserveTopology(geometry, 200) AS geometry, - group_id, - start_decdate, - end_decdate, - start_date, - end_date -FROM mv_admin_boundaries_relations_ways -WHERE admin_level IN (1,2,3,4,5,6) -WITH DATA; - -CREATE UNIQUE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z6_7_idx -ON mv_admin_boundaries_lines_z6_7 (admin_level, member, group_id); - -CREATE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z6_7_geometry_idx -ON mv_admin_boundaries_lines_z6_7 USING GIST (geometry); - --- ========================================== --- MViews for admin lines zoom 8-9 --- ========================================== -DROP MATERIALIZED VIEW IF EXISTS mv_admin_boundaries_lines_z8_9 CASCADE; -CREATE MATERIALIZED VIEW mv_admin_boundaries_lines_z8_9 AS -SELECT - type, - admin_level, - member, - ST_SimplifyPreserveTopology(geometry, 100) AS geometry, - group_id, - start_decdate, - end_decdate, - start_date, - end_date -FROM mv_admin_boundaries_relations_ways -WHERE admin_level IN (1,2,3,4,5,6,7,8,9) -WITH DATA; - -CREATE UNIQUE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z8_9_idx -ON mv_admin_boundaries_lines_z8_9 (admin_level, member, group_id); - -CREATE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z8_9_geometry_idx -ON mv_admin_boundaries_lines_z8_9 USING GIST (geometry); - --- ========================================== --- MViews for admin lines zoom 10-12 --- ========================================== -DROP MATERIALIZED VIEW IF EXISTS mv_admin_boundaries_lines_z10_12 CASCADE; -CREATE MATERIALIZED VIEW mv_admin_boundaries_lines_z10_12 AS -SELECT - type, - admin_level, - member, - ST_SimplifyPreserveTopology(geometry, 20) AS geometry, - group_id, - start_decdate, - end_decdate, - start_date, - end_date -FROM mv_admin_boundaries_relations_ways -WHERE admin_level IN (1,2,3,4,5,6,7,8,9,10) -WITH DATA; - -CREATE UNIQUE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z10_12_idx -ON mv_admin_boundaries_lines_z10_12 (admin_level, member, group_id); - -CREATE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z10_12_geometry_idx -ON mv_admin_boundaries_lines_z10_12 USING GIST (geometry); - --- ========================================== --- MViews for admin lines zoom 13-15 --- ========================================== -DROP MATERIALIZED VIEW IF EXISTS mv_admin_boundaries_lines_z13_15 CASCADE; -CREATE MATERIALIZED VIEW mv_admin_boundaries_lines_z13_15 AS -SELECT - type, - admin_level, - member, - ST_SimplifyPreserveTopology(geometry, 5) AS geometry, - group_id, - start_decdate, - end_decdate, - start_date, - end_date -FROM mv_admin_boundaries_relations_ways -WHERE admin_level IN (1,2,3,4,5,6,7,8,9,10) -WITH DATA; - -CREATE UNIQUE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z13_15_idx -ON mv_admin_boundaries_lines_z13_15 (admin_level, member, group_id); - -CREATE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z13_15_geometry_idx -ON mv_admin_boundaries_lines_z13_15 USING GIST (geometry); - -- ========================================== -- MViews for admin lines zoom 16-20 -- ========================================== DROP MATERIALIZED VIEW IF EXISTS mv_admin_boundaries_lines_z16_20 CASCADE; CREATE MATERIALIZED VIEW mv_admin_boundaries_lines_z16_20 AS SELECT + ROW_NUMBER() OVER (ORDER BY admin_level, member, group_id) AS id, type, admin_level, - member, + member as osm_id, ST_SimplifyPreserveTopology(geometry, 1) AS geometry, group_id, start_decdate, @@ -407,11 +311,32 @@ SELECT start_date, end_date FROM mv_admin_boundaries_relations_ways -WHERE admin_level IN (1,2,3,4,5,6,7,8,9,10) +WHERE admin_level IN (1,2,3,4,5,6,7,8,9,10,11) WITH DATA; -CREATE UNIQUE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z16_20_idx -ON mv_admin_boundaries_lines_z16_20 (admin_level, member, group_id); +CREATE UNIQUE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z16_20_id_idx +ON mv_admin_boundaries_lines_z16_20 (id); + +CREATE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z16_20_admin_level_idx +ON mv_admin_boundaries_lines_z16_20 (admin_level); CREATE INDEX IF NOT EXISTS mv_admin_boundaries_lines_z16_20_geometry_idx ON mv_admin_boundaries_lines_z16_20 USING GIST (geometry); + +SELECT create_mview_line_from_mview('mv_admin_boundaries_lines_z16_20', 'mv_admin_boundaries_lines_z13_15', 5, 'admin_level IN (1,2,3,4,5,6,7,8,9,10)'); +SELECT create_mview_line_from_mview('mv_admin_boundaries_lines_z13_15', 'mv_admin_boundaries_lines_z10_12', 20, NULL); +SELECT create_mview_line_from_mview('mv_admin_boundaries_lines_z10_12', 'mv_admin_boundaries_lines_z8_9', 100, 'admin_level IN (1,2,3,4,5,6,7,8,9)'); +SELECT create_mview_line_from_mview('mv_admin_boundaries_lines_z8_9', 'mv_admin_boundaries_lines_z6_7', 200, 'admin_level IN (1,2,3,4,5,6)'); +SELECT create_mview_line_from_mview('mv_admin_boundaries_lines_z6_7', 'mv_admin_boundaries_lines_z3_5', 1000, 'admin_level IN (1,2,3,4)'); +SELECT create_mview_line_from_mview('mv_admin_boundaries_lines_z3_5', 'mv_admin_boundaries_lines_z0_2', 5000, 'admin_level IN (1,2)'); + +-- Refresh lines views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_relation_members_boundaries; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_relations_ways; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_lines_z16_20; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_lines_z13_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_lines_z10_12; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_lines_z8_9; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_lines_z6_7; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_lines_z3_5; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_boundaries_lines_z0_2; diff --git a/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_maritime.sql b/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_maritime.sql index af0c7b22..c75007de 100644 --- a/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_maritime.sql +++ b/images/tiler-imposm/queries/ohm_mviews/admin_boundaries_maritime.sql @@ -1,21 +1,34 @@ -- ============================================================================ -- Create materialized views for maritime admin boundaries -- ============================================================================ -SELECT create_generic_mview( - 'osm_admin_lines_z0_5', - 'mv_admin_maritime_lines_z0_5', - ARRAY ['osm_id', 'type'] - ); +SELECT create_lines_mview( + 'osm_admin_lines', + 'mv_admin_maritime_lines_z0_5_v2', + 2000, + 0, + 'id, osm_id, type', + 'maritime = ''yes''' +); -SELECT create_generic_mview( - 'osm_admin_lines_z6_9', +SELECT create_lines_mview( + 'osm_admin_lines', 'mv_admin_maritime_lines_z6_9', - ARRAY ['osm_id', 'type'] + 500, + 0, + 'id, osm_id, type', + 'maritime = ''yes''' ); -SELECT create_generic_mview( - 'osm_admin_lines_z10_15', +SELECT create_lines_mview( + 'osm_admin_lines', 'mv_admin_maritime_lines_z10_15', - ARRAY ['osm_id', 'type'] + 10, + 0, + 'id, osm_id, type', + 'maritime = ''yes''' ); - \ No newline at end of file + +-- Refresh maritime lines views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_maritime_lines_z0_5_v2; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_maritime_lines_z6_9; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_admin_maritime_lines_z10_15; diff --git a/images/tiler-imposm/queries/ohm_mviews/amenity.sql b/images/tiler-imposm/queries/ohm_mviews/amenity.sql index dfeee3a7..896c195d 100644 --- a/images/tiler-imposm/queries/ohm_mviews/amenity.sql +++ b/images/tiler-imposm/queries/ohm_mviews/amenity.sql @@ -43,3 +43,11 @@ SELECT create_points_centroids_mview( 'mv_amenity_points_centroids_z16_20', 'mv_amenity_points' ); + +-- Refresh areas views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_amenity_areas_z14_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_amenity_areas_z16_20; + +-- Refresh centroids views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_amenity_points_centroids_z14_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_amenity_points_centroids_z16_20; diff --git a/images/tiler-imposm/queries/ohm_mviews/buildings.sql b/images/tiler-imposm/queries/ohm_mviews/buildings.sql index 1207724b..40039f51 100644 --- a/images/tiler-imposm/queries/ohm_mviews/buildings.sql +++ b/images/tiler-imposm/queries/ohm_mviews/buildings.sql @@ -51,3 +51,11 @@ SELECT create_points_centroids_mview( 'mv_buildings_points_centroids_z16_20', 'mv_buildings_points' ); + +-- Refresh areas views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_buildings_areas_z14_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_buildings_areas_z16_20; + +-- Refresh centroids views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_buildings_points_centroids_z14_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_buildings_points_centroids_z16_20; diff --git a/images/tiler-imposm/queries/ohm_mviews/landuse.sql b/images/tiler-imposm/queries/ohm_mviews/landuse.sql index d480f6b4..047a0633 100644 --- a/images/tiler-imposm/queries/ohm_mviews/landuse.sql +++ b/images/tiler-imposm/queries/ohm_mviews/landuse.sql @@ -1,172 +1,37 @@ --- Create materialized views for landuse areas with different simplification levels --- Using the generalized create_areas_mview function -- ============================================================================ --- Zoom 3-5: --- High simplification (200m) --- Large areas only (>50M m² = 50 km²) --- Exclude water areas and natural areas, which are handled by the water_areas view --- Create centroids view from simplified areas (no points at this zoom level) --- ============================================================================ --- SELECT create_areas_mview( --- 'osm_landuse_areas', --- 'mv_landuse_areas_z3_5', --- 200, --- 50000000, --- 'id, osm_id, type', --- 'NOT (type = ''water'' AND class = ''natural'')' --- ); --- SELECT create_points_centroids_mview( --- 'mv_landuse_areas_z3_5', --- 'mv_landuse_points_centroids_z3_5', --- NULL --- ); - --- ============================================================================ --- Zoom 6-7: --- Medium-high simplification (100m) --- Medium-large areas (>10M m² = 10 km²) --- Exclude water areas and natural areas, which are handled by the water_areas view +-- Landuse Areas +-- Create landuse areas materialized views with simplification and filtering -- Exclude natrual=water https://github.com/OpenHistoricalMap/issues/issues/1197 -- ============================================================================ -SELECT create_areas_mview( - 'osm_landuse_areas', - 'mv_landuse_areas_z6_7', - 100, - 10000000, - 'id, osm_id, type', - 'NOT (type = ''water'' AND class = ''natural'')' -); -SELECT create_points_centroids_mview( - 'mv_landuse_areas_z6_7', - 'mv_landuse_points_centroids_z6_7', - NULL -); +DROP MATERIALIZED VIEW IF EXISTS mv_landuse_areas_z16_20 CASCADE; --- ============================================================================ --- Zoom 8-9: --- Medium simplification (50m) --- Medium areas (>1M m² = 1 km²) --- Exclude water areas and natural areas, which are handled by the water_areas view --- Exclude natrual=water https://github.com/OpenHistoricalMap/issues/issues/1197 --- ============================================================================ -SELECT create_areas_mview( - 'osm_landuse_areas', - 'mv_landuse_areas_z8_9', - 50, - 1000000, - 'id, osm_id, type', - 'NOT (type = ''water'' AND class = ''natural'')' -); -SELECT create_points_centroids_mview( - 'mv_landuse_areas_z8_9', - 'mv_landuse_points_centroids_z8_9', - NULL -); --- ============================================================================ --- Zoom 10-11: --- Medium-low simplification (15m) --- Medium areas (>50K m² = 0.05 km²) --- Exclude water areas and natural areas, which are handled by the water_areas view --- Exclude natrual=water https://github.com/OpenHistoricalMap/issues/issues/1197 --- ============================================================================ -SELECT create_areas_mview( - 'osm_landuse_areas', - 'mv_landuse_areas_z10_11', - 15, - 50000, - 'id, osm_id, type', - 'NOT (type = ''water'' AND class = ''natural'')' -); -SELECT create_points_centroids_mview( - 'mv_landuse_areas_z10_11', - 'mv_landuse_points_centroids_z10_11', - NULL -); +SELECT create_areas_mview( 'osm_landuse_areas', 'mv_landuse_areas_z16_20', 0, 0, 'id, osm_id, type', 'NOT (type = ''water'' AND class = ''natural'')'); +SELECT create_area_mview_from_mview('mv_landuse_areas_z16_20', 'mv_landuse_areas_z13_15', 5, 10000, NULL); +SELECT create_area_mview_from_mview('mv_landuse_areas_z13_15', 'mv_landuse_areas_z10_12', 20, 50000, NULL); +SELECT create_area_mview_from_mview('mv_landuse_areas_z10_12', 'mv_landuse_areas_z8_9', 100, 1000000, NULL); +SELECT create_area_mview_from_mview('mv_landuse_areas_z8_9', 'mv_landuse_areas_z6_7', 200, 10000000, NULL); -- ============================================================================ --- Prepare points materialized view for higher zoom levels (12+) --- ============================================================================ --- Prepare points table with necessary columns (start_decdate, end_decdate, area_m2, area_km2, etc.) --- This must be done before creating centroids views that include points -SELECT create_points_mview( - 'osm_landuse_points', - 'mv_landuse_points' -); - - --- ============================================================================ --- Zoom 12-13: --- Low simplification (10m) --- Small areas (>10K m² = 0.01 km²) --- Exclude water areas and natural areas, which are handled by the water_areas view --- Include landuse points --- ============================================================================ -SELECT create_areas_mview( - 'osm_landuse_areas', - 'mv_landuse_areas_z12_13', - 10, - 10000, - 'id, osm_id, type', - 'NOT (type = ''water'' AND class = ''natural'')' -); -SELECT create_points_centroids_mview( - 'mv_landuse_areas_z12_13', - 'mv_landuse_points_centroids_z12_13', - 'mv_landuse_points' -); - - --- ============================================================================ --- Zoom 14-15: --- Very low simplification (5m) --- Very small areas (>5K m² = 0.005 km²) --- Exclude water areas and natural areas, which are handled by the water_areas view --- Include landuse points --- ============================================================================ -SELECT create_areas_mview( - 'osm_landuse_areas', - 'mv_landuse_areas_z14_15', - 5, - 5000, - 'id, osm_id, type', - 'NOT (type = ''water'' AND class = ''natural'')' -); -SELECT create_points_centroids_mview( - 'mv_landuse_areas_z14_15', - 'mv_landuse_points_centroids_z14_15', - 'mv_landuse_points' -); - --- ============================================================================ --- Zoom 16-20: --- No simplification --- All areas --- Exclude water areas and natural areas, which are handled by the water_areas view --- Include landuse points +-- Landuse centroids +-- Create points materialized view to add laater with centroids +-- Exclude natrual=water https://github.com/OpenHistoricalMap/issues/issues/1197 -- ============================================================================ -SELECT create_areas_mview( - 'osm_landuse_areas', - 'mv_landuse_areas_z16_20', - 0, - 0, - 'id, osm_id, type', - 'NOT (type = ''water'' AND class = ''natural'')' -); -SELECT create_points_centroids_mview( - 'mv_landuse_areas_z16_20', - 'mv_landuse_points_centroids_z16_20', - 'mv_landuse_points' -); +SELECT create_points_mview('osm_landuse_points','mv_landuse_points' ); +-- Create points centroids materialized views, add points only for higher zoom levels +SELECT create_points_centroids_mview('mv_landuse_areas_z16_20','mv_landuse_points_centroids_z16_20','mv_landuse_points'); +SELECT create_points_centroids_mview( 'mv_landuse_areas_z13_15', 'mv_landuse_points_centroids_z13_15', 'mv_landuse_points'); +SELECT create_points_centroids_mview( 'mv_landuse_areas_z10_12', 'mv_landuse_points_centroids_z10_12', NULL); +SELECT create_points_centroids_mview( 'mv_landuse_areas_z8_9', 'mv_landuse_points_centroids_z8_9', NULL); +SELECT create_points_centroids_mview( 'mv_landuse_areas_z6_7', 'mv_landuse_points_centroids_z6_7', NULL); -- ============================================================================ --- Create materialized views for landuse lines +-- Landuse lines +-- Create materialized views for landuse lines, +-- Only tree_row type is used in the map style -- ============================================================================ -SELECT create_generic_mview( - 'osm_landuse_lines', - 'mv_landuse_lines_z14_20', - ARRAY['osm_id', 'type', 'class'] -); +SELECT create_lines_mview('osm_landuse_lines', 'mv_landuse_lines_z16_20', 5, 0, 'id, osm_id, type', 'type IN (''tree_row'')'); +SELECT create_mview_line_from_mview('mv_landuse_lines_z16_20', 'mv_landuse_lines_z14_15', 5, NULL); diff --git a/images/tiler-imposm/queries/ohm_mviews/others.sql b/images/tiler-imposm/queries/ohm_mviews/others.sql index 9dff4006..e78fded9 100644 --- a/images/tiler-imposm/queries/ohm_mviews/others.sql +++ b/images/tiler-imposm/queries/ohm_mviews/others.sql @@ -9,7 +9,7 @@ SELECT create_areas_mview( 'osm_other_areas', 'mv_other_areas_z8_9', - 50, + 100, 1000000, 'id, osm_id, type', NULL @@ -21,21 +21,19 @@ SELECT create_points_centroids_mview( ); -- ============================================================================ --- Zoom 10-11: --- Medium-low simplification (15m) --- Medium areas (>50K m² = 0.05 km²) +-- Zoom 10-12 -- ============================================================================ SELECT create_areas_mview( 'osm_other_areas', - 'mv_other_areas_z10_11', - 15, + 'mv_other_areas_z10_12', + 20, 50000, 'id, osm_id, type', NULL ); SELECT create_points_centroids_mview( - 'mv_other_areas_z10_11', - 'mv_other_points_centroids_z10_11', + 'mv_other_areas_z10_12', + 'mv_other_points_centroids_z10_12', NULL ); @@ -49,43 +47,21 @@ SELECT create_points_mview( 'mv_other_points' ); --- ============================================================================ --- Zoom 12-13: --- Low simplification (10m) --- Small areas (>10K m² = 0.01 km²) --- Include other points --- ============================================================================ -SELECT create_areas_mview( - 'osm_other_areas', - 'mv_other_areas_z12_13', - 10, - 10000, - 'id, osm_id, type', - NULL -); -SELECT create_points_centroids_mview( - 'mv_other_areas_z12_13', - 'mv_other_points_centroids_z12_13', - 'mv_other_points' -); -- ============================================================================ --- Zoom 14-15: --- Very low simplification (5m) --- Very small areas (>5K m² = 0.005 km²) --- Include other points +-- Zoom 13-15: -- ============================================================================ SELECT create_areas_mview( 'osm_other_areas', - 'mv_other_areas_z14_15', + 'mv_other_areas_z13_15', 5, 5000, 'id, osm_id, type', NULL ); SELECT create_points_centroids_mview( - 'mv_other_areas_z14_15', - 'mv_other_points_centroids_z14_15', + 'mv_other_areas_z13_15', + 'mv_other_points_centroids_z13_15', 'mv_other_points' ); @@ -112,4 +88,22 @@ SELECT create_points_centroids_mview( -- ============================================================================ -- Create materialized views for other lines -- ============================================================================ -SELECT create_generic_mview('osm_other_lines', 'mv_other_lines_z14_20', ARRAY['osm_id', 'type', 'class']); \ No newline at end of file +SELECT create_lines_mview('osm_other_lines', 'mv_other_lines_z16_20', 0, 0, 'id, osm_id, type'); +SELECT create_mview_line_from_mview('mv_other_lines_z16_20', 'mv_other_lines_z14_15', 5); + +-- Refresh areas views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_other_areas_z8_9; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_other_areas_z10_12; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_other_areas_z13_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_other_areas_z16_20; + +-- Refresh centroids views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_other_points_centroids_z8_9; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_other_points_centroids_z10_12; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_other_points_centroids_z13_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_other_points_centroids_z16_20; + +-- Refresh lines views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_other_lines_z16_20; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_other_lines_z14_15; + diff --git a/images/tiler-imposm/queries/ohm_mviews/places.sql b/images/tiler-imposm/queries/ohm_mviews/places.sql index 98c48191..5091f060 100644 --- a/images/tiler-imposm/queries/ohm_mviews/places.sql +++ b/images/tiler-imposm/queries/ohm_mviews/places.sql @@ -206,3 +206,12 @@ SELECT create_place_areas_mview( 'mv_place_areas_z14_20', ARRAY['plot', 'square', 'islet'] ); + +-- Refresh centroids views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_place_points_centroids_z0_2; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_place_points_centroids_z3_5; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_place_points_centroids_z6_10; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_place_points_centroids_z11_20; + +-- Refresh areas views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_place_areas_z14_20; diff --git a/images/tiler-imposm/queries/ohm_mviews/routes_01_merge_by_date.sql b/images/tiler-imposm/queries/ohm_mviews/routes_01_merge_by_date.sql index 7bd5000f..3fb83c60 100644 --- a/images/tiler-imposm/queries/ohm_mviews/routes_01_merge_by_date.sql +++ b/images/tiler-imposm/queries/ohm_mviews/routes_01_merge_by_date.sql @@ -1,18 +1,52 @@ -- ============================================================================ --- STEP 1: Add New Columns +-- STEP 1: Add New Columns (only if they don't exist) -- ============================================================================ --- osm_route_multilines SELECT log_notice('STEP 1: Adding new columns in osm_route_multilines table'); -ALTER TABLE osm_route_multilines -ADD COLUMN start_decdate DOUBLE PRECISION, -ADD COLUMN end_decdate DOUBLE PRECISION; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'osm_route_multilines' + AND column_name = 'start_decdate' + ) THEN + ALTER TABLE osm_route_multilines ADD COLUMN start_decdate DOUBLE PRECISION; + END IF; + + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'osm_route_multilines' + AND column_name = 'end_decdate' + ) THEN + ALTER TABLE osm_route_multilines ADD COLUMN end_decdate DOUBLE PRECISION; + END IF; +END $$; --- osm_route_lines SELECT log_notice('STEP 1: Adding new columns in osm_route_lines table'); -ALTER TABLE osm_route_lines -ADD COLUMN start_decdate DOUBLE PRECISION, -ADD COLUMN end_decdate DOUBLE PRECISION; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'osm_route_lines' + AND column_name = 'start_decdate' + ) THEN + ALTER TABLE osm_route_lines ADD COLUMN start_decdate DOUBLE PRECISION; + END IF; + + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'osm_route_lines' + AND column_name = 'end_decdate' + ) THEN + ALTER TABLE osm_route_lines ADD COLUMN end_decdate DOUBLE PRECISION; + END IF; +END $$; -- ============================================================================ @@ -21,18 +55,34 @@ ADD COLUMN end_decdate DOUBLE PRECISION; -- ============================================================================ --- osm_route_multilines -CREATE TRIGGER trigger_decimal_dates_osm_route_multilines -BEFORE INSERT OR UPDATE -ON osm_route_multilines -FOR EACH ROW -EXECUTE FUNCTION convert_dates_to_decimal(); +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM pg_trigger + WHERE tgname = 'trigger_decimal_dates_osm_route_multilines' + ) THEN + CREATE TRIGGER trigger_decimal_dates_osm_route_multilines + BEFORE INSERT OR UPDATE + ON osm_route_multilines + FOR EACH ROW + EXECUTE FUNCTION convert_dates_to_decimal(); + END IF; +END $$; --- osm_route_lines -CREATE TRIGGER trigger_decimal_dates_osm_route_lines -BEFORE INSERT OR UPDATE -ON osm_route_lines -FOR EACH ROW -EXECUTE FUNCTION convert_dates_to_decimal(); +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM pg_trigger + WHERE tgname = 'trigger_decimal_dates_osm_route_lines' + ) THEN + CREATE TRIGGER trigger_decimal_dates_osm_route_lines + BEFORE INSERT OR UPDATE + ON osm_route_lines + FOR EACH ROW + EXECUTE FUNCTION convert_dates_to_decimal(); + END IF; +END $$; -- ============================================================================ diff --git a/images/tiler-imposm/queries/ohm_mviews/routes_03_mv.sql b/images/tiler-imposm/queries/ohm_mviews/routes_03_mv.sql index a55d0a2d..eae44b8c 100644 --- a/images/tiler-imposm/queries/ohm_mviews/routes_03_mv.sql +++ b/images/tiler-imposm/queries/ohm_mviews/routes_03_mv.sql @@ -2,25 +2,25 @@ -- FUNCTION: create_mv_routes_by_length -- ============================================================================ -- Purpose: --- Creates a materialized view filtered by minimum geometry length and --- optionally simplified geometry, based on the source view mv_routes_indexed. +-- Creates a materialized view with optionally simplified geometry, +-- based on the source view mv_routes_indexed. -- -- Includes all route_* columns generated in mv_routes_indexed -- (up to 6 slots per type: road, train, subway, light_rail, tram, trolleybus, bus), -- applying NULLIF(..., '') to avoid empty string values. -- -- Automatically creates: +-- - Sequential ID column (ROW_NUMBER) -- - Unique index on (osm_id, start_decdate, end_decdate) -- - Spatial GIST index on the geometry column -- -- Parameters: -- full_view_name TEXT - Name of the new materialized view --- min_length DOUBLE PRECISION - Minimum geometry length (ST_Length filter) -- simplify_tol DOUBLE PRECISION - Simplification tolerance (ST_Simplify) -- -- Typical usage: --- SELECT create_mv_routes_by_length('mv_routes_indexed_z5_6', 500, 500); --- SELECT create_mv_routes_by_length('mv_routes_indexed_z11_13', 1, 50); +-- SELECT create_mv_routes_by_length('mv_routes_indexed_z5_6', 500); +-- SELECT create_mv_routes_by_length('mv_routes_indexed_z11_13', 50); -- -- Notes: -- - mv_routes_indexed must exist before calling this function. @@ -31,7 +31,6 @@ DROP MATERIALIZED VIEW IF EXISTS create_mv_routes_by_length CASCADE; CREATE OR REPLACE FUNCTION create_mv_routes_by_length( full_view_name TEXT, - min_length DOUBLE PRECISION, simplify_tol DOUBLE PRECISION ) RETURNS void AS $$ DECLARE @@ -42,6 +41,7 @@ BEGIN CREATE MATERIALIZED VIEW %I AS SELECT + ROW_NUMBER() OVER (ORDER BY way_id, min_start_decdate, max_end_decdate) AS id, way_id AS osm_id, min_start_decdate AS start_decdate, max_end_decdate AS end_decdate, @@ -364,7 +364,6 @@ BEGIN NULLIF(route_bus_6_direction, '') AS route_bus_6_direction FROM mv_routes_indexed - WHERE ST_Length(geometry) > %s WITH DATA; -- Índice único (con todas las columnas *_ref) @@ -381,7 +380,6 @@ BEGIN $f$, full_view_name, full_view_name, simplify_tol::text, simplify_tol::text, - min_length::text, full_view_name, full_view_name, full_view_name, full_view_name ); @@ -393,14 +391,27 @@ END; $$ LANGUAGE plpgsql; -SELECT create_mv_routes_by_length('mv_routes_indexed_z5_6', 500, 100); -SELECT create_mv_routes_by_length('mv_routes_indexed_z7_8', 200, 50); -SELECT create_mv_routes_by_length('mv_routes_indexed_z9_10', 100, 20); -SELECT create_mv_routes_by_length('mv_routes_indexed_z11_13', 1, 5); -SELECT create_mv_routes_by_length('mv_routes_indexed_z14_20', 0, 0); --- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_routes_indexed_z5_6; --- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_routes_indexed_z7_8; --- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_routes_indexed_z9_10; --- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_routes_indexed_z11_13; --- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_routes_indexed_z14_20; +DROP MATERIALIZED VIEW IF EXISTS mv_routes_indexed_z16_20 CASCADE; + +SELECT create_mv_routes_by_length('mv_routes_indexed_z16_20', 0); +SELECT create_mview_line_from_mview('mv_routes_indexed_z16_20', 'mv_routes_indexed_z13_15', 5, NULL); +SELECT create_mview_line_from_mview('mv_routes_indexed_z13_15', 'mv_routes_indexed_z10_12', 20, NULL); +SELECT create_mview_line_from_mview('mv_routes_indexed_z10_12', 'mv_routes_indexed_z8_9', 100, NULL); +SELECT create_mview_line_from_mview('mv_routes_indexed_z8_9', 'mv_routes_indexed_z6_7', 200, NULL); +SELECT create_mview_line_from_mview('mv_routes_indexed_z6_7', 'mv_routes_indexed_z5', 1000, NULL); + +-- SELECT create_mv_routes_by_length('mv_routes_indexed_z5', 1000); +-- SELECT create_mv_routes_by_length('mv_routes_indexed_z6_7', 200); +-- SELECT create_mv_routes_by_length('mv_routes_indexed_z8_9', 100); +-- SELECT create_mv_routes_by_length('mv_routes_indexed_z10_12', 20); +-- SELECT create_mv_routes_by_length('mv_routes_indexed_z13_15', 5); +-- SELECT create_mv_routes_by_length('mv_routes_indexed_z16_20', 0); + +-- Refresh routes views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_routes_indexed_z5; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_routes_indexed_z6_7; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_routes_indexed_z8_9; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_routes_indexed_z10_12; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_routes_indexed_z13_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_routes_indexed_z16_20; diff --git a/images/tiler-imposm/queries/ohm_mviews/transport_areas.sql b/images/tiler-imposm/queries/ohm_mviews/transport_areas.sql index 3d512316..d2ac2998 100644 --- a/images/tiler-imposm/queries/ohm_mviews/transport_areas.sql +++ b/images/tiler-imposm/queries/ohm_mviews/transport_areas.sql @@ -1,85 +1,9 @@ --- ============================================================================ --- Zoom 10-11: --- Medium-low simplification (15m) --- Medium areas (>50K m² = 0.05 km²) --- We include aerodrome to start at zoom 10 from https://github.com/OpenHistoricalMap/issues/issues/1083 --- From https://github.com/OpenHistoricalMap/issues/issues/1141 add 'apron', 'terminal' --- ============================================================================ -SELECT create_areas_mview( - 'osm_transport_areas', - 'mv_transport_areas_z10_11', - 15, - 50000, - 'id, osm_id, type', - 'type in (''aerodrome'', ''apron'', ''terminal'')' -); - -SELECT create_points_centroids_mview( - 'mv_transport_areas_z10_11', - 'mv_transport_points_centroids_z10_11', - NULL -); - --- ============================================================================ --- Prepare points materialized view for higher zoom levels (12+) --- ============================================================================ --- Prepare points table with necessary columns (start_decdate, end_decdate, area_m2, area_km2, etc.) --- This must be done before creating centroids views that include points -SELECT create_points_mview( - 'osm_transport_points', - 'mv_transport_points' -); - --- ============================================================================ --- Zoom 12-13: --- Low simplification (10m) --- Small areas (>10K m² = 0.01 km²) --- Include other points --- Exclude closed highways from https://github.com/OpenHistoricalMap/issues/issues/1194 --- ============================================================================ -SELECT create_areas_mview( - 'osm_transport_areas', - 'mv_transport_areas_z12_13', - 10, - 10000, - 'id, osm_id, type', - 'NOT (class = ''highway'' AND type IN (''motorway'', ''motorway_link'', ''trunk'', ''trunk_link'', ''primary'', ''primary_link'', ''secondary'', ''secondary_link'', ''tertiary'', ''tertiary_link'', ''unclassified'', ''residential'', ''service'', ''living_street'', ''cycleway'', ''bridleway''))' -); -SELECT create_points_centroids_mview( - 'mv_transport_areas_z12_13', - 'mv_transport_points_centroids_z12_13', - 'mv_transport_points' -); - --- ============================================================================ --- Zoom 14-15: --- Very low simplification (5m) --- Very small areas (>5K m² = 0.005 km²) --- Include transport points +-- Create areas materialized views -- Exclude closed highways from https://github.com/OpenHistoricalMap/issues/issues/1194 --- ============================================================================ -SELECT create_areas_mview( - 'osm_transport_areas', - 'mv_transport_areas_z14_15', - 5, - 5000, - 'id, osm_id, type', - 'NOT (class = ''highway'' AND type IN (''motorway'', ''motorway_link'', ''trunk'', ''trunk_link'', ''primary'', ''primary_link'', ''secondary'', ''secondary_link'', ''tertiary'', ''tertiary_link'', ''unclassified'', ''residential'', ''service'', ''living_street'', ''cycleway'', ''bridleway''))' -); -SELECT create_points_centroids_mview( - 'mv_transport_areas_z14_15', - 'mv_transport_points_centroids_z14_15', - 'mv_transport_points' -); +-- -- We include aerodrome to start at zoom 10 from https://github.com/OpenHistoricalMap/issues/issues/1083 +-- -- From https://github.com/OpenHistoricalMap/issues/issues/1141 add 'apron', 'terminal' +DROP MATERIALIZED VIEW IF EXISTS mv_transport_areas_z16_20 CASCADE; --- ============================================================================ --- Zoom 16-20: --- No simplification --- All areas --- Include transport points --- Exclude closed highways from https://github.com/OpenHistoricalMap/issues/issues/1194 - --- ============================================================================ SELECT create_areas_mview( 'osm_transport_areas', 'mv_transport_areas_z16_20', @@ -88,8 +12,21 @@ SELECT create_areas_mview( 'id, osm_id, type', 'NOT (class = ''highway'' AND type IN (''motorway'', ''motorway_link'', ''trunk'', ''trunk_link'', ''primary'', ''primary_link'', ''secondary'', ''secondary_link'', ''tertiary'', ''tertiary_link'', ''unclassified'', ''residential'', ''service'', ''living_street'', ''cycleway'', ''bridleway''))' ); -SELECT create_points_centroids_mview( - 'mv_transport_areas_z16_20', - 'mv_transport_points_centroids_z16_20', - 'mv_transport_points' -); +SELECT create_area_mview_from_mview('mv_transport_areas_z16_20','mv_transport_areas_z13_15',5,0.0,NULL); +SELECT create_area_mview_from_mview('mv_transport_areas_z13_15','mv_transport_areas_z10_12',20,100, 'type IN (''aerodrome'', ''apron'', ''terminal'')'); + +-- Create points materialized view and centroids views +SELECT create_points_mview('osm_transport_points', 'mv_transport_points'); +SELECT create_points_centroids_mview('mv_transport_areas_z16_20', 'mv_transport_points_centroids_z16_20', 'mv_transport_points'); +SELECT create_points_centroids_mview('mv_transport_areas_z13_15', 'mv_transport_points_centroids_z13_15', 'mv_transport_points'); +SELECT create_points_centroids_mview('mv_transport_areas_z10_12', 'mv_transport_points_centroids_z10_12', NULL); + +-- Refresh areas views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_transport_areas_z16_20; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_transport_areas_z13_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_transport_areas_z10_12; + +-- Refresh centroids views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_transport_points_centroids_z10_12; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_transport_points_centroids_z13_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_transport_points_centroids_z16_20; diff --git a/images/tiler-imposm/queries/ohm_mviews/transport_lines.sql b/images/tiler-imposm/queries/ohm_mviews/transport_lines.sql index 79ccd400..079e5b9c 100644 --- a/images/tiler-imposm/queries/ohm_mviews/transport_lines.sql +++ b/images/tiler-imposm/queries/ohm_mviews/transport_lines.sql @@ -164,11 +164,20 @@ $$ LANGUAGE plpgsql; -- ============================================================================ -- Create materialized views for transport lines -- ============================================================================ -SELECT create_transport_lines_mview('mv_transport_lines_z5', 1000, ARRAY['motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'rail'], ARRAY['railway']); -SELECT create_transport_lines_mview('mv_transport_lines_z6', 500, ARRAY['motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'rail'], ARRAY['railway']); -SELECT create_transport_lines_mview('mv_transport_lines_z7', 300, ARRAY['motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'rail'], ARRAY['railway']); -SELECT create_transport_lines_mview('mv_transport_lines_z8', 200, ARRAY['motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'rail', 'secondary', 'secondary_link'], ARRAY['railway']); -SELECT create_transport_lines_mview('mv_transport_lines_z9', 100, ARRAY['motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'rail', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link'], ARRAY['railway']); -SELECT create_transport_lines_mview('mv_transport_lines_z10_11', 80, ARRAY['motorway', 'motorway_link', 'trunk', 'trunk_link', 'construction', 'primary', 'primary_link', 'rail', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link', 'taxiway', 'runway'], ARRAY['railway']); -SELECT create_transport_lines_mview('mv_transport_lines_z12_13', 50, ARRAY['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'], ARRAY['railway']); -SELECT create_transport_lines_mview('mv_transport_lines_z14_20', 0, ARRAY['*'], ARRAY['railway','route']); +DROP MATERIALIZED VIEW IF EXISTS mv_transport_lines_z16_20 CASCADE; +SELECT create_transport_lines_mview('mv_transport_lines_z16_20', 0, ARRAY['*'], ARRAY['railway','route']); +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'')'); +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'')'); +SELECT create_mview_line_from_mview('mv_transport_lines_z10_12', 'mv_transport_lines_z8_9', 100, NULL); +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'')'); +SELECT create_mview_line_from_mview('mv_transport_lines_z6_7', 'mv_transport_lines_z5', 1000 , NULL); + + + +-- Refresh lines views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_transport_lines_z5; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_transport_lines_z6_7; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_transport_lines_z8_9; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_transport_lines_z10_12; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_transport_lines_z13_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_transport_lines_z16_20; diff --git a/images/tiler-imposm/queries/ohm_mviews/water.sql b/images/tiler-imposm/queries/ohm_mviews/water.sql index 3868ca87..fc25d4a6 100644 --- a/images/tiler-imposm/queries/ohm_mviews/water.sql +++ b/images/tiler-imposm/queries/ohm_mviews/water.sql @@ -1,168 +1,54 @@ -- ============================================================================ --- Function: create_water_areas_subdivided_mview --- Description: --- Creates a materialized view for water areas using ST_Subdivide to simplify --- complex geometries. The input geometries are validated with ST_MakeValid and --- dumped using ST_Dump to extract components. --- --- Multilingual name columns are added dynamically from the `languages` table. --- --- Parameters: --- input_table TEXT - The source table containing raw geometries. --- mview_name TEXT - The name of the materialized view to be created. --- --- Behavior: --- - Uses a temporary view during creation to avoid downtime. --- - Only valid POLYGON and MULTIPOLYGON geometries are retained. --- - Adds GiST spatial index on geometry and unique index on (id). +-- Water Areas Materialized Views for Multiple Zoom Levels +-- Creates a pyramid of materialized views for water areas, optimized for -- ============================================================================ -DROP FUNCTION IF EXISTS create_water_areas_subdivided_mview; -CREATE OR REPLACE FUNCTION create_water_areas_subdivided_mview( - input_table TEXT, - mview_name TEXT -) -RETURNS void AS $$ -DECLARE - lang_columns TEXT := get_language_columns(); - tmp_view_name TEXT := mview_name || '_tmp'; - sql_create TEXT; - unique_columns TEXT := 'id'; -BEGIN - sql_create := format($sql$ - CREATE MATERIALIZED VIEW %I AS - SELECT - row_number() OVER () AS id, - geometry, - osm_id, - NULLIF(name, '') AS name, - NULLIF(type, '') AS type, - NULLIF(start_date, '') AS start_date, - NULLIF(end_date, '') AS end_date, - isodatetodecimaldate(pad_date(start_date, 'start'), FALSE) AS start_decdate, - isodatetodecimaldate(pad_date(end_date, 'end'), FALSE) AS end_decdate, - area, - %s - FROM ( - SELECT - ST_Subdivide((g).geom, 512) AS geometry, - osm_id, - name, - type, - start_date, - end_date, - area, - tags, - %s - FROM ( - SELECT - osm_id, - name, - type, - start_date, - end_date, - area, - ST_Dump(ST_MakeValid(geometry)) AS g, - tags, - %s - FROM %I - WHERE geometry IS NOT NULL - ) AS fixed_geoms - WHERE GeometryType((g).geom) IN ('POLYGON', 'MULTIPOLYGON') - ) AS final_data; - $sql$, tmp_view_name, lang_columns, lang_columns, lang_columns, input_table); +-- Delete existing views, in cascade +DROP MATERIALIZED VIEW IF EXISTS mv_water_areas_z16_20 CASCADE; - PERFORM finalize_materialized_view( - tmp_view_name, - mview_name, - unique_columns, - sql_create - ); -END; -$$ LANGUAGE plpgsql; +SELECT create_areas_mview('osm_water_areas','mv_water_areas_z16_20',0,0,'id, osm_id, type'); +SELECT create_area_mview_from_mview('mv_water_areas_z16_20','mv_water_areas_z13_15',5,0.0,NULL); +SELECT create_area_mview_from_mview('mv_water_areas_z13_15','mv_water_areas_z10_12',20,100, 'type IN (''water'',''pond'',''basin'',''canal'',''mill_pond'',''riverbank'')'); +SELECT create_area_mview_from_mview('mv_water_areas_z10_12','mv_water_areas_z8_9',100,10000, NULL); +SELECT create_area_mview_from_mview('mv_water_areas_z8_9','mv_water_areas_z6_7',200,1000000, NULL); +SELECT create_area_mview_from_mview('mv_water_areas_z6_7','mv_water_areas_z3_5',1000,50000000, NULL); +SELECT create_area_mview_from_mview('mv_water_areas_z3_5','mv_water_areas_z0_2',5000,100000000, 'type IN (''water'',''riverbank'')'); -- ============================================================================ --- Function: create_water_areas_centroids_mview --- Description: --- This function creates a materialized view with centroids for named water areas. --- It uses ST_MaximumInscribedCircle to compute a representative centroid from --- each polygonal feature. The function can be called per zoom level using different source tables. --- --- Parameters: --- source_table TEXT - Source table containing water area polygons. --- view_name TEXT - Name of the resulting materialized view. --- --- Notes: --- - Only features with non-empty names are included. --- - Geometry is computed as the center of the maximum inscribed circle. --- - A GiST index is created on geometry, and uniqueness is enforced on osm_id. --- - Uses a temporary view to avoid downtime during refresh. +-- Water Areas Centroids Materialized Views for Multiple Zoom Levels -- ============================================================================ +select create_mview_centroid_from_mview('mv_water_areas_z16_20','mv_water_areas_centroids_z16_20', 'name IS NOT NULL AND name <> '''''); +select create_mview_centroid_from_mview('mv_water_areas_z13_15','mv_water_areas_centroids_z13_15', 'name IS NOT NULL AND name <> '''''); +select create_mview_centroid_from_mview('mv_water_areas_z10_12','mv_water_areas_centroids_z10_12', 'name IS NOT NULL AND name <> '''''); +select create_mview_centroid_from_mview('mv_water_areas_z8_9','mv_water_areas_centroids_z8_9', 'name IS NOT NULL AND name <> '''''); -DROP FUNCTION IF EXISTS create_water_areas_centroids_mview; - -CREATE OR REPLACE FUNCTION create_water_areas_centroids_mview( - source_table TEXT, - view_name TEXT -) -RETURNS void AS $$ -DECLARE - lang_columns TEXT := get_language_columns(); - tmp_view_name TEXT := view_name || '_tmp'; - sql_create TEXT; - unique_columns TEXT := 'osm_id, type'; -BEGIN - sql_create := format($sql$ - CREATE MATERIALIZED VIEW %I AS - SELECT - osm_id, - NULLIF(name, '') AS name, - NULLIF(type, '') AS type, - NULLIF(start_date, '') AS start_date, - NULLIF(end_date, '') AS end_date, - isodatetodecimaldate(pad_date(start_date, 'start'), FALSE) AS start_decdate, - isodatetodecimaldate(pad_date(end_date, 'end'), FALSE) AS end_decdate, - area, - %s, - (ST_MaximumInscribedCircle(geometry)).center AS geometry - FROM %I - WHERE name IS NOT NULL AND name <> ''; - $sql$, tmp_view_name, lang_columns, source_table); - - PERFORM finalize_materialized_view( - tmp_view_name, - view_name, - unique_columns, - sql_create - ); -END; -$$ LANGUAGE plpgsql; -- ============================================================================ --- Create materialized views for water ceontroids +-- Water lines Materialized Views for Multiple Zoom Levels -- ============================================================================ -SELECT create_water_areas_centroids_mview('osm_water_areas_z0_2', 'mv_water_areas_centroids_z0_2'); -SELECT create_water_areas_centroids_mview('osm_water_areas_z3_5', 'mv_water_areas_centroids_z3_5'); -SELECT create_water_areas_centroids_mview('osm_water_areas_z6_7', 'mv_water_areas_centroids_z6_7'); -SELECT create_water_areas_centroids_mview('osm_water_areas_z8_9', 'mv_water_areas_centroids_z8_9'); -SELECT create_water_areas_centroids_mview('osm_water_areas_z10_12', 'mv_water_areas_centroids_z10_12'); -SELECT create_water_areas_centroids_mview('osm_water_areas_z13_15', 'mv_water_areas_centroids_z13_20'); --- ============================================================================ --- Create materialized views for water areas using subdivided geometries and generic function --- ============================================================================ -SELECT create_water_areas_subdivided_mview('osm_water_areas_z0_2', 'mv_water_areas_z0_2_subdivided'); -SELECT create_water_areas_subdivided_mview('osm_water_areas_z3_5', 'mv_water_areas_z3_5_subdivided'); -SELECT create_water_areas_subdivided_mview('osm_water_areas_z6_7', 'mv_water_areas_z6_7_subdivided'); -SELECT create_water_areas_subdivided_mview('osm_water_areas_z8_9', 'mv_water_areas_z8_9_subdivided'); -SELECT create_generic_mview('osm_water_areas_z10_12', 'mv_water_areas_z10_12', ARRAY['osm_id', 'type']); -SELECT create_generic_mview('osm_water_areas_z13_15', 'mv_water_areas_z13_15', ARRAY['osm_id', 'type']); -SELECT create_generic_mview('osm_water_areas', 'mv_water_areas_z16_20', ARRAY['osm_id', 'type']); +SELECT create_lines_mview('osm_water_lines', 'mv_water_lines_z16_20', 0, 0, 'id, osm_id, type', 'type IN (''river'', ''canal'', ''cliff'', ''dam'', ''stream'', ''ditch'', ''drain'')'); +SELECT create_mview_line_from_mview('mv_water_lines_z16_20', 'mv_water_lines_z13_15', 5, 'type IN (''river'', ''canal'', ''cliff'', ''dam'', ''stream'')'); +SELECT create_mview_line_from_mview('mv_water_lines_z13_15', 'mv_water_lines_z10_12', 20, 'type IN (''river'', ''canal'', ''cliff'', ''dam'')'); +SELECT create_mview_line_from_mview('mv_water_lines_z10_12', 'mv_water_lines_z8_9', 100, 'type IN (''river'', ''canal'')'); --- ============================================================================ --- Create materialized views for water lines --- ============================================================================ -SELECT create_generic_mview('osm_water_lines_z8_9', 'mv_water_lines_z8_9'); -SELECT create_generic_mview('osm_water_lines_z10_12', 'mv_water_lines_z10_12'); -SELECT create_generic_mview('osm_water_lines_z13_15', 'mv_water_lines_z13_15'); -SELECT create_generic_mview('osm_water_lines_z16_20', 'mv_water_lines_z16_20'); +-- Refresh areas views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_areas_z16_20; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_areas_z13_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_areas_z10_12; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_areas_z8_9; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_areas_z6_7; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_areas_z3_5; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_areas_z0_2; + +-- Refresh centroids views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_areas_centroids_z16_20; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_areas_centroids_z13_15; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_areas_centroids_z10_12; +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_areas_centroids_z8_9; + +-- Refresh lines views +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_lines_z16_20 +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_lines_z13_15 +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_lines_z10_12 +-- REFRESH MATERIALIZED VIEW CONCURRENTLY mv_water_lines_z8_9 \ No newline at end of file diff --git a/images/tiler-imposm/queries/utils/create_04_lines_mviews.sql b/images/tiler-imposm/queries/utils/create_04_lines_mviews.sql new file mode 100644 index 00000000..e2dad218 --- /dev/null +++ b/images/tiler-imposm/queries/utils/create_04_lines_mviews.sql @@ -0,0 +1,118 @@ +-- ============================================================================ +-- Function: create_lines_mview +-- Description: +-- Creates a materialized view from a source table with configurable geometry +-- simplification and minimum length filtering for LINESTRING geometries. +-- +-- - Applies ST_SimplifyPreserveTopology for geometry simplification +-- - Filters by minimum length (in meters) +-- - Includes length_m (rounded length in m) and length_km (rounded length in km) +-- - Includes multilingual name columns using get_language_columns() +-- - Includes temporal fields: start_date, end_date, and their decimal equivalents +-- +-- Parameters: +-- source_table TEXT - Name of the source table or materialized view +-- view_name TEXT - Name of the materialized view to create +-- simplify_tol DOUBLE PRECISION - Simplification tolerance (0 = no simplification) +-- min_length DOUBLE PRECISION - Minimum length in m to include (0 = no filter) +-- unique_columns TEXT - Comma-separated columns for unique index (default: 'id, osm_id, type') +-- where_filter TEXT - Optional WHERE clause filter (e.g., "highway != 'abandoned'"). NULL = no filter +-- +-- Notes: +-- - Creates the materialized view using a temporary swap mechanism +-- - Adds a spatial index (GiST) on geometry and a unique index on unique_columns +-- - Useful for creating views at different zoom levels with variable simplification +-- - where_filter is appended to WHERE clause with AND +-- ============================================================================ +DROP FUNCTION IF EXISTS create_lines_mview(TEXT, TEXT, DOUBLE PRECISION, DOUBLE PRECISION, TEXT, TEXT); + +CREATE OR REPLACE FUNCTION create_lines_mview( + source_table TEXT, + view_name TEXT, + simplify_tol DOUBLE PRECISION DEFAULT 0, + min_length DOUBLE PRECISION DEFAULT 0, + unique_columns TEXT DEFAULT 'id, osm_id, type', + where_filter TEXT DEFAULT NULL +) +RETURNS void AS $$ +DECLARE + lang_columns TEXT; + tmp_view_name TEXT := view_name || '_tmp'; + sql_create TEXT; + simplify_expr TEXT; + length_filter TEXT; + custom_filter TEXT; + all_cols TEXT; +BEGIN + -- Language columns will always be available + lang_columns := get_language_columns(); + + -- Build simplification expression + IF simplify_tol > 0 THEN + simplify_expr := format('ST_SimplifyPreserveTopology(geometry, %s)', simplify_tol); + ELSE + simplify_expr := 'geometry'; + END IF; + + -- Build length filter + IF min_length > 0 THEN + length_filter := format('AND ST_Length(geometry) > %s', min_length); + ELSE + length_filter := ''; + END IF; + + -- Build custom WHERE filter (if provided) + IF where_filter IS NOT NULL AND where_filter <> '' THEN + custom_filter := format(' AND (%s)', where_filter); + ELSE + custom_filter := ''; + END IF; + + -- Build SQL - get all columns from source table and replace geometry, handle special columns + -- Exclude start_decdate and end_decdate because they will be recalculated + SELECT COALESCE(string_agg( + CASE + WHEN column_name = 'geometry' THEN format('%s AS geometry', simplify_expr) + WHEN column_name IN ('length', 'len') THEN format( + '%I, ROUND(CAST(%I AS numeric), 1)::numeric(20,1) AS length_m, ROUND(CAST(%I AS numeric) / 1000, 1)::numeric(20,1) AS length_km', + column_name, column_name, column_name + ) + WHEN column_name = 'name' THEN 'NULLIF(name, '''') AS name' + WHEN column_name = 'start_date' THEN 'NULLIF(start_date, '''') AS start_date' + WHEN column_name = 'end_date' THEN 'NULLIF(end_date, '''') AS end_date' + ELSE quote_ident(column_name) + END, + ', ' ORDER BY ordinal_position + ), '') + INTO all_cols + FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = source_table + AND column_name NOT IN ('start_decdate', 'end_decdate'); + + -- Always add calculated date columns + all_cols := all_cols || ', public.isodatetodecimaldate(public.pad_date(start_date, ''start''), FALSE) AS start_decdate'; + all_cols := all_cols || ', public.isodatetodecimaldate(public.pad_date(end_date, ''end''), FALSE) AS end_decdate'; + + -- Add language columns (always available) + all_cols := all_cols || ', ' || lang_columns; + -- Add source column to identify origin (line) + all_cols := all_cols || ', ''line'' AS source'; + + sql_create := format($sql$ + CREATE MATERIALIZED VIEW %I AS + SELECT + %s + FROM %I + WHERE geometry IS NOT NULL + %s%s; + $sql$, tmp_view_name, all_cols, source_table, length_filter, custom_filter); + + PERFORM finalize_materialized_view( + tmp_view_name, + view_name, + unique_columns, + sql_create + ); +END; +$$ LANGUAGE plpgsql; diff --git a/images/tiler-imposm/queries/utils/create_mview_area_mview.sql b/images/tiler-imposm/queries/utils/create_mview_area_mview.sql new file mode 100644 index 00000000..5c9fac18 --- /dev/null +++ b/images/tiler-imposm/queries/utils/create_mview_area_mview.sql @@ -0,0 +1,110 @@ +DROP FUNCTION IF EXISTS create_area_mview_from_mview(TEXT, TEXT, DOUBLE PRECISION, DOUBLE PRECISION, TEXT); + +/** + * Creates a new materialized view from an existing materialized view with optional + * geometry simplification, area filtering, and custom WHERE conditions. + * + * Uses a temporary view pattern to avoid downtime: creates the new view with a _tmp suffix, + * then atomically replaces the old view by dropping it and renaming the temporary one. + * + * @param source_mview - Name of the source materialized view to read from + * @param target_mview - Name of the target materialized view to create/replace + * @param tolerance_meters - Geometry simplification tolerance in meters (0 = no simplification) + * @param min_area - Minimum area filter (0 = no filter, uses 'area' column) + * @param custom_filter - Additional WHERE clause filter (e.g., "type IN ('water', 'pond')") + */ +CREATE OR REPLACE FUNCTION create_area_mview_from_mview( + source_mview text, + target_mview text, + tolerance_meters double precision, + min_area double precision, + custom_filter text DEFAULT NULL +) +RETURNS void AS +$$ +DECLARE + cols_no_geom text; + sql text; + tmp_mview text; +BEGIN + + RAISE NOTICE '==> [MVIEW AREA] Creating % from % (simplification: %m, min_area: %s, custom_filter: %s)', target_mview, source_mview, tolerance_meters, min_area, custom_filter; + -- Generate temporary view name to avoid conflicts during creation + tmp_mview := target_mview || '_tmp'; + + -- 1) Get all columns from the source mview except 'geometry' + SELECT string_agg(quote_ident(attname), ', ' ORDER BY attnum) + INTO cols_no_geom + FROM pg_attribute a + JOIN pg_class c ON a.attrelid = c.oid + JOIN pg_namespace n ON c.relnamespace = n.oid + WHERE n.nspname = 'public' + AND c.relname = source_mview + AND a.attnum > 0 + AND NOT a.attisdropped + AND attname <> 'geometry'; + + IF cols_no_geom IS NULL THEN + RAISE EXCEPTION 'No columns found for %. Make sure the materialized view exists.', source_mview; + END IF; + + -- 2) Build the CREATE MATERIALIZED VIEW statement + sql := format( + 'CREATE MATERIALIZED VIEW %I AS + SELECT %s, %s AS geometry + FROM %I + WHERE geometry IS NOT NULL', + tmp_mview, + cols_no_geom, + CASE + WHEN tolerance_meters > 0 + THEN format('ST_SimplifyPreserveTopology(geometry, %s)', tolerance_meters) + ELSE 'geometry' + END, + source_mview + ); + + -- 3) Apply area filter if requested (filters by 'area' column) + IF min_area > 0 THEN + sql := sql || format(' AND area >= %s', min_area); + END IF; + + -- 4) Apply custom filter if provided (allows additional WHERE conditions) + IF custom_filter IS NOT NULL AND length(trim(custom_filter)) > 0 THEN + sql := sql || ' AND ' || custom_filter; + END IF; + + -- 5) Execute the CREATE MATERIALIZED VIEW statement + EXECUTE sql; + + -- 6) Create indexes on the temporary view + EXECUTE format( + 'CREATE UNIQUE INDEX IF NOT EXISTS %I_id_osm_id_uidx + ON %I (id, osm_id)', + tmp_mview, tmp_mview + ); + + EXECUTE format( + 'CREATE INDEX IF NOT EXISTS %I_geom_idx + ON %I USING GIST (geometry)', + tmp_mview, tmp_mview + ); + + -- 7) Drop the old materialized view if it exists + EXECUTE format('DROP MATERIALIZED VIEW IF EXISTS %I', target_mview); + + -- 8) Atomically rename the temporary view to the final name + EXECUTE format('ALTER MATERIALIZED VIEW %I RENAME TO %I', tmp_mview, target_mview); + + -- 9) Rename indexes to match the final view name + EXECUTE format( + 'ALTER INDEX IF EXISTS %I_id_osm_id_uidx RENAME TO %I_id_osm_id_uidx', + tmp_mview, target_mview + ); + + EXECUTE format( + 'ALTER INDEX IF EXISTS %I_geom_idx RENAME TO %I_geom_idx', + tmp_mview, target_mview + ); +END; +$$ LANGUAGE plpgsql; diff --git a/images/tiler-imposm/queries/utils/create_mview_centroid_mview.sql b/images/tiler-imposm/queries/utils/create_mview_centroid_mview.sql new file mode 100644 index 00000000..b06c13a5 --- /dev/null +++ b/images/tiler-imposm/queries/utils/create_mview_centroid_mview.sql @@ -0,0 +1,102 @@ +DROP FUNCTION IF EXISTS create_mview_centroid_from_mview(TEXT, TEXT, TEXT); + +/** + * Creates a new materialized view with point centroids from an existing materialized view + * containing area geometries (polygons/multipolygons). + * + * Converts area geometries to their centroid points using ST_MaximumInscribedCircle, + * which provides a better centroid position (center of the largest inscribed circle) + * compared to ST_Centroid. Useful for point-based rendering at lower zoom levels + * or when displaying areas as points. + * + * Uses a temporary view pattern to avoid downtime: creates the new view with a _tmp suffix, + * then atomically replaces the old view by dropping it and renaming the temporary one. + * + * @param source_mview - Name of the source materialized view to read from (must contain area geometries) + * @param target_mview - Name of the target materialized view to create/replace (will contain point geometries) + * @param custom_filter - Additional WHERE clause filter (e.g., "type IN ('water', 'pond')") + */ +CREATE OR REPLACE FUNCTION create_mview_centroid_from_mview( + source_mview text, + target_mview text, + custom_filter text DEFAULT NULL +) +RETURNS void AS +$$ +DECLARE + cols_no_geom text; + sql text; + tmp_mview text; +BEGIN + + RAISE NOTICE '==> [MVIEW CENTROID] Creating % from % (custom_filter: %s)',target_mview, source_mview, custom_filter; + -- Generate temporary view name to avoid conflicts during creation + tmp_mview := target_mview || '_tmp'; + + -- 1) Get all columns from the source mview except 'geometry' + SELECT string_agg(quote_ident(attname), ', ' ORDER BY attnum) + INTO cols_no_geom + FROM pg_attribute a + JOIN pg_class c ON a.attrelid = c.oid + JOIN pg_namespace n ON c.relnamespace = n.oid + WHERE n.nspname = 'public' + AND c.relname = source_mview + AND a.attnum > 0 + AND NOT a.attisdropped + AND attname <> 'geometry'; + + IF cols_no_geom IS NULL THEN + RAISE EXCEPTION 'No columns found for %. Make sure the materialized view exists.', source_mview; + END IF; + + -- 2) Build the CREATE MATERIALIZED VIEW statement + sql := format( + 'CREATE MATERIALIZED VIEW %I AS + SELECT %s, (ST_MaximumInscribedCircle(geometry)).center AS geometry + FROM %I + WHERE geometry IS NOT NULL + AND ST_GeometryType(geometry) IN (''ST_Polygon'', ''ST_MultiPolygon'')', + tmp_mview, + cols_no_geom, + source_mview + ); + + -- 3) Apply custom filter if provided (allows additional WHERE conditions) + IF custom_filter IS NOT NULL AND length(trim(custom_filter)) > 0 THEN + sql := sql || ' AND ' || custom_filter; + END IF; + + -- 5) Execute the CREATE MATERIALIZED VIEW statement + EXECUTE sql; + + -- 6) Create indexes on the temporary view + EXECUTE format( + 'CREATE UNIQUE INDEX IF NOT EXISTS %I_id_osm_id_uidx + ON %I (id, osm_id)', + tmp_mview, tmp_mview + ); + + EXECUTE format( + 'CREATE INDEX IF NOT EXISTS %I_geom_idx + ON %I USING GIST (geometry)', + tmp_mview, tmp_mview + ); + + -- 7) Drop the old materialized view if it exists + EXECUTE format('DROP MATERIALIZED VIEW IF EXISTS %I', target_mview); + + -- 8) Atomically rename the temporary view to the final name + EXECUTE format('ALTER MATERIALIZED VIEW %I RENAME TO %I', tmp_mview, target_mview); + + -- 9) Rename indexes to match the final view name + EXECUTE format( + 'ALTER INDEX IF EXISTS %I_id_osm_id_uidx RENAME TO %I_id_osm_id_uidx', + tmp_mview, target_mview + ); + + EXECUTE format( + 'ALTER INDEX IF EXISTS %I_geom_idx RENAME TO %I_geom_idx', + tmp_mview, target_mview + ); +END; +$$ LANGUAGE plpgsql; diff --git a/images/tiler-imposm/queries/utils/create_mview_line_mview.sql b/images/tiler-imposm/queries/utils/create_mview_line_mview.sql new file mode 100644 index 00000000..f4cb2104 --- /dev/null +++ b/images/tiler-imposm/queries/utils/create_mview_line_mview.sql @@ -0,0 +1,106 @@ +DROP FUNCTION IF EXISTS create_mview_line_from_mview(TEXT, TEXT, DOUBLE PRECISION, TEXT); + +/** + * Creates a new materialized view with line geometries from an existing materialized view + * containing line geometries (linestrings/multilinestrings). + * + * Applies optional geometry simplification for line geometries, useful for rendering + * at lower zoom levels or when simplifying complex line features. + * + * Uses a temporary view pattern to avoid downtime: creates the new view with a _tmp suffix, + * then atomically replaces the old view by dropping it and renaming the temporary one. + * + * @param source_mview - Name of the source materialized view to read from (must contain line geometries) + * @param target_mview - Name of the target materialized view to create/replace (will contain line geometries) + * @param tolerance_meters - Geometry simplification tolerance in meters (0 = no simplification) + * @param custom_filter - Additional WHERE clause filter (e.g., "type IN ('river', 'stream')") + */ +CREATE OR REPLACE FUNCTION create_mview_line_from_mview( + source_mview text, + target_mview text, + tolerance_meters double precision, + custom_filter text DEFAULT NULL +) +RETURNS void AS +$$ +DECLARE + cols_no_geom text; + sql text; + tmp_mview text; +BEGIN + RAISE NOTICE '==> [MVIEW LINE] Creating % from % (simplification: %m, custom_filter: %s)', target_mview, source_mview, tolerance_meters, custom_filter; + -- Generate temporary view name to avoid conflicts during creation + tmp_mview := target_mview || '_tmp'; + + -- 1) Get all columns from the source mview except 'geometry' + SELECT string_agg(quote_ident(attname), ', ' ORDER BY attnum) + INTO cols_no_geom + FROM pg_attribute a + JOIN pg_class c ON a.attrelid = c.oid + JOIN pg_namespace n ON c.relnamespace = n.oid + WHERE n.nspname = 'public' + AND c.relname = source_mview + AND a.attnum > 0 + AND NOT a.attisdropped + AND attname <> 'geometry'; + + IF cols_no_geom IS NULL THEN + RAISE EXCEPTION 'No columns found for %. Make sure the materialized view exists.', source_mview; + END IF; + + -- 2) Build the CREATE MATERIALIZED VIEW statement + sql := format( + 'CREATE MATERIALIZED VIEW %I AS + SELECT %s, %s AS geometry + FROM %I + WHERE geometry IS NOT NULL + AND ST_GeometryType(geometry) IN (''ST_LineString'', ''ST_MultiLineString'')', + tmp_mview, + cols_no_geom, + CASE + WHEN tolerance_meters > 0 + THEN format('ST_SimplifyPreserveTopology(geometry, %s)', tolerance_meters) + ELSE 'geometry' + END, + source_mview + ); + + -- 3) Apply custom filter if provided (allows additional WHERE conditions) + IF custom_filter IS NOT NULL AND length(trim(custom_filter)) > 0 THEN + sql := sql || ' AND ' || custom_filter; + END IF; + + -- 5) Execute the CREATE MATERIALIZED VIEW statement + EXECUTE sql; + + -- 6) Create indexes on the temporary view + EXECUTE format( + 'CREATE UNIQUE INDEX IF NOT EXISTS %I_id_osm_id_uidx + ON %I (id, osm_id)', + tmp_mview, tmp_mview + ); + + EXECUTE format( + 'CREATE INDEX IF NOT EXISTS %I_geom_idx + ON %I USING GIST (geometry)', + tmp_mview, tmp_mview + ); + + -- 7) Drop the old materialized view if it exists + EXECUTE format('DROP MATERIALIZED VIEW IF EXISTS %I', target_mview); + + -- 8) Atomically rename the temporary view to the final name + EXECUTE format('ALTER MATERIALIZED VIEW %I RENAME TO %I', tmp_mview, target_mview); + + -- 9) Rename indexes to match the final view name + EXECUTE format( + 'ALTER INDEX IF EXISTS %I_id_osm_id_uidx RENAME TO %I_id_osm_id_uidx', + tmp_mview, target_mview + ); + + EXECUTE format( + 'ALTER INDEX IF EXISTS %I_geom_idx RENAME TO %I_geom_idx', + tmp_mview, target_mview + ); +END; +$$ LANGUAGE plpgsql; diff --git a/images/tiler-imposm/scripts/create_mviews.sh b/images/tiler-imposm/scripts/create_mviews.sh index 24ea5f69..5907eee4 100755 --- a/images/tiler-imposm/scripts/create_mviews.sh +++ b/images/tiler-imposm/scripts/create_mviews.sh @@ -38,6 +38,12 @@ if [[ "$ALL" == true ]]; then execute_sql_file queries/utils/create_01_areas_mview.sql execute_sql_file queries/utils/create_02_points_mview.sql execute_sql_file queries/utils/create_03_points_centroids_mview.sql + execute_sql_file queries/utils/create_04_lines_mviews.sql + + ## Functions to create simplified areas, lines and centroids from existing materialized views + execute_sql_file queries/utils/create_mview_line_mview.sql + execute_sql_file queries/utils/create_mview_centroid_mview.sql + execute_sql_file queries/utils/create_mview_area_mview.sql # Route priority execute_sql_file queries/utils/route_priority.sql @@ -57,7 +63,10 @@ fi ##################### OHM ##################### log_message "Creating materialized views for OSM data" -execute_sql_file queries/ohm_mviews/admin_boundaries_centroids.sql & +## Admin boundaries areas +execute_sql_file queries/ohm_mviews/admin_boundaries_areas.sql +execute_sql_file queries/ohm_mviews/admin_boundaries_centroids.sql + execute_sql_file queries/ohm_mviews/landuse.sql & execute_sql_file queries/ohm_mviews/admin_boundaries_maritime.sql @@ -69,10 +78,10 @@ execute_sql_file queries/ohm_mviews/places.sql & execute_sql_file queries/ohm_mviews/transport_areas.sql & execute_sql_file queries/ohm_mviews/transport_lines.sql -execute_sql_file queries/ohm_mviews/water.sql & -execute_sql_file queries/ohm_mviews/admin_boundaries_areas.sql +execute_sql_file queries/ohm_mviews/water.sql ## routes execute_sql_file queries/ohm_mviews/routes_01_merge_by_date.sql execute_sql_file queries/ohm_mviews/routes_02_indexed.sql execute_sql_file queries/ohm_mviews/routes_03_mv.sql + diff --git a/images/tiler-imposm/scripts/refresh_mviews.sh b/images/tiler-imposm/scripts/refresh_mviews.sh index 0f2dc810..cf8bb9e0 100755 --- a/images/tiler-imposm/scripts/refresh_mviews.sh +++ b/images/tiler-imposm/scripts/refresh_mviews.sh @@ -1,255 +1,75 @@ #!/bin/bash set -e +source ./scripts/utils.sh + # ============================================================================ -# Script: refresh_mviews.sh +# Function: refresh_mviews_group # Description: -# Optimized script to refresh materialized views efficiently -# WITHOUT competing with tile generation. +# Refreshes a group of materialized views sequentially in an infinite loop. +# Each view is refreshed using REFRESH MATERIALIZED VIEW CONCURRENTLY to +# avoid blocking reads during the refresh operation. # -# Optimization strategy: -# - Conservative parallelism: Maximum 2 simultaneous refreshes globally -# - Reduced parallelism per group: 1-2 views in parallel within each group -# - Optional load monitoring: Can pause if there's high tile generation load -# - Dependency respect: Updates base views before dependent ones +# Parameters: +# $1 - group_name: Name of the group (used for logging purposes) +# $2 - sleep_interval: Number of seconds to wait between refresh cycles +# $@ - materialized_views: Array of materialized view names to refresh # -# Implemented improvements: -# 1. Controlled parallelization: Updates multiple views in parallel within -# each group, but with conservative limits to avoid competing with tiles -# 2. Dependency handling: Respects update order for views that depend on -# others (e.g., routes, admin_boundaries) -# 3. Concurrency control: Limits the number of simultaneous refreshes -# to avoid saturating the database (default: 2, vs previous 3) -# 4. Time tracking: Measures and reports execution time for each -# update and complete cycle -# 5. Lock cleanup: Automatically removes locks from terminated processes -# 6. Smart pause: Option to pause refreshes during high load -# -# Environment variables: -# MAX_CONCURRENT_REFRESHES: Maximum number of simultaneous refreshes (default: 2) -# PAUSE_ON_HIGH_LOAD: Pause refreshes if there's high load (default: false) -# HIGH_LOAD_THRESHOLD: Active connections threshold to pause (default: 180) +# Behavior: +# - Runs in an infinite loop +# - Refreshes all views in the group sequentially (one after another) +# - Uses CONCURRENTLY to avoid blocking database reads +# - Logs success/failure for each view refresh +# - Waits for sleep_interval seconds after completing each full cycle # # Usage: -# ./refresh_mviews.sh -# MAX_CONCURRENT_REFRESHES=2 ./refresh_mviews.sh -# PAUSE_ON_HIGH_LOAD=true HIGH_LOAD_THRESHOLD=170 ./refresh_mviews.sh +# refresh_mviews_group "GROUP_NAME" 180 "${views_array[@]}" & # -# IMPORTANT: -# - Tegola uses ~150 connections to generate tiles -# - DB has ~200 max_connections -# - This script uses maximum 2 simultaneous refreshes to leave margin -# - CONCURRENTLY refreshes don't block reads, but consume resources -# - If you notice tiles generate slower, reduce MAX_CONCURRENT_REFRESHES to 1 +# Example: +# refresh_mviews_group "WATER" 180 "${water_views[@]}" & # ============================================================================ - -source ./scripts/utils.sh - -# Global concurrency configuration -# IMPORTANT: Adjust according to DB capacity and tile load -# Tegola uses ~150 connections, DB has ~200 max_connections -# We leave margin for other operations -MAX_CONCURRENT_REFRESHES=${MAX_CONCURRENT_REFRESHES:-2} -REFRESH_LOCK_DIR="/tmp/mview_refresh_locks" -mkdir -p "$REFRESH_LOCK_DIR" - -# Priority configuration: pause refreshes if there's high tile load -# You can monitor active connections and pause automatically -PAUSE_ON_HIGH_LOAD=${PAUSE_ON_HIGH_LOAD:-false} -HIGH_LOAD_THRESHOLD=${HIGH_LOAD_THRESHOLD:-180} # Pause if there are more than 180 connections - -# Function to acquire a concurrency lock -acquire_refresh_lock() { - local lock_file="$REFRESH_LOCK_DIR/refresh.lock" - local max_wait=${1:-300} # Wait maximum 5 minutes by default - local waited=0 - - while [ $waited -lt $max_wait ]; do - local current_count=$(find "$REFRESH_LOCK_DIR" -name "*.pid" 2>/dev/null | wc -l | tr -d ' ') - - if [ "$current_count" -lt "$MAX_CONCURRENT_REFRESHES" ]; then - local pid_file="$REFRESH_LOCK_DIR/$$.pid" - echo "$$" > "$pid_file" - return 0 - fi - - sleep 1 - waited=$((waited + 1)) - done - - log_message "[LOCK] ⚠️ Timeout waiting for concurrency lock" - return 1 -} - -# Function to release the lock -release_refresh_lock() { - local pid_file="$REFRESH_LOCK_DIR/$$.pid" - rm -f "$pid_file" -} - -# Function to clean up orphaned locks -cleanup_stale_locks() { - find "$REFRESH_LOCK_DIR" -name "*.pid" -type f | while read pid_file; do - local pid=$(cat "$pid_file" 2>/dev/null) - if [ -n "$pid" ] && ! kill -0 "$pid" 2>/dev/null; then - rm -f "$pid_file" - fi - done -} - -# Function to check database load -check_db_load() { - if [ "$PAUSE_ON_HIGH_LOAD" != "true" ]; then - return 0 # Don't check if disabled - fi - - local active_connections=$(psql "$PG_CONNECTION" -t -A -c \ - "SELECT count(*) FROM pg_stat_activity WHERE state = 'active' AND pid != pg_backend_pid();" 2>/dev/null | tr -d ' \n') - - if [ -z "$active_connections" ]; then - # If we can't get the count, assume it's okay (don't block) - return 0 - fi - - if [ "$active_connections" -gt "$HIGH_LOAD_THRESHOLD" ]; then - return 1 # High load, pause - fi - return 0 # Normal load, continue -} - -# Function to refresh a single view with time tracking -refresh_single_mview() { - local mview="$1" - local use_concurrent="${2:-true}" - local start_time=$(date +%s) - - # Check load before starting - if ! check_db_load; then - local active_conn=$(psql "$PG_CONNECTION" -t -A -c \ - "SELECT count(*) FROM pg_stat_activity WHERE state = 'active' AND pid != pg_backend_pid();" 2>/dev/null | tr -d ' \n') - log_message "[REFRESH] ⏸️ Pausing update of $mview (high load: $active_conn active connections, threshold: $HIGH_LOAD_THRESHOLD)" - return 2 # Special code for "paused due to load" - fi - - log_message "[REFRESH] Starting update of $mview..." - - # Acquire lock before refreshing - if ! acquire_refresh_lock; then - log_message "[REFRESH] ❌ Could not acquire lock for $mview" - return 1 - fi - - local refresh_cmd - if [ "$use_concurrent" = "true" ]; then - refresh_cmd="REFRESH MATERIALIZED VIEW CONCURRENTLY $mview;" - else - refresh_cmd="REFRESH MATERIALIZED VIEW $mview;" - fi - - if psql "$PG_CONNECTION" -c "$refresh_cmd"; then - local end_time=$(date +%s) - local duration=$((end_time - start_time)) - log_message "[REFRESH] ✅ $mview updated successfully (${duration}s)" - release_refresh_lock - return 0 - else - local end_time=$(date +%s) - local duration=$((end_time - start_time)) - log_message "[REFRESH] ❌ ERROR updating $mview (${duration}s)" - release_refresh_lock - return 1 - fi -} - -# Improved function to refresh a group of views -# Now supports parallelization and dependencies -refresh_mviews_group() { +function refresh_mviews_group() { local group_name="$1" local sleep_interval="$2" - local max_parallel="${3:-1}" # Maximum number of views to refresh in parallel - shift 3 + shift 2 local materialized_views=("$@") - - # Periodically clean up orphaned locks - cleanup_stale_locks - + while true; do - # Check load before starting cycle - local retries=0 - while ! check_db_load && [ $retries -lt 10 ]; do - sleep 30 # Wait 30 seconds if there's high load - retries=$((retries + 1)) + for mview in "${materialized_views[@]}"; do + log_message "[$group_name] Refreshing $mview..." + if psql "$PG_CONNECTION" -c "REFRESH MATERIALIZED VIEW CONCURRENTLY $mview;"; then + log_message "[$group_name] ✅ Successfully refreshed $mview." + else + log_message "[$group_name] ❌ ERROR refreshing $mview!" + fi done - - local group_start_time=$(date +%s) - log_message "[$group_name] Starting update cycle (${#materialized_views[@]} views)" - - # If max_parallel is 1, refresh sequentially (original behavior) - if [ "$max_parallel" -eq 1 ]; then - for mview in "${materialized_views[@]}"; do - refresh_single_mview "$mview" "true" - local result=$? - # If paused due to load, wait a bit more - if [ $result -eq 2 ]; then - sleep 60 - fi - done - else - # Refresh in parallel with limit - local pids=() - local index=0 - - while [ $index -lt ${#materialized_views[@]} ]; do - cleanup_finished_pids pids - # Wait if we already have the maximum parallel processes - while [ ${#pids[@]} -ge "$max_parallel" ]; do - cleanup_finished_pids pids - sleep 1 - done - - # Start new refresh in background - refresh_single_mview "${materialized_views[$index]}" "true" & - pids+=($!) - index=$((index + 1)) - - # Small pause between starts to avoid saturating - sleep 2 - done - - # Wait for all processes to finish - for pid in "${pids[@]}"; do - wait "$pid" 2>/dev/null || true - done - fi - - local group_end_time=$(date +%s) - local group_duration=$((group_end_time - group_start_time)) - log_message "[$group_name] ✅ Cycle completed in ${group_duration}s. Waiting ${sleep_interval}s before next cycle..." sleep "$sleep_interval" done } -# Views with dependencies - must be refreshed in order -admin_boundaries_lines_base_views=( +admin_boundaries_lines_views=( mv_relation_members_boundaries -) - -admin_boundaries_lines_intermediate_views=( mv_admin_boundaries_relations_ways -) - -admin_boundaries_lines_views=( - mv_admin_boundaries_lines_z0_2 - mv_admin_boundaries_lines_z3_5 - mv_admin_boundaries_lines_z6_7 - mv_admin_boundaries_lines_z8_9 - mv_admin_boundaries_lines_z10_12 - mv_admin_boundaries_lines_z13_15 mv_admin_boundaries_lines_z16_20 + mv_admin_boundaries_lines_z13_15 + mv_admin_boundaries_lines_z10_12 + mv_admin_boundaries_lines_z8_9 + mv_admin_boundaries_lines_z6_7 + mv_admin_boundaries_lines_z3_5 + mv_admin_boundaries_lines_z0_2 ) -admin_boundaries_centroids_views=( +admin_boundaries_areas_centroids_views=( + # areas + mv_admin_boundaries_areas_z16_20 + mv_admin_boundaries_areas_z13_15 + mv_admin_boundaries_areas_z10_12 + mv_admin_boundaries_areas_z8_9 + mv_admin_boundaries_areas_z6_7 + mv_admin_boundaries_areas_z3_5 + mv_admin_boundaries_areas_z0_2 + # centroids mv_admin_boundaries_centroids_z0_2 mv_admin_boundaries_centroids_z3_5 mv_admin_boundaries_centroids_z6_7 @@ -260,7 +80,7 @@ admin_boundaries_centroids_views=( ) admin_maritime_lines_views=( - mv_admin_maritime_lines_z0_5 + mv_admin_maritime_lines_z0_5_v2 mv_admin_maritime_lines_z6_9 mv_admin_maritime_lines_z10_15 ) @@ -280,40 +100,38 @@ landuse_views=( # areas mv_landuse_areas_z6_7 mv_landuse_areas_z8_9 - mv_landuse_areas_z10_11 - mv_landuse_areas_z12_13 - mv_landuse_areas_z14_15 + mv_landuse_areas_z10_12 + mv_landuse_areas_z13_15 mv_landuse_areas_z16_20 # points mv_landuse_points # points centroids mv_landuse_points_centroids_z6_7 mv_landuse_points_centroids_z8_9 - mv_landuse_points_centroids_z10_11 - mv_landuse_points_centroids_z12_13 - mv_landuse_points_centroids_z14_15 + mv_landuse_points_centroids_z10_12 + mv_landuse_points_centroids_z13_15 mv_landuse_points_centroids_z16_20 # lines - mv_landuse_lines_z14_20 + mv_landuse_lines_z14_15 + mv_landuse_lines_z16_20 ) others_views=( # areas mv_other_areas_z8_9 - mv_other_areas_z10_11 - mv_other_areas_z12_13 - mv_other_areas_z14_15 + mv_other_areas_z10_12 + mv_other_areas_z13_15 mv_other_areas_z16_20 # points mv_other_points # points centroids mv_other_points_centroids_z8_9 - mv_other_points_centroids_z10_11 - mv_other_points_centroids_z12_13 - mv_other_points_centroids_z14_15 + mv_other_points_centroids_z10_12 + mv_other_points_centroids_z13_15 mv_other_points_centroids_z16_20 # lines - mv_other_lines_z14_20 + mv_other_lines_z16_20 + mv_other_lines_z14_15 ) places_views=( @@ -324,49 +142,47 @@ places_views=( mv_place_areas_z14_20 ) + transport_views=( # lines + mv_transport_lines_z16_20 + mv_transport_lines_z13_15 + mv_transport_lines_z10_12 + mv_transport_lines_z8_9 + mv_transport_lines_z6_7 mv_transport_lines_z5 - mv_transport_lines_z6 - mv_transport_lines_z7 - mv_transport_lines_z8 - mv_transport_lines_z9 - mv_transport_lines_z10_11 - mv_transport_lines_z12_13 - mv_transport_lines_z14_20 # areas - mv_transport_areas_z10_11 - mv_transport_areas_z12_13 - mv_transport_areas_z14_15 mv_transport_areas_z16_20 + mv_transport_areas_z13_15 + mv_transport_areas_z10_12 # points mv_transport_points # points centroids - mv_transport_points_centroids_z10_11 - mv_transport_points_centroids_z12_13 - mv_transport_points_centroids_z14_15 mv_transport_points_centroids_z16_20 + mv_transport_points_centroids_z13_15 + mv_transport_points_centroids_z10_12 ) water_views=( - mv_water_areas_centroids_z0_2 - mv_water_areas_centroids_z3_5 - mv_water_areas_centroids_z6_7 - mv_water_areas_centroids_z8_9 - mv_water_areas_centroids_z10_12 - mv_water_areas_centroids_z13_20 - mv_water_areas_z0_2_subdivided - mv_water_areas_z3_5_subdivided - mv_water_areas_z6_7_subdivided - mv_water_areas_z8_9_subdivided - mv_water_areas_z10_12 - mv_water_areas_z13_15 + # areas mv_water_areas_z16_20 - mv_water_lines_z8_9 - mv_water_lines_z10_12 - mv_water_lines_z13_15 + mv_water_areas_z13_15 + mv_water_areas_z10_12 + mv_water_areas_z8_9 + mv_water_areas_z6_7 + mv_water_areas_z3_5 + mv_water_areas_z0_2 + # centroids + mv_water_areas_centroids_z16_20 + mv_water_areas_centroids_z13_15 + mv_water_areas_centroids_z10_12 + mv_water_areas_centroids_z8_9 + # lines mv_water_lines_z16_20 + mv_water_lines_z13_15 + mv_water_lines_z10_12 + mv_water_lines_z8_9 ) buildings_views=( @@ -380,151 +196,27 @@ buildings_views=( mv_buildings_points_centroids_z16_20 ) -# Route views with dependencies -routes_base_views=( +routes_views=( + ## normalized mv_routes_normalized -) - -routes_intermediate_views=( mv_routes_indexed -) - -routes_views=( - mv_routes_indexed_z5_6 - mv_routes_indexed_z7_8 - mv_routes_indexed_z9_10 - mv_routes_indexed_z11_13 - mv_routes_indexed_z14_20 -) - - -admin_boundaries_areas_views=( - mv_admin_boundaries_areas_z0_2 - mv_admin_boundaries_areas_z3_5 - mv_admin_boundaries_areas_z6_7 - mv_admin_boundaries_areas_z8_9 - mv_admin_boundaries_areas_z10_12 - mv_admin_boundaries_areas_z13_15 - mv_admin_boundaries_areas_z16_20 -) - - - -# Helper function to clean up finished PIDs -cleanup_finished_pids() { - local -n pids_ref=$1 - local new_pids=() - for pid in "${pids_ref[@]}"; do - if kill -0 "$pid" 2>/dev/null; then - new_pids+=("$pid") - fi - done - pids_ref=("${new_pids[@]}") -} - -# Function to refresh groups with dependencies -refresh_dependent_group() { - local group_name="$1" - local sleep_interval="$2" - local base_array_name="$3" - local intermediate_array_name="$4" - local dependent_array_name="$5" - local max_parallel="${6:-3}" - - # Get arrays by name - local base_views - local intermediate_views - local dependent_views - eval "base_views=(\"\${${base_array_name}[@]}\")" - eval "intermediate_views=(\"\${${intermediate_array_name}[@]}\")" - eval "dependent_views=(\"\${${dependent_array_name}[@]}\")" - - while true; do - local cycle_start=$(date +%s) - log_message "[$group_name] Starting update cycle with dependencies" - - # Step 1: Refresh base views first (sequentially) - if [ ${#base_views[@]} -gt 0 ]; then - for mview in "${base_views[@]}"; do - refresh_single_mview "$mview" "true" - done - fi - - # Step 2: Refresh intermediate views (can be in parallel) - if [ ${#intermediate_views[@]} -gt 0 ]; then - local pids=() - local index=0 - while [ $index -lt ${#intermediate_views[@]} ]; do - cleanup_finished_pids pids - while [ ${#pids[@]} -ge "$max_parallel" ]; do - cleanup_finished_pids pids - sleep 1 - done - refresh_single_mview "${intermediate_views[$index]}" "true" & - pids+=($!) - index=$((index + 1)) - done - for pid in "${pids[@]}"; do - wait "$pid" 2>/dev/null || true - done - fi - - # Step 3: Refresh dependent views in parallel - if [ ${#dependent_views[@]} -gt 0 ]; then - local pids=() - local index=0 - while [ $index -lt ${#dependent_views[@]} ]; do - cleanup_finished_pids pids - while [ ${#pids[@]} -ge "$max_parallel" ]; do - cleanup_finished_pids pids - sleep 1 - done - refresh_single_mview "${dependent_views[$index]}" "true" & - pids+=($!) - index=$((index + 1)) - done - for pid in "${pids[@]}"; do - wait "$pid" 2>/dev/null || true - done - fi - - local cycle_end=$(date +%s) - local cycle_duration=$((cycle_end - cycle_start)) - log_message "[$group_name] ✅ Cycle completed in ${cycle_duration}s. Waiting ${sleep_interval}s..." - sleep "$sleep_interval" - done -} - -# Start update groups -# NOTE: Reduced parallelism to avoid competing with tile generation -# Tegola needs ~150 connections, we leave margin for other operations - -# Groups with dependencies (must be refreshed in order) -# Reduced to 1-2 in parallel to minimize impact on tiles -refresh_dependent_group "ADMIN_BOUNDARIES_LINES" 1 \ - "admin_boundaries_lines_base_views" \ - "admin_boundaries_lines_intermediate_views" \ - "admin_boundaries_lines_views" \ - 1 & # Reduced to 1 for this critical group - -refresh_dependent_group "ROUTES" 180 \ - "routes_base_views" \ - "routes_intermediate_views" \ - "routes_views" \ - 2 & # Reduced to 2 - -# Independent groups - conservative parallelism -# We reduce parallelism within each group to leave resources for tiles -refresh_mviews_group "ADMIN_BOUNDARIES_CENTROIDS" 60 2 "${admin_boundaries_centroids_views[@]}" & -refresh_mviews_group "ADMIN_MARITIME_LINES" 300 1 "${admin_maritime_lines_views[@]}" & -refresh_mviews_group "TRANSPORTS" 180 2 "${transport_views[@]}" & -refresh_mviews_group "AMENITY" 180 2 "${amenity_views[@]}" & -refresh_mviews_group "LANDUSE" 180 2 "${landuse_views[@]}" & -refresh_mviews_group "OTHERS" 180 2 "${others_views[@]}" & -refresh_mviews_group "PLACES" 180 2 "${places_views[@]}" & -refresh_mviews_group "WATER" 180 2 "${water_views[@]}" & -refresh_mviews_group "BUILDINGS" 180 1 "${buildings_views[@]}" & -refresh_mviews_group "ADMIN_BOUNDARIES_AREAS" 180 2 "${admin_boundaries_areas_views[@]}" & - -# Wait for all processes to finish (should never happen in an infinite loop) -wait + ## indexed + mv_routes_indexed_z16_20 + mv_routes_indexed_z13_15 + mv_routes_indexed_z10_12 + mv_routes_indexed_z8_9 + mv_routes_indexed_z6_7 + mv_routes_indexed_z5 +) + +refresh_mviews_group "ADMIN_BOUNDARIES_LINES" 60 "${admin_boundaries_lines_views[@]}" & +refresh_mviews_group "ADMIN_BOUNDARIES_AREAS_CENTROIDS" 180 "${admin_boundaries_areas_centroids_views[@]}" & +refresh_mviews_group "ADMIN_MARITIME_LINES" 300 "${admin_maritime_lines_views[@]}" & +refresh_mviews_group "TRANSPORTS" 180 "${transport_views[@]}" & +refresh_mviews_group "AMENITY" 180 "${amenity_views[@]}" & +refresh_mviews_group "LANDUSE" 180 "${landuse_views[@]}" & +refresh_mviews_group "OTHERS" 180 "${others_views[@]}" & +refresh_mviews_group "PLACES" 180 "${places_views[@]}" & +refresh_mviews_group "WATER" 180 "${water_views[@]}" & +refresh_mviews_group "BUILDINGS" 180 "${buildings_views[@]}" & +refresh_mviews_group "ROUTES" 180 "${routes_views[@]}" & diff --git a/images/tiler-imposm/start.sh b/images/tiler-imposm/start.sh index 3f43a144..fd4fb518 100755 --- a/images/tiler-imposm/start.sh +++ b/images/tiler-imposm/start.sh @@ -272,21 +272,17 @@ function importData() { fi log_message "Import PBF file..." - if [ -z "$TILER_IMPORT_LIMIT" ]; then - imposm import \ - -config $WORKDIR/config.json \ - -read $PBFFILE \ - -write \ - -diff -cachedir $CACHE_DIR -overwritecache -diffdir $DIFF_DIR - else - wget $TILER_IMPORT_LIMIT -O $WORKDIR/$LIMITFILE - imposm import \ - -config $WORKDIR/config.json \ - -read $PBFFILE \ - -write \ - -diff -cachedir $CACHE_DIR -overwritecache -diffdir $DIFF_DIR \ - -limitto $WORKDIR/$LIMITFILE - fi + + imposm import \ + -config $WORKDIR/config.json \ + -read $PBFFILE \ + -write \ + -diff \ + -cachedir $CACHE_DIR \ + -overwritecache \ + -diffdir $DIFF_DIR \ + -optimize + imposm import \ -config $WORKDIR/config.json \ diff --git a/images/tiler-server/config/providers/admin_boundaries_lines.toml b/images/tiler-server/config/providers/admin_boundaries_lines.toml index 08a97564..7ad67efc 100644 --- a/images/tiler-server/config/providers/admin_boundaries_lines.toml +++ b/images/tiler-server/config/providers/admin_boundaries_lines.toml @@ -6,7 +6,7 @@ id_fieldname = "osm_id" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - member as osm_id, + osm_id, admin_level, type, start_date, @@ -18,6 +18,7 @@ FROM WHERE geometry && !BBOX! """ + [[providers.layers]] name = "admin_boundaries_lines_z3_5" geometry_fieldname = "geometry" @@ -26,7 +27,7 @@ id_fieldname = "osm_id" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - member as osm_id, + osm_id, admin_level, type, start_date, @@ -48,7 +49,7 @@ id_fieldname = "osm_id" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - member as osm_id, + osm_id, admin_level, type, start_date, @@ -69,7 +70,7 @@ id_fieldname = "osm_id" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - member as osm_id, + osm_id, admin_level, type, start_date, @@ -90,7 +91,7 @@ id_fieldname = "osm_id" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - member as osm_id, + osm_id, admin_level, type, start_date, @@ -111,7 +112,7 @@ id_fieldname = "osm_id" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - member as osm_id, + osm_id, admin_level, type, start_date, @@ -132,7 +133,7 @@ id_fieldname = "osm_id" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - member as osm_id, + osm_id, admin_level, type, start_date, diff --git a/images/tiler-server/config/providers/admin_boundaries_maritime.toml b/images/tiler-server/config/providers/admin_boundaries_maritime.toml index adb58225..2b9d1670 100644 --- a/images/tiler-server/config/providers/admin_boundaries_maritime.toml +++ b/images/tiler-server/config/providers/admin_boundaries_maritime.toml @@ -19,7 +19,7 @@ SELECT official_name, {{LENGUAGES}} FROM - mv_admin_maritime_lines_z0_5 + mv_admin_maritime_lines_z0_5_v2 WHERE geometry && !BBOX! """ diff --git a/images/tiler-server/config/providers/landuse_areas.toml b/images/tiler-server/config/providers/landuse_areas.toml index 17adb720..bf170f39 100644 --- a/images/tiler-server/config/providers/landuse_areas.toml +++ b/images/tiler-server/config/providers/landuse_areas.toml @@ -49,7 +49,7 @@ WHERE """ [[providers.layers]] -name = "landuse_areas_z10_11" +name = "landuse_areas_z10_12" geometry_fieldname = "geometry" geometry_type = "multipolygon" id_fieldname = "osm_id" @@ -68,13 +68,13 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_landuse_areas_z10_11 + mv_landuse_areas_z10_12 WHERE geometry && !BBOX! """ [[providers.layers]] -name = "landuse_areas_z12_13" +name = "landuse_areas_z13_15" geometry_fieldname = "geometry" geometry_type = "multipolygon" id_fieldname = "osm_id" @@ -93,32 +93,7 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_landuse_areas_z12_13 -WHERE - geometry && !BBOX! -""" - -[[providers.layers]] -name = "landuse_areas_z14_15" -geometry_fieldname = "geometry" -geometry_type = "multipolygon" -id_fieldname = "osm_id" -sql = """ -SELECT - ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - osm_id, - name, - class, - type, - area_m2, - area, - start_date, - end_date, - start_decdate, - end_decdate, - {{LENGUAGES}} -FROM - mv_landuse_areas_z14_15 + mv_landuse_areas_z13_15 WHERE geometry && !BBOX! """ @@ -165,20 +140,14 @@ max_zoom = 9 [[maps.layers]] name = "landuse_areas" -provider_layer = "osm.landuse_areas_z10_11" +provider_layer = "osm.landuse_areas_z10_12" min_zoom = 10 -max_zoom = 11 - -[[maps.layers]] -name = "landuse_areas" -provider_layer = "osm.landuse_areas_z12_13" -min_zoom = 12 -max_zoom = 13 +max_zoom = 12 [[maps.layers]] name = "landuse_areas" -provider_layer = "osm.landuse_areas_z14_15" -min_zoom = 14 +provider_layer = "osm.landuse_areas_z13_15" +min_zoom = 13 max_zoom = 15 [[maps.layers]] diff --git a/images/tiler-server/config/providers/landuse_lines.toml b/images/tiler-server/config/providers/landuse_lines.toml index 0d152ce2..c3a2a904 100644 --- a/images/tiler-server/config/providers/landuse_lines.toml +++ b/images/tiler-server/config/providers/landuse_lines.toml @@ -1,5 +1,5 @@ [[providers.layers]] -name = "landuse_lines" +name = "landuse_lines_z14_15" geometry_fieldname = "geometry" geometry_type = "linestring" id_fieldname = "osm_id" @@ -16,13 +16,45 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_landuse_lines_z14_20 + mv_landuse_lines_z14_15 +WHERE + geometry && !BBOX! +""" + +[[providers.layers]] +name = "landuse_lines_z16_20" +geometry_fieldname = "geometry" +geometry_type = "linestring" +id_fieldname = "osm_id" +sql = """ +SELECT + ST_AsMVTGeom(geometry, !BBOX!) AS geometry, + osm_id, + name, + class, + type, + start_date, + end_date, + start_decdate, + end_decdate, + {{LENGUAGES}} +FROM + mv_landuse_lines_z16_20 WHERE geometry && !BBOX! """ #######Maps + [[maps.layers]] name = "landuse_lines" -provider_layer = "osm.landuse_lines" +provider_layer = "osm.landuse_lines_z14_15" min_zoom = 14 +max_zoom = 15 + +[[maps.layers]] +name = "landuse_lines" +provider_layer = "osm.landuse_lines_z16_20" +min_zoom = 16 max_zoom = 20 + + diff --git a/images/tiler-server/config/providers/landuse_points_centroids.toml b/images/tiler-server/config/providers/landuse_points_centroids.toml index 185e7000..e8433884 100644 --- a/images/tiler-server/config/providers/landuse_points_centroids.toml +++ b/images/tiler-server/config/providers/landuse_points_centroids.toml @@ -49,7 +49,7 @@ WHERE [[providers.layers]] -name = "landuse_points_centroids_z10_11" +name = "landuse_points_centroids_z10_12" geometry_fieldname = "geometry" geometry_type = "point" id_fieldname = "osm_id" @@ -67,13 +67,13 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_landuse_points_centroids_z10_11 + mv_landuse_points_centroids_z10_12 WHERE geometry && !BBOX! """ [[providers.layers]] -name = "landuse_points_centroids_z12_13" +name = "landuse_points_centroids_z13_15" geometry_fieldname = "geometry" geometry_type = "point" id_fieldname = "osm_id" @@ -91,31 +91,7 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_landuse_points_centroids_z12_13 -WHERE - geometry && !BBOX! -""" - -[[providers.layers]] -name = "landuse_points_centroids_z14_15" -geometry_fieldname = "geometry" -geometry_type = "point" -id_fieldname = "osm_id" -sql = """ -SELECT - ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - osm_id, - name, - class, - type, - area_m2, - start_date, - end_date, - start_decdate, - end_decdate, - {{LENGUAGES}} -FROM - mv_landuse_points_centroids_z14_15 + mv_landuse_points_centroids_z13_15 WHERE geometry && !BBOX! """ @@ -160,20 +136,14 @@ max_zoom = 9 [[maps.layers]] name = "landuse_points_centroids" -provider_layer = "osm.landuse_points_centroids_z10_11" +provider_layer = "osm.landuse_points_centroids_z10_12" min_zoom = 10 -max_zoom = 11 - -[[maps.layers]] -name = "landuse_points_centroids" -provider_layer = "osm.landuse_points_centroids_z12_13" -min_zoom = 12 -max_zoom = 13 +max_zoom = 12 [[maps.layers]] name = "landuse_points_centroids" -provider_layer = "osm.landuse_points_centroids_z14_15" -min_zoom = 14 +provider_layer = "osm.landuse_points_centroids_z13_15" +min_zoom = 13 max_zoom = 15 [[maps.layers]] diff --git a/images/tiler-server/config/providers/other_areas.toml b/images/tiler-server/config/providers/other_areas.toml index 03627f60..21568d9d 100644 --- a/images/tiler-server/config/providers/other_areas.toml +++ b/images/tiler-server/config/providers/other_areas.toml @@ -26,7 +26,7 @@ WHERE geometry_fieldname = "geometry" geometry_type = "multipolygon" id_fieldname = "osm_id" -name = "other_areas_z10_11" +name = "other_areas_z10_12" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, @@ -41,7 +41,7 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_other_areas_z10_11 + mv_other_areas_z10_12 WHERE geometry && !BBOX! """ @@ -50,7 +50,7 @@ WHERE geometry_fieldname = "geometry" geometry_type = "multipolygon" id_fieldname = "osm_id" -name = "other_areas_z12_13" +name = "other_areas_z13_15" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, @@ -65,31 +65,7 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_other_areas_z12_13 -WHERE - geometry && !BBOX! -""" - -[[providers.layers]] -geometry_fieldname = "geometry" -geometry_type = "multipolygon" -id_fieldname = "osm_id" -name = "other_areas_z14_15" -sql = """ -SELECT - ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - osm_id, - name, - class, - type, - area_m2, - start_date, - end_date, - start_decdate, - end_decdate, - {{LENGUAGES}} -FROM - mv_other_areas_z14_15 + mv_other_areas_z13_15 WHERE geometry && !BBOX! """ @@ -127,20 +103,14 @@ max_zoom = 9 [[maps.layers]] name = "other_areas" -provider_layer = "osm.other_areas_z10_11" +provider_layer = "osm.other_areas_z10_12" min_zoom = 10 -max_zoom = 11 - -[[maps.layers]] -name = "other_areas" -provider_layer = "osm.other_areas_z12_13" -min_zoom = 12 -max_zoom = 13 +max_zoom = 12 [[maps.layers]] name = "other_areas" -provider_layer = "osm.other_areas_z14_15" -min_zoom = 14 +provider_layer = "osm.other_areas_z13_15" +min_zoom = 13 max_zoom = 15 [[maps.layers]] diff --git a/images/tiler-server/config/providers/other_lines.toml b/images/tiler-server/config/providers/other_lines.toml index f5cfeca9..03da853e 100644 --- a/images/tiler-server/config/providers/other_lines.toml +++ b/images/tiler-server/config/providers/other_lines.toml @@ -1,5 +1,5 @@ [[providers.layers]] -name = "other_lines" +name = "other_lines_z14_15" geometry_fieldname = "geometry" geometry_type = "linestring" id_fieldname = "osm_id" @@ -16,13 +16,42 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_other_lines_z14_20 + mv_other_lines_z14_15 +WHERE + geometry && !BBOX! +""" + +[[providers.layers]] +name = "other_lines_z16_20" +geometry_fieldname = "geometry" +geometry_type = "linestring" +id_fieldname = "osm_id" +sql = """ +SELECT + ST_AsMVTGeom(geometry, !BBOX!) AS geometry, + osm_id, + name, + class, + type, + start_date, + end_date, + start_decdate, + end_decdate, + {{LENGUAGES}} +FROM + mv_other_lines_z16_20 WHERE geometry && !BBOX! """ #######Maps [[maps.layers]] name = "other_lines" -provider_layer = "osm.other_lines" +provider_layer = "osm.other_lines_z14_15" min_zoom = 14 +max_zoom = 15 + +[[maps.layers]] +name = "other_lines" +provider_layer = "osm.other_lines_z16_20" +min_zoom = 16 max_zoom = 20 diff --git a/images/tiler-server/config/providers/other_points_centroids.toml b/images/tiler-server/config/providers/other_points_centroids.toml index 68472d54..5ba0d084 100644 --- a/images/tiler-server/config/providers/other_points_centroids.toml +++ b/images/tiler-server/config/providers/other_points_centroids.toml @@ -26,7 +26,7 @@ WHERE geometry_fieldname = "geometry" geometry_type = "point" id_fieldname = "osm_id" -name = "other_points_centroids_z10_11" +name = "other_points_centroids_z10_12" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, @@ -41,7 +41,7 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_other_points_centroids_z10_11 + mv_other_points_centroids_z10_12 WHERE geometry && !BBOX! """ @@ -50,7 +50,7 @@ WHERE geometry_fieldname = "geometry" geometry_type = "point" id_fieldname = "osm_id" -name = "other_points_centroids_z12_13" +name = "other_points_centroids_z13_15" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, @@ -65,31 +65,7 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_other_points_centroids_z12_13 -WHERE - geometry && !BBOX! -""" - -[[providers.layers]] -geometry_fieldname = "geometry" -geometry_type = "point" -id_fieldname = "osm_id" -name = "other_points_centroids_z14_15" -sql = """ -SELECT - ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - osm_id, - name, - class, - type, - area_m2, - start_date, - end_date, - start_decdate, - end_decdate, - {{LENGUAGES}} -FROM - mv_other_points_centroids_z14_15 + mv_other_points_centroids_z13_15 WHERE geometry && !BBOX! """ @@ -128,20 +104,14 @@ max_zoom = 9 [[maps.layers]] name = "other_points_centroids" -provider_layer = "osm.other_points_centroids_z10_11" +provider_layer = "osm.other_points_centroids_z10_12" min_zoom = 10 -max_zoom = 11 - -[[maps.layers]] -name = "other_points_centroids" -provider_layer = "osm.other_points_centroids_z12_13" -min_zoom = 12 -max_zoom = 13 +max_zoom = 12 [[maps.layers]] name = "other_points_centroids" -provider_layer = "osm.other_points_centroids_z14_15" -min_zoom = 14 +provider_layer = "osm.other_points_centroids_z13_15" +min_zoom = 13 max_zoom = 15 [[maps.layers]] diff --git a/images/tiler-server/config/providers/route_lines.toml b/images/tiler-server/config/providers/route_lines.toml index 9aa64d0a..883f4398 100644 --- a/images/tiler-server/config/providers/route_lines.toml +++ b/images/tiler-server/config/providers/route_lines.toml @@ -1,5 +1,5 @@ [[providers.layers]] -name = "route_lines_z5_6" +name = "route_lines_z5" geometry_fieldname = "geometry" geometry_type = "LineString" id_fieldname = "osm_id" @@ -67,12 +67,12 @@ SELECT route_bus_5_ref,route_bus_5_network,route_bus_5_network_wikidata,route_bus_5_operator,route_bus_5_name,route_bus_5_direction, route_bus_6_ref,route_bus_6_network,route_bus_6_network_wikidata,route_bus_6_operator,route_bus_6_name,route_bus_6_direction -FROM mv_routes_indexed_z5_6 +FROM mv_routes_indexed_z5 WHERE geometry && !BBOX! """ [[providers.layers]] -name = "route_lines_z7_8" +name = "route_lines_z6_7" geometry_fieldname = "geometry" geometry_type = "LineString" id_fieldname = "osm_id" @@ -140,12 +140,13 @@ SELECT route_bus_5_ref,route_bus_5_network,route_bus_5_network_wikidata,route_bus_5_operator,route_bus_5_name,route_bus_5_direction, route_bus_6_ref,route_bus_6_network,route_bus_6_network_wikidata,route_bus_6_operator,route_bus_6_name,route_bus_6_direction -FROM mv_routes_indexed_z7_8 +FROM mv_routes_indexed_z6_7 WHERE geometry && !BBOX! """ + [[providers.layers]] -name = "route_lines_z9_10" +name = "route_lines_z8_9" geometry_fieldname = "geometry" geometry_type = "LineString" id_fieldname = "osm_id" @@ -213,12 +214,12 @@ SELECT route_bus_5_ref,route_bus_5_network,route_bus_5_network_wikidata,route_bus_5_operator,route_bus_5_name,route_bus_5_direction, route_bus_6_ref,route_bus_6_network,route_bus_6_network_wikidata,route_bus_6_operator,route_bus_6_name,route_bus_6_direction -FROM mv_routes_indexed_z9_10 +FROM mv_routes_indexed_z8_9 WHERE geometry && !BBOX! """ [[providers.layers]] -name = "route_lines_z11_13" +name = "route_lines_z10_12" geometry_fieldname = "geometry" geometry_type = "LineString" id_fieldname = "osm_id" @@ -286,12 +287,12 @@ SELECT route_bus_5_ref,route_bus_5_network,route_bus_5_network_wikidata,route_bus_5_operator,route_bus_5_name,route_bus_5_direction, route_bus_6_ref,route_bus_6_network,route_bus_6_network_wikidata,route_bus_6_operator,route_bus_6_name,route_bus_6_direction -FROM mv_routes_indexed_z11_13 +FROM mv_routes_indexed_z10_12 WHERE geometry && !BBOX! """ [[providers.layers]] -name = "route_lines_z14_20" +name = "route_lines_z13_15" geometry_fieldname = "geometry" geometry_type = "LineString" id_fieldname = "osm_id" @@ -359,37 +360,116 @@ SELECT route_bus_5_ref,route_bus_5_network,route_bus_5_network_wikidata,route_bus_5_operator,route_bus_5_name,route_bus_5_direction, route_bus_6_ref,route_bus_6_network,route_bus_6_network_wikidata,route_bus_6_operator,route_bus_6_name,route_bus_6_direction - FROM mv_routes_indexed_z14_20 + FROM mv_routes_indexed_z13_15 +WHERE geometry && !BBOX! +""" + +[[providers.layers]] +name = "route_lines_z16_20" +geometry_fieldname = "geometry" +geometry_type = "LineString" +id_fieldname = "osm_id" +sql = """ +SELECT + ST_AsMVTGeom(geometry, !BBOX!) AS geometry, + osm_id, + start_decdate, + end_decdate, + start_date, + end_date, + -- ROAD + route_road_1_ref,route_road_1_network,route_road_1_network_wikidata,route_road_1_operator,route_road_1_name,route_road_1_direction, + route_road_2_ref,route_road_2_network,route_road_2_network_wikidata,route_road_2_operator,route_road_2_name,route_road_2_direction, + route_road_3_ref,route_road_3_network,route_road_3_network_wikidata,route_road_3_operator,route_road_3_name,route_road_3_direction, + route_road_4_ref,route_road_4_network,route_road_4_network_wikidata,route_road_4_operator,route_road_4_name,route_road_4_direction, + route_road_5_ref,route_road_5_network,route_road_5_network_wikidata,route_road_5_operator,route_road_5_name,route_road_5_direction, + route_road_6_ref,route_road_6_network,route_road_6_network_wikidata,route_road_6_operator,route_road_6_name,route_road_6_direction, + + -- TRAIN + route_train_1_ref,route_train_1_network,route_train_1_network_wikidata,route_train_1_operator,route_train_1_name,route_train_1_direction, + route_train_2_ref,route_train_2_network,route_train_2_network_wikidata,route_train_2_operator,route_train_2_name,route_train_2_direction, + route_train_3_ref,route_train_3_network,route_train_3_network_wikidata,route_train_3_operator,route_train_3_name,route_train_3_direction, + route_train_4_ref,route_train_4_network,route_train_4_network_wikidata,route_train_4_operator,route_train_4_name,route_train_4_direction, + route_train_5_ref,route_train_5_network,route_train_5_network_wikidata,route_train_5_operator,route_train_5_name,route_train_5_direction, + route_train_6_ref,route_train_6_network,route_train_6_network_wikidata,route_train_6_operator,route_train_6_name,route_train_6_direction, + + -- SUBWAY + route_subway_1_ref,route_subway_1_network,route_subway_1_network_wikidata,route_subway_1_operator,route_subway_1_name,route_subway_1_direction, + route_subway_2_ref,route_subway_2_network,route_subway_2_network_wikidata,route_subway_2_operator,route_subway_2_name,route_subway_2_direction, + route_subway_3_ref,route_subway_3_network,route_subway_3_network_wikidata,route_subway_3_operator,route_subway_3_name,route_subway_3_direction, + route_subway_4_ref,route_subway_4_network,route_subway_4_network_wikidata,route_subway_4_operator,route_subway_4_name,route_subway_4_direction, + route_subway_5_ref,route_subway_5_network,route_subway_5_network_wikidata,route_subway_5_operator,route_subway_5_name,route_subway_5_direction, + route_subway_6_ref,route_subway_6_network,route_subway_6_network_wikidata,route_subway_6_operator,route_subway_6_name,route_subway_6_direction, + + -- LIGHT_RAIL + route_light_rail_1_ref,route_light_rail_1_network,route_light_rail_1_network_wikidata,route_light_rail_1_operator,route_light_rail_1_name,route_light_rail_1_direction, + route_light_rail_2_ref,route_light_rail_2_network,route_light_rail_2_network_wikidata,route_light_rail_2_operator,route_light_rail_2_name,route_light_rail_2_direction, + route_light_rail_3_ref,route_light_rail_3_network,route_light_rail_3_network_wikidata,route_light_rail_3_operator,route_light_rail_3_name,route_light_rail_3_direction, + route_light_rail_4_ref,route_light_rail_4_network,route_light_rail_4_network_wikidata,route_light_rail_4_operator,route_light_rail_4_name,route_light_rail_4_direction, + route_light_rail_5_ref,route_light_rail_5_network,route_light_rail_5_network_wikidata,route_light_rail_5_operator,route_light_rail_5_name,route_light_rail_5_direction, + route_light_rail_6_ref,route_light_rail_6_network,route_light_rail_6_network_wikidata,route_light_rail_6_operator,route_light_rail_6_name,route_light_rail_6_direction, + + -- TRAM + route_tram_1_ref,route_tram_1_network,route_tram_1_network_wikidata,route_tram_1_operator,route_tram_1_name,route_tram_1_direction, + route_tram_2_ref,route_tram_2_network,route_tram_2_network_wikidata,route_tram_2_operator,route_tram_2_name,route_tram_2_direction, + route_tram_3_ref,route_tram_3_network,route_tram_3_network_wikidata,route_tram_3_operator,route_tram_3_name,route_tram_3_direction, + route_tram_4_ref,route_tram_4_network,route_tram_4_network_wikidata,route_tram_4_operator,route_tram_4_name,route_tram_4_direction, + route_tram_5_ref,route_tram_5_network,route_tram_5_network_wikidata,route_tram_5_operator,route_tram_5_name,route_tram_5_direction, + route_tram_6_ref,route_tram_6_network,route_tram_6_network_wikidata,route_tram_6_operator,route_tram_6_name,route_tram_6_direction, + + -- TROLLEYBUS + route_trolleybus_1_ref,route_trolleybus_1_network,route_trolleybus_1_network_wikidata,route_trolleybus_1_operator,route_trolleybus_1_name,route_trolleybus_1_direction, + route_trolleybus_2_ref,route_trolleybus_2_network,route_trolleybus_2_network_wikidata,route_trolleybus_2_operator,route_trolleybus_2_name,route_trolleybus_2_direction, + route_trolleybus_3_ref,route_trolleybus_3_network,route_trolleybus_3_network_wikidata,route_trolleybus_3_operator,route_trolleybus_3_name,route_trolleybus_3_direction, + route_trolleybus_4_ref,route_trolleybus_4_network,route_trolleybus_4_network_wikidata,route_trolleybus_4_operator,route_trolleybus_4_name,route_trolleybus_4_direction, + route_trolleybus_5_ref,route_trolleybus_5_network,route_trolleybus_5_network_wikidata,route_trolleybus_5_operator,route_trolleybus_5_name,route_trolleybus_5_direction, + route_trolleybus_6_ref,route_trolleybus_6_network,route_trolleybus_6_network_wikidata,route_trolleybus_6_operator,route_trolleybus_6_name,route_trolleybus_6_direction, + + -- BUS + route_bus_1_ref,route_bus_1_network,route_bus_1_network_wikidata,route_bus_1_operator,route_bus_1_name,route_bus_1_direction, + route_bus_2_ref,route_bus_2_network,route_bus_2_network_wikidata,route_bus_2_operator,route_bus_2_name,route_bus_2_direction, + route_bus_3_ref,route_bus_3_network,route_bus_3_network_wikidata,route_bus_3_operator,route_bus_3_name,route_bus_3_direction, + route_bus_4_ref,route_bus_4_network,route_bus_4_network_wikidata,route_bus_4_operator,route_bus_4_name,route_bus_4_direction, + route_bus_5_ref,route_bus_5_network,route_bus_5_network_wikidata,route_bus_5_operator,route_bus_5_name,route_bus_5_direction, + route_bus_6_ref,route_bus_6_network,route_bus_6_network_wikidata,route_bus_6_operator,route_bus_6_name,route_bus_6_direction + + FROM mv_routes_indexed_z16_20 WHERE geometry && !BBOX! """ #######Maps [[maps.layers]] name = "route_lines" -provider_layer = "osm.route_lines_z5_6" +provider_layer = "osm.route_lines_z5" min_zoom = 5 -max_zoom = 6 +max_zoom = 5 + +[[maps.layers]] +name = "route_lines" +provider_layer = "osm.route_lines_z6_7" +min_zoom = 6 +max_zoom = 7 [[maps.layers]] name = "route_lines" -provider_layer = "osm.route_lines_z7_8" -min_zoom = 7 -max_zoom = 8 +provider_layer = "osm.route_lines_z8_9" +min_zoom = 8 +max_zoom = 9 [[maps.layers]] name = "route_lines" -provider_layer = "osm.route_lines_z9_10" -min_zoom = 9 -max_zoom = 10 +provider_layer = "osm.route_lines_z10_12" +min_zoom = 10 +max_zoom = 12 [[maps.layers]] name = "route_lines" -provider_layer = "osm.route_lines_z11_13" -min_zoom = 11 -max_zoom = 13 +provider_layer = "osm.route_lines_z13_15" +min_zoom = 13 +max_zoom = 15 [[maps.layers]] name = "route_lines" -provider_layer = "osm.route_lines_z14_20" -min_zoom = 14 +provider_layer = "osm.route_lines_z16_20" +min_zoom = 16 max_zoom = 20 diff --git a/images/tiler-server/config/providers/transport_areas.toml b/images/tiler-server/config/providers/transport_areas.toml index b0aa1a4a..6ee9188b 100644 --- a/images/tiler-server/config/providers/transport_areas.toml +++ b/images/tiler-server/config/providers/transport_areas.toml @@ -2,7 +2,7 @@ geometry_fieldname = "geometry" geometry_type = "multipolygon" id_fieldname = "osm_id" -name = "transport_areas_z10_11" +name = "transport_areas_z10_12" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, @@ -17,7 +17,7 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_transport_areas_z10_11 + mv_transport_areas_z10_12 WHERE geometry && !BBOX! """ @@ -26,7 +26,7 @@ WHERE geometry_fieldname = "geometry" geometry_type = "multipolygon" id_fieldname = "osm_id" -name = "transport_areas_z12_13" +name = "transport_areas_z13_15" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, @@ -34,38 +34,14 @@ SELECT name, class, type, - - start_date, - end_date, - start_decdate, - end_decdate, - {{LENGUAGES}} -FROM - mv_transport_areas_z12_13 -WHERE - geometry && !BBOX! -""" - -[[providers.layers]] -geometry_fieldname = "geometry" -geometry_type = "multipolygon" -id_fieldname = "osm_id" -name = "transport_areas_z14_15" -sql = """ -SELECT - ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - osm_id, - name, - class, - type, - + area_m2, start_date, end_date, start_decdate, end_decdate, {{LENGUAGES}} FROM - mv_transport_areas_z14_15 + mv_transport_areas_z13_15 WHERE geometry && !BBOX! """ @@ -96,20 +72,14 @@ WHERE #######Maps [[maps.layers]] name = "transport_areas" -provider_layer = "osm.transport_areas_z10_11" +provider_layer = "osm.transport_areas_z10_12" min_zoom = 10 -max_zoom = 11 - -[[maps.layers]] -name = "transport_areas" -provider_layer = "osm.transport_areas_z12_13" -min_zoom = 12 -max_zoom = 13 +max_zoom = 12 [[maps.layers]] name = "transport_areas" -provider_layer = "osm.transport_areas_z14_15" -min_zoom = 14 +provider_layer = "osm.transport_areas_z13_15" +min_zoom = 13 max_zoom = 15 [[maps.layers]] diff --git a/images/tiler-server/config/providers/transport_lines.toml b/images/tiler-server/config/providers/transport_lines.toml index 9fa02b17..7ca1fd81 100644 --- a/images/tiler-server/config/providers/transport_lines.toml +++ b/images/tiler-server/config/providers/transport_lines.toml @@ -32,7 +32,7 @@ WHERE """ [[providers.layers]] -name = "transport_lines_z6" +name = "transport_lines_z6_7" geometry_fieldname = "geometry" geometry_type = "linestring" id_fieldname = "osm_id" @@ -59,81 +59,13 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_transport_lines_z6 + mv_transport_lines_z6_7 WHERE geometry && !BBOX! """ [[providers.layers]] -name = "transport_lines_z7" -geometry_fieldname = "geometry" -geometry_type = "linestring" -id_fieldname = "osm_id" -sql = """ -SELECT - ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - osm_id, - class, - member, - type, - ref, - service, - name, - electrified, - highspeed, - usage, - railway, - aeroway, - highway, - route, - start_date, - end_date, - start_decdate, - end_decdate, - {{LENGUAGES}} -FROM - mv_transport_lines_z7 -WHERE - geometry && !BBOX! -""" - -[[providers.layers]] -name = "transport_lines_z8" -geometry_fieldname = "geometry" -geometry_type = "linestring" -id_fieldname = "osm_id" -sql = """ -SELECT - ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - osm_id, - class, - member, - type, - tunnel, - bridge, - ref, - service, - name, - electrified, - highspeed, - usage, - railway, - aeroway, - highway, - route, - start_date, - end_date, - start_decdate, - end_decdate, - {{LENGUAGES}} -FROM - mv_transport_lines_z8 -WHERE - geometry && !BBOX! -""" - -[[providers.layers]] -name = "transport_lines_z9" +name = "transport_lines_z8_9" geometry_fieldname = "geometry" geometry_type = "linestring" id_fieldname = "osm_id" @@ -162,14 +94,13 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_transport_lines_z9 + mv_transport_lines_z8_9 WHERE geometry && !BBOX! """ - [[providers.layers]] -name = "transport_lines_z10_11" +name = "transport_lines_z10_12" geometry_fieldname = "geometry" geometry_type = "linestring" id_fieldname = "osm_id" @@ -198,14 +129,13 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_transport_lines_z10_11 + mv_transport_lines_z10_12 WHERE geometry && !BBOX! """ - [[providers.layers]] -name = "transport_lines_z12_13" +name = "transport_lines_z13_15" geometry_fieldname = "geometry" geometry_type = "linestring" id_fieldname = "osm_id" @@ -234,13 +164,13 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_transport_lines_z12_13 + mv_transport_lines_z13_15 WHERE geometry && !BBOX! """ [[providers.layers]] -name = "transport_lines_z14_20" +name = "transport_lines_z16_20" geometry_fieldname = "geometry" geometry_type = "linestring" id_fieldname = "osm_id" @@ -269,7 +199,7 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_transport_lines_z14_20 + mv_transport_lines_z16_20 WHERE geometry && !BBOX! """ @@ -283,42 +213,30 @@ max_zoom = 5 [[maps.layers]] name = "transport_lines" -provider_layer = "osm.transport_lines_z6" +provider_layer = "osm.transport_lines_z6_7" min_zoom = 6 -max_zoom = 6 - -[[maps.layers]] -name = "transport_lines" -provider_layer = "osm.transport_lines_z7" -min_zoom = 7 max_zoom = 7 [[maps.layers]] name = "transport_lines" -provider_layer = "osm.transport_lines_z8" +provider_layer = "osm.transport_lines_z8_9" min_zoom = 8 -max_zoom = 8 - -[[maps.layers]] -name = "transport_lines" -provider_layer = "osm.transport_lines_z9" -min_zoom = 9 max_zoom = 9 [[maps.layers]] name = "transport_lines" -provider_layer = "osm.transport_lines_z10_11" +provider_layer = "osm.transport_lines_z10_12" min_zoom = 10 -max_zoom = 11 +max_zoom = 12 [[maps.layers]] name = "transport_lines" -provider_layer = "osm.transport_lines_z12_13" -min_zoom = 12 -max_zoom = 13 +provider_layer = "osm.transport_lines_z13_15" +min_zoom = 13 +max_zoom = 15 [[maps.layers]] name = "transport_lines" -provider_layer = "osm.transport_lines_z14_20" -min_zoom = 14 +provider_layer = "osm.transport_lines_z16_20" +min_zoom = 16 max_zoom = 20 diff --git a/images/tiler-server/config/providers/transport_points_centroids.toml b/images/tiler-server/config/providers/transport_points_centroids.toml index 0d8439db..f0ffdbae 100644 --- a/images/tiler-server/config/providers/transport_points_centroids.toml +++ b/images/tiler-server/config/providers/transport_points_centroids.toml @@ -2,7 +2,7 @@ geometry_fieldname = "geometry" geometry_type = "point" id_fieldname = "osm_id" -name = "transport_points_centroids_z10_11" +name = "transport_points_centroids_z10_12" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, @@ -17,7 +17,7 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_transport_points_centroids_z10_11 + mv_transport_points_centroids_z10_12 WHERE geometry && !BBOX! """ @@ -26,7 +26,7 @@ WHERE geometry_fieldname = "geometry" geometry_type = "point" id_fieldname = "osm_id" -name = "transport_points_centroids_z12_13" +name = "transport_points_centroids_z13_15" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, @@ -41,31 +41,7 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_transport_points_centroids_z12_13 -WHERE - geometry && !BBOX! -""" - -[[providers.layers]] -geometry_fieldname = "geometry" -geometry_type = "point" -id_fieldname = "osm_id" -name = "transport_points_centroids_z14_15" -sql = """ -SELECT - ST_AsMVTGeom(geometry, !BBOX!) AS geometry, - osm_id, - name, - class, - type, - area_m2, - start_date, - end_date, - start_decdate, - end_decdate, - {{LENGUAGES}} -FROM - mv_transport_points_centroids_z14_15 + mv_transport_points_centroids_z13_15 WHERE geometry && !BBOX! """ @@ -96,20 +72,14 @@ WHERE #######Maps [[maps.layers]] name = "transport_points_centroids" -provider_layer = "osm.transport_points_centroids_z10_11" +provider_layer = "osm.transport_points_centroids_z10_12" min_zoom = 10 -max_zoom = 11 - -[[maps.layers]] -name = "transport_points_centroids" -provider_layer = "osm.transport_points_centroids_z12_13" -min_zoom = 12 -max_zoom = 13 +max_zoom = 12 [[maps.layers]] name = "transport_points_centroids" -provider_layer = "osm.transport_points_centroids_z14_15" -min_zoom = 14 +provider_layer = "osm.transport_points_centroids_z13_15" +min_zoom = 13 max_zoom = 15 [[maps.layers]] diff --git a/images/tiler-server/config/providers/water_areas.toml b/images/tiler-server/config/providers/water_areas.toml index 713c33b5..767800ed 100644 --- a/images/tiler-server/config/providers/water_areas.toml +++ b/images/tiler-server/config/providers/water_areas.toml @@ -16,7 +16,7 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_water_areas_z0_2_subdivided + mv_water_areas_z0_2 WHERE geometry && !BBOX! """ @@ -39,7 +39,7 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_water_areas_z3_5_subdivided + mv_water_areas_z3_5 WHERE geometry && !BBOX! """ @@ -63,7 +63,7 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_water_areas_z6_7_subdivided + mv_water_areas_z6_7 WHERE geometry && !BBOX! """ @@ -86,7 +86,7 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_water_areas_z8_9_subdivided + mv_water_areas_z8_9 WHERE geometry && !BBOX! """ diff --git a/images/tiler-server/config/providers/water_areas_centroids.toml b/images/tiler-server/config/providers/water_areas_centroids.toml index ca97adb2..9d5b54c2 100644 --- a/images/tiler-server/config/providers/water_areas_centroids.toml +++ b/images/tiler-server/config/providers/water_areas_centroids.toml @@ -48,7 +48,7 @@ WHERE geometry_fieldname = "geometry" geometry_type = "point" id_fieldname = "osm_id" -name = "water_areas_centroid_z13_20" +name = "water_areas_centroid_z13_15" sql = """ SELECT ST_AsMVTGeom(geometry, !BBOX!) AS geometry, @@ -62,7 +62,30 @@ SELECT end_decdate, {{LENGUAGES}} FROM - mv_water_areas_centroids_z13_20 + mv_water_areas_centroids_z13_15 +WHERE + geometry && !BBOX! +""" + +[[providers.layers]] +geometry_fieldname = "geometry" +geometry_type = "point" +id_fieldname = "osm_id" +name = "water_areas_centroid_z16_20" +sql = """ +SELECT + ST_AsMVTGeom(geometry, !BBOX!) AS geometry, + osm_id, + name, + type, + area, + start_date, + end_date, + start_decdate, + end_decdate, + {{LENGUAGES}} +FROM + mv_water_areas_centroids_z16_20 WHERE geometry && !BBOX! """ @@ -83,6 +106,12 @@ max_zoom = 12 [[maps.layers]] name = "water_areas_centroids" -provider_layer = "osm.water_areas_centroid_z13_20" +provider_layer = "osm.water_areas_centroid_z13_15" min_zoom = 13 +max_zoom = 15 + +[[maps.layers]] +name = "water_areas_centroids" +provider_layer = "osm.water_areas_centroid_z16_20" +min_zoom = 16 max_zoom = 20