Skip to content

Commit

Permalink
Coalesce duplicate route concurrencies (#1361)
Browse files Browse the repository at this point in the history
# Problem description
#1128 introduced route relation concurrency information in OpenMapTiles via the `route_X` attributes.  The original implementation assumed that there would be a single route relation for each `network` and `ref` pair.  However, it is increasingly common practice to tag a separate route relation for each direction of a route in order to provide awareness to routers and other data consumers of the directionality of a route.  This standard and growing practice is described on the [OSM wiki page on route directions](https://wiki.openstreetmap.org/wiki/Route_directions).  Thus, the naïve implementation of #1128 caused duplicate entries to be added as `route_X` attributes in the case where separate route relations were used for directional routes.

# Solution description
This PR adds grouping when computing route concurrency information, such that duplicate entries are coalesced in a predictable way.  Since this grouping is done only within a route membership join of a single member way, the computational complexity should be trivial.
  • Loading branch information
ZeLonewolf committed Jan 26, 2023
1 parent efa6b27 commit bc9bbd2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
11 changes: 11 additions & 0 deletions layers/transportation/update_route_member.sql
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ CREATE INDEX IF NOT EXISTS osm_route_member_ref_idx ON osm_route_member ("ref");

CREATE INDEX IF NOT EXISTS osm_route_member_network_type_idx ON osm_route_member ("network_type");

/**
* Discard duplicate routes
*/
DELETE FROM osm_route_member WHERE id IN
(SELECT id
FROM (SELECT id,
ROW_NUMBER() OVER (partition BY member, network, ref ORDER BY id) AS rnum
FROM osm_route_member) t
WHERE t.rnum > 1);
CREATE UNIQUE INDEX IF NOT EXISTS osm_route_member_network_ref_idx ON osm_route_member ("member", "network", "ref");

CREATE INDEX IF NOT EXISTS osm_highway_linestring_osm_id_idx ON osm_highway_linestring ("osm_id");
CREATE UNIQUE INDEX IF NOT EXISTS osm_highway_linestring_gen_z11_osm_id_idx ON osm_highway_linestring_gen_z11 ("osm_id");

Expand Down
18 changes: 18 additions & 0 deletions tests/import/500_import-highway.osm
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,22 @@
<tag k="route" v="hiking"/>
<tag k="network" v="nwn"/>
</relation>

<!-- Route Concurrency de-duplication -->
<relation id="515" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" changeset="1" user="u" uid="1">
<member type="way" ref="5000" role=""/>
<tag k="type" v="route"/>
<tag k="route" v="road"/>
<tag k="network" v="US:I"/>
<tag k="ref" v="95"/>
<tag k="description" v="I-95 Northbound"/>
</relation>
<relation id="516" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" changeset="1" user="u" uid="1">
<member type="way" ref="5000" role=""/>
<tag k="type" v="route"/>
<tag k="route" v="road"/>
<tag k="network" v="US:I"/>
<tag k="ref" v="95"/>
<tag k="description" v="I-95 Southbound"/>
</relation>
</osm>
7 changes: 7 additions & 0 deletions tests/test-post-import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ BEGIN
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_transportation_name_linestring z12 route_rank expected 1, got ' || cnt);
END IF;

-- Duplicate route concurrencies collapsed
SELECT COUNT(*) INTO cnt FROM osm_route_member
WHERE network='US:I' AND ref='95';
IF cnt <> 1 THEN
INSERT INTO omt_test_failures VALUES(500, 'import', 'osm_route_member 1 route membership expected, got ' || cnt);
END IF;

-- Test 600

-- verify that atms are imported with correct name which can come from tags like operator or network
Expand Down

0 comments on commit bc9bbd2

Please sign in to comment.