From a8e6573ba86cf0a9d7bcd13ae55623703adbd52e Mon Sep 17 00:00:00 2001 From: benedikt-brandtner-bikemap Date: Mon, 10 Jul 2023 11:50:31 +0200 Subject: [PATCH] boundary.sql parallelization issue fix (#1551) VectorTiles generated via the [openmaptiles-tools](https://github.com/openmaptiles/openmaptiles-tools) toolchain and using the OpenMaptiles-SQL-Layers as the query-source result in tiles which can contain duplicated keys. This is because PostGIS `ST_AsMVT` is used to generate the Tiles and due to the way they [implemented parallelization](https://trac.osgeo.org/postgis/ticket/4310). Although it is not prohibited by the Mapbox-Vector-Tile-Specification MapBox as well as MapLibre depending on version either throw a lot of warnings or even crash when encountering tiles with duplicated keys. https://github.com/mapbox/vector-tile/issues/55 https://github.com/maplibre/maplibre-native/issues/795 After investigating I identified the boundary layer in zoom-leves 1 - 4 as the only layers containing duplicated keys. --- layers/boundary/boundary.sql | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/layers/boundary/boundary.sql b/layers/boundary/boundary.sql index cfe39531..e95de1f2 100644 --- a/layers/boundary/boundary.sql +++ b/layers/boundary/boundary.sql @@ -348,7 +348,8 @@ FROM ne_110m_admin_0_boundary_lines_land_gen_z0 -- etldoc: ne_50m_admin_0_boundary_lines_land_gen_z1 -> boundary_z1 -- etldoc: ne_10m_admin_1_states_provinces_lines_gen_z1 -> boundary_z1 -- etldoc: osm_border_disp_linestring_gen_z1 -> boundary_z1 -CREATE OR REPLACE VIEW boundary_z1 AS +DROP MATERIALIZED VIEW IF EXISTS boundary_z1 CASCADE; +CREATE MATERIALIZED VIEW boundary_z1 AS ( SELECT geometry, admin_level, @@ -380,12 +381,14 @@ SELECT geometry, maritime FROM osm_border_disp_linestring_gen_z1 ); +CREATE INDEX IF NOT EXISTS boundary_z1_idx ON boundary_z1 USING gist (geometry); -- etldoc: ne_50m_admin_0_boundary_lines_land_gen_z2 -> boundary_z2 -- etldoc: ne_10m_admin_1_states_provinces_lines_gen_z2 -> boundary_z2 -- etldoc: osm_border_disp_linestring_gen_z2 -> boundary_z2 -CREATE OR REPLACE VIEW boundary_z2 AS +DROP MATERIALIZED VIEW IF EXISTS boundary_z2 CASCADE; +CREATE MATERIALIZED VIEW boundary_z2 AS ( SELECT geometry, admin_level, @@ -417,11 +420,13 @@ SELECT geometry, maritime FROM osm_border_disp_linestring_gen_z2 ); +CREATE INDEX IF NOT EXISTS boundary_z2_idx ON boundary_z2 USING gist (geometry); -- etldoc: ne_50m_admin_0_boundary_lines_land_gen_z3 -> boundary_z3 -- etldoc: ne_10m_admin_1_states_provinces_lines_gen_z3 -> boundary_z3 -- etldoc: osm_border_disp_linestring_gen_z3 -> boundary_z3 -CREATE OR REPLACE VIEW boundary_z3 AS +DROP MATERIALIZED VIEW IF EXISTS boundary_z3 CASCADE; +CREATE MATERIALIZED VIEW boundary_z3 AS ( SELECT geometry, admin_level, @@ -453,11 +458,13 @@ SELECT geometry, maritime FROM osm_border_disp_linestring_gen_z3 ); +CREATE INDEX IF NOT EXISTS boundary_z3_idx ON boundary_z3 USING gist (geometry); -- etldoc: ne_10m_admin_0_boundary_lines_land_gen_z4 -> boundary_z4 -- etldoc: ne_10m_admin_1_states_provinces_lines_gen_z4 -> boundary_z4 -- etldoc: osm_border_linestring_gen_z4 -> boundary_z4 -CREATE OR REPLACE VIEW boundary_z4 AS +DROP MATERIALIZED VIEW IF EXISTS boundary_z4 CASCADE; +CREATE MATERIALIZED VIEW boundary_z4 AS ( SELECT geometry, admin_level, @@ -489,6 +496,7 @@ SELECT geometry, maritime FROM osm_border_linestring_gen_z4 ); +CREATE INDEX IF NOT EXISTS boundary_z4_idx ON boundary_z4 USING gist (geometry); -- etldoc: osm_border_linestring_gen_z5 -> boundary_z5 CREATE OR REPLACE VIEW boundary_z5 AS