Compute separate concurrency_index on osm_route_member (#1135)

Closes #1134 

Adds a `concurrency_index` column to `osm_route_member` as described in #1134.  For example, listing concurrencies on a [segment of the Washington Bridge](https://www.openstreetmap.org/way/43080535) in Providence, Rhode Island, USA:

```
openmaptiles=# select osm_id, network, ref, network_type, name, concurrency_index from osm_route_member where member=43080535 order by concurrency_index asc;
  osm_id  | network | ref | network_type  |     name      | concurrency_index
----------+---------+-----+---------------+---------------+-------------------
 -1694950 | US:I    | 195 | us-interstate | I 195 (RI/MA) |                 1
 -2308410 | US:US   | 6   | us-highway    | US 6 (RI)     |                 2
 -1347856 | US:US   | 1A  | us-highway    | US 1A (RI)    |                 3
 -2309143 | US:US   | 44  | us-highway    | US 44 (RI)    |                 4
(4 rows)
```
This commit is contained in:
Brian Sperlongano 2021-07-02 09:00:25 -04:00 committed by GitHub
parent 3f70b878e2
commit 1b0b1fd121
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 12 deletions

View File

@ -91,3 +91,12 @@ CREATE INDEX IF NOT EXISTS osm_route_member_name_idx ON osm_route_member ("name"
CREATE INDEX IF NOT EXISTS osm_route_member_ref_idx ON osm_route_member ("ref"); 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"); CREATE INDEX IF NOT EXISTS osm_route_member_network_type_idx ON osm_route_member ("network_type");
ALTER TABLE osm_route_member ADD COLUMN IF NOT EXISTS concurrency_index int;
INSERT INTO osm_route_member (id, concurrency_index)
SELECT
id,
ROW_NUMBER() over (PARTITION BY member ORDER BY network_type, network, LENGTH(ref), ref) AS concurrency_index
FROM osm_route_member
ON CONFLICT (id) DO UPDATE SET concurrency_index = EXCLUDED.concurrency_index;

View File

@ -42,16 +42,12 @@ FROM (
CASE WHEN highway IN ('footway', 'steps') THEN layer END AS layer, CASE WHEN highway IN ('footway', 'steps') THEN layer END AS layer,
CASE WHEN highway IN ('footway', 'steps') THEN level END AS level, CASE WHEN highway IN ('footway', 'steps') THEN level END AS level,
CASE WHEN highway IN ('footway', 'steps') THEN indoor END AS indoor, CASE WHEN highway IN ('footway', 'steps') THEN indoor END AS indoor,
ROW_NUMBER() OVER (PARTITION BY hl.osm_id
ORDER BY rm.network_type) AS "rank",
hl.z_order hl.z_order
FROM osm_highway_linestring hl FROM osm_highway_linestring hl
LEFT JOIN osm_route_member rm ON LEFT OUTER JOIN osm_route_member rm ON rm.member = hl.osm_id AND rm.concurrency_index=1
rm.member = hl.osm_id
WHERE (hl.name <> '' OR hl.ref <> '') WHERE (hl.name <> '' OR hl.ref <> '')
AND NULLIF(hl.highway, '') IS NOT NULL AND NULLIF(hl.highway, '') IS NOT NULL
) AS t ) AS t;
WHERE ("rank" = 1 OR "rank" IS NULL);
CREATE 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_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(name, ''), coalesce(ref, ''));
CREATE INDEX IF NOT EXISTS osm_transportation_name_network_geometry_idx ON osm_transportation_name_network USING gist (geometry); CREATE INDEX IF NOT EXISTS osm_transportation_name_network_geometry_idx ON osm_transportation_name_network USING gist (geometry);
@ -308,18 +304,14 @@ BEGIN
CASE WHEN highway IN ('footway', 'steps') THEN layer END AS layer, CASE WHEN highway IN ('footway', 'steps') THEN layer END AS layer,
CASE WHEN highway IN ('footway', 'steps') THEN level END AS level, CASE WHEN highway IN ('footway', 'steps') THEN level END AS level,
CASE WHEN highway IN ('footway', 'steps') THEN indoor END AS indoor, CASE WHEN highway IN ('footway', 'steps') THEN indoor END AS indoor,
ROW_NUMBER() OVER (PARTITION BY hl.osm_id
ORDER BY rm.network_type) AS "rank",
hl.z_order hl.z_order
FROM osm_highway_linestring hl FROM osm_highway_linestring hl
JOIN transportation_name.network_changes AS c ON JOIN transportation_name.network_changes AS c ON
hl.osm_id = c.osm_id hl.osm_id = c.osm_id
LEFT JOIN osm_route_member rm ON LEFT OUTER JOIN osm_route_member rm ON rm.member = hl.osm_id AND rm.concurrency_index=1
rm.member = hl.osm_id
WHERE (hl.name <> '' OR hl.ref <> '') WHERE (hl.name <> '' OR hl.ref <> '')
AND NULLIF(hl.highway, '') IS NOT NULL AND NULLIF(hl.highway, '') IS NOT NULL
) AS t ) AS t;
WHERE ("rank" = 1 OR "rank" IS NULL);
-- noinspection SqlWithoutWhere -- noinspection SqlWithoutWhere
DELETE FROM transportation_name.network_changes; DELETE FROM transportation_name.network_changes;