BUGFIX: Fix name-based way fragmentation in transportation_name (#1295)
I discovered this bug while investigating issues with the updates process related to #1190 #1292, and #814. The `transportation_name` layer produces slightly different `tags` hstore values in the `osm_transportation_name_linestring` table during the initial import versus when running an update. As currently written, the import code produces null-value keys in the `tags` column, while the update code suppresses them. This PR removes that difference and makes the import code use same method that is currently used in the update code. With a test case I've written, the import code produces a tags hstore that looks like this: `"name"=>"OpenMapTiles Secondary 2", "name:de"=>NULL, "name:en"=>NULL, "name_int"=>"OpenMapTiles Secondary 2", "name:latin"=>"OpenMapTiles Secondary 2"` ...while the update code produces a tags hstore that looks like this: `"name"=>"OpenMapTiles Secondary 2", "name_int"=>"OpenMapTiles Secondary 2", "name:latin"=>"OpenMapTiles Secondary 2"` Note the missing NULL values. This bug causes a small amount of space wastage after an update is run, because the update matching code detects the `tags` value as different, resulting in a duplicate copy of the tags value if that row is updated. This causes duplicate objects and breaks GROUP BY clauses that expect to group same-tagged features together. I've tested this by inspection of a generated mbtiles, database spot checks, and the unit test code included in this PR.
This commit is contained in:
committed by
GitHub
parent
0cff3449b5
commit
ec74480414
15
layers/transportation/highway_name.sql
Normal file
15
layers/transportation/highway_name.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
CREATE OR REPLACE FUNCTION transportation_name_tags(geometry geometry, tags hstore, name text, name_en text, name_de text) RETURNS hstore AS
|
||||
$$
|
||||
SELECT hstore(string_agg(nullif(slice_language_tags(tags ||
|
||||
hstore(ARRAY [
|
||||
'name', CASE WHEN length(name) > 15 THEN osml10n_street_abbrev_all(name) ELSE NULLIF(name, '') END,
|
||||
'name:en', CASE WHEN length(name_en) > 15 THEN osml10n_street_abbrev_en(name_en) ELSE NULLIF(name_en, '') END,
|
||||
'name:de', CASE WHEN length(name_de) > 15 THEN osml10n_street_abbrev_de(name_de) ELSE NULLIF(name_de, '') END
|
||||
]))::text,
|
||||
''), ','))
|
||||
|| get_basic_names(tags, geometry);
|
||||
$$ LANGUAGE SQL IMMUTABLE
|
||||
STRICT
|
||||
PARALLEL SAFE;
|
||||
|
||||
|
||||
@@ -200,6 +200,7 @@ layer:
|
||||
schema:
|
||||
- ./network_type.sql
|
||||
- ./class.sql
|
||||
- ./highway_name.sql
|
||||
- ./update_route_member.sql
|
||||
- ./update_transportation_merge.sql
|
||||
- ./transportation.sql
|
||||
|
||||
@@ -12,9 +12,6 @@ CREATE TABLE IF NOT EXISTS osm_transportation_name_network AS
|
||||
SELECT
|
||||
geometry,
|
||||
osm_id,
|
||||
name,
|
||||
name_en,
|
||||
name_de,
|
||||
tags,
|
||||
ref,
|
||||
highway,
|
||||
@@ -32,10 +29,7 @@ FROM (
|
||||
SELECT DISTINCT ON (hl.osm_id)
|
||||
hl.geometry,
|
||||
hl.osm_id,
|
||||
CASE WHEN length(hl.name) > 15 THEN osml10n_street_abbrev_all(hl.name) ELSE NULLIF(hl.name, '') END AS "name",
|
||||
CASE WHEN length(hl.name_en) > 15 THEN osml10n_street_abbrev_en(hl.name_en) ELSE NULLIF(hl.name_en, '') END AS "name_en",
|
||||
CASE WHEN length(hl.name_de) > 15 THEN osml10n_street_abbrev_de(hl.name_de) ELSE NULLIF(hl.name_de, '') END AS "name_de",
|
||||
slice_language_tags(hl.tags) AS tags,
|
||||
transportation_name_tags(hl.geometry, hl.tags, hl.name, hl.name_en, hl.name_de) AS tags,
|
||||
rm1.network_type,
|
||||
CASE
|
||||
WHEN rm1.network_type IS NOT NULL AND rm1.ref::text <> ''
|
||||
@@ -68,7 +62,7 @@ FROM (
|
||||
AND hl.highway <> ''
|
||||
) AS t;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS osm_transportation_name_network_osm_id_idx ON osm_transportation_name_network (osm_id);
|
||||
CREATE INDEX IF NOT EXISTS osm_transportation_name_network_name_ref_idx ON osm_transportation_name_network (coalesce(name, ''), coalesce(ref, ''));
|
||||
CREATE INDEX IF NOT EXISTS osm_transportation_name_network_name_ref_idx ON osm_transportation_name_network (coalesce(tags->'name', ''), coalesce(ref, ''));
|
||||
CREATE INDEX IF NOT EXISTS osm_transportation_name_network_geometry_idx ON osm_transportation_name_network USING gist (geometry);
|
||||
|
||||
-- Improve performance of the sql in transportation/update_route_member.sql
|
||||
|
||||
Reference in New Issue
Block a user