Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Fix name-based way fragmentation in transportation_name #1295

Merged
merged 18 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions layers/transportation_name/highway_name.sql
Original file line number Diff line number Diff line change
@@ -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;


22 changes: 5 additions & 17 deletions layers/transportation_name/transportation_name.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ CREATE OR REPLACE FUNCTION layer_transportation_name(bbox geometry, zoom_level i
AS
$$
SELECT geometry,
name,
COALESCE(name_en, name) AS name_en,
COALESCE(name_de, name, name_en) AS name_de,
tags->'name',
ZeLonewolf marked this conversation as resolved.
Show resolved Hide resolved
COALESCE(tags->'name_en', tags->'name') AS name_en,
COALESCE(tags->'name_de', tags->'name', tags->'name_en') AS name_de,
ZeLonewolf marked this conversation as resolved.
Show resolved Hide resolved
tags,
ref,
NULLIF(LENGTH(ref), 0) AS ref_length,
Expand Down Expand Up @@ -93,9 +93,6 @@ FROM (

-- etldoc: osm_transportation_name_linestring -> layer_transportation_name:z12
SELECT geometry,
name,
name_en,
name_de,
"tags",
ref,
highway,
Expand All @@ -109,16 +106,13 @@ FROM (
indoor
FROM osm_transportation_name_linestring
WHERE zoom_level = 12
AND LineLabel(zoom_level, COALESCE(name, ref), geometry)
AND LineLabel(zoom_level, COALESCE(tags->'name', tags->'ref'), geometry)
AND (highway_class(highway, '', subclass) NOT IN ('minor', 'track', 'path') OR highway='shipway')
AND NOT highway_is_link(highway)
UNION ALL

-- etldoc: osm_transportation_name_linestring -> layer_transportation_name:z13
SELECT geometry,
name,
name_en,
name_de,
"tags",
ref,
highway,
Expand All @@ -132,15 +126,12 @@ FROM (
indoor
FROM osm_transportation_name_linestring
WHERE zoom_level = 13
AND LineLabel(zoom_level, COALESCE(name, ref), geometry)
AND LineLabel(zoom_level, COALESCE(tags->'name', tags->'ref'), geometry)
AND (highway_class(highway, '', subclass) NOT IN ('track', 'path') OR highway='shipway')
UNION ALL

-- etldoc: osm_transportation_name_linestring -> layer_transportation_name:z14_
SELECT geometry,
name,
name_en,
name_de,
"tags",
ref,
highway,
Expand All @@ -159,9 +150,6 @@ FROM (
-- etldoc: osm_highway_point -> layer_transportation_name:z10
SELECT
p.geometry,
p.name,
p.name_en,
p.name_de,
p.tags,
p.tags->'ref',
(
Expand Down
1 change: 1 addition & 0 deletions layers/transportation_name/transportation_name.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ layer:
query: (SELECT geometry, name, name_en, name_de, {name_languages}, ref, ref_length, network::text, class::text, subclass, brunnel, layer, level, indoor, route_1, route_2, route_3, route_4, route_5, route_6 FROM layer_transportation_name(!bbox!, z(!scale_denominator!))) AS t
schema:
- ./highway_classification.sql
- ./highway_name.sql
- ./update_transportation_name.sql
- ./transportation_name.sql
datasources:
Expand Down
141 changes: 31 additions & 110 deletions layers/transportation_name/update_transportation_name.sql

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions tests/import/500_import-highway.osm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
<node id="500052" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="33.5" lon="-90.05" />
<node id="500061" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="33.0" lon="-90.06" />
<node id="500062" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="33.5" lon="-90.06" />
<node id="500071" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="33.0" lon="-90.07" />
<node id="500072" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="33.5" lon="-90.07" />
<node id="500081" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="34.0" lon="-90.07" />
<node id="500091" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="34.5" lon="-90.07" />
<node id="500101" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="33.0" lon="-90.08" />
<node id="500102" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="33.5" lon="-90.08" />
<node id="500111" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="34.0" lon="-90.08" />
<node id="500121" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="34.5" lon="-90.08" />

<way id="5000" version="1" timestamp="2019-01-01T00:00:00Z" visible="true">
<nd ref="500001" />
Expand Down Expand Up @@ -65,4 +73,49 @@
<tag k="highway" v="track"/>
<tag k="name" v="OpenMapTiles Track"/>
</way>
<<<<<<< HEAD

<!-- Test way stitching -->
<way id="5007" version="1" timestamp="2019-01-01T00:00:00Z" visible="true">
<nd ref="500071" />
<nd ref="500072" />
<tag k="highway" v="secondary"/>
<tag k="name" v="OpenMapTiles Secondary 2"/>
</way>
<way id="5008" version="1" timestamp="2019-01-01T00:00:00Z" visible="true">
<nd ref="500072" />
<nd ref="500081" />
<tag k="highway" v="secondary"/>
<tag k="name" v="OpenMapTiles Secondary 2"/>
</way>
<way id="5009" version="1" timestamp="2019-01-01T00:00:00Z" visible="true">
<nd ref="500081" />
<nd ref="500091" />
<tag k="highway" v="secondary"/>
<tag k="name" v="OpenMapTiles Secondary 2"/>
</way>

<!-- Test disrupted way stitching -->
<way id="5010" version="1" timestamp="2019-01-01T00:00:00Z" visible="true">
<nd ref="500101" />
<nd ref="500102" />
<tag k="highway" v="secondary"/>
<tag k="bicycle" v="yes"/>
<tag k="name" v="OpenMapTiles Secondary 3"/>
</way>
<way id="5011" version="1" timestamp="2019-01-01T00:00:00Z" visible="true">
<nd ref="500102" />
<nd ref="500111" />
<tag k="highway" v="secondary"/>
<tag k="bridge" v="yes"/>
<tag k="layer" v="1"/>
<tag k="toll" v="yes"/>
<tag k="name" v="OpenMapTiles Secondary 3 (Toll)"/>
</way>
<way id="5012" version="1" timestamp="2019-01-01T00:00:00Z" visible="true">
<nd ref="500111" />
<nd ref="500121" />
<tag k="highway" v="secondary"/>
<tag k="name" v="OpenMapTiles Secondary 3"/>
</way>
</osm>
26 changes: 16 additions & 10 deletions tests/test-post-import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ BEGIN

-- Verify that road classifications show up at the right zoom level
SELECT COUNT(*) INTO cnt FROM osm_transportation_merge_linestring_gen_z4 WHERE highway='motorway';
IF cnt <> 1 THEN
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring z4 motorway count expected 1, got ' || cnt);
IF cnt < 1 THEN
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring z4 motorway count expected >=1, got ' || cnt);
END IF;

SELECT COUNT(*) INTO cnt FROM osm_transportation_merge_linestring_gen_z4 WHERE highway='trunk';
Expand All @@ -83,8 +83,8 @@ BEGIN
END IF;

SELECT COUNT(*) INTO cnt FROM osm_transportation_merge_linestring_gen_z5 WHERE highway='trunk';
IF cnt <> 1 THEN
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring z5 trunk count expected 1, got ' || cnt);
IF cnt < 1 THEN
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring z5 trunk count expected >=1, got ' || cnt);
END IF;

SELECT COUNT(*) INTO cnt FROM osm_transportation_merge_linestring_gen_z6 WHERE highway='primary';
Expand All @@ -93,8 +93,8 @@ BEGIN
END IF;

SELECT COUNT(*) INTO cnt FROM osm_transportation_merge_linestring_gen_z7 WHERE highway='primary';
IF cnt <> 1 THEN
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring z7 primary count expected 1, got ' || cnt);
IF cnt < 1 THEN
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring z7 primary count expected >=1, got ' || cnt);
END IF;

SELECT COUNT(*) INTO cnt FROM osm_transportation_merge_linestring_gen_z8 WHERE highway='secondary';
Expand All @@ -103,8 +103,8 @@ BEGIN
END IF;

SELECT COUNT(*) INTO cnt FROM osm_transportation_merge_linestring_gen_z9 WHERE highway='secondary';
IF cnt <> 1 THEN
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring z9 secondary count expected 1, got ' || cnt);
IF cnt < 1 THEN
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring z9 secondary count expected >=1, got ' || cnt);
END IF;

SELECT COUNT(*) INTO cnt FROM osm_transportation_merge_linestring_gen_z10 WHERE highway='tertiary';
Expand All @@ -113,8 +113,8 @@ BEGIN
END IF;

SELECT COUNT(*) INTO cnt FROM osm_transportation_merge_linestring_gen_z11 WHERE highway='tertiary';
IF cnt <> 1 THEN
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring z11 tertiary count expected 1, got ' || cnt);
IF cnt < 1 THEN
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring z11 tertiary count expected >=1, got ' || cnt);
END IF;

SELECT COUNT(*) INTO cnt FROM osm_transportation_merge_linestring_gen_z11 WHERE highway IN ('service', 'track');
Expand All @@ -133,6 +133,12 @@ BEGIN
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring z9 import tags expected 1, got ' || cnt);
END IF;

-- Same-named road split into 3 parts, because the middle segment is tagged toll=yes
SELECT COUNT(*) INTO cnt FROM osm_transportation_name_linestring WHERE tags->'name' = 'OpenMapTiles Secondary 3';
IF cnt <> 2 THEN
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_linestring split road count expected 2, got ' || cnt);
END IF;

END;

$$
Expand Down
9 changes: 8 additions & 1 deletion tests/test-post-update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ BEGIN
INSERT INTO omt_test_failures VALUES(400, 'update', 'osm_border_linestring city count expected 2, got ' || cnt);
END IF;

-- Test 500: Verify tags changed
-- Test 500: Highways
-- Same-named road previous split into 3 parts, now merged because the middle segment had toll=yes removed
SELECT COUNT(*) INTO cnt FROM osm_transportation_name_linestring WHERE tags->'name' = 'OpenMapTiles Secondary 3';
IF cnt <> 1 THEN
INSERT INTO omt_test_failures VALUES(500, 'update', 'osm_transportation_linestring unsplit road count expected 1, got ' || cnt);
END IF;

-- Verify tags changed
SELECT COUNT(*) INTO cnt FROM osm_transportation_merge_linestring_gen_z9
WHERE is_tunnel = TRUE
AND is_bridge = FALSE
Expand Down
16 changes: 15 additions & 1 deletion tests/update/500_update-highway.osc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-->
<modify>
<!-- Change tags -->
<way id="5003" version="2" timestamp="2019-01-01T00:00:00Z" visible="true">
<way id="5003" version="2" timestamp="2020-01-02T00:00:00Z" visible="true">
<nd ref="500031" />
<nd ref="500032" />
<tag k="highway" v="secondary"/>
Expand All @@ -19,5 +19,19 @@
<tag k="horse" v="yes"/>
<tag k="foot" v="yes"/>
</way>

<!-- Remove toll to make way match adjoining ways -->
<way id="5010" version="2" timestamp="2019-01-01T00:00:00Z" visible="true">
<nd ref="500101" />
<nd ref="500102" />
<tag k="highway" v="secondary"/>
<tag k="name" v="OpenMapTiles Secondary 3"/>
</way>
<way id="5011" version="2" timestamp="2020-01-02T00:00:00Z" visible="true">
<nd ref="500102" />
<nd ref="500111" />
<tag k="highway" v="secondary"/>
<tag k="name" v="OpenMapTiles Secondary 3"/>
</way>
</modify>
</osmChange>