Skip to content

Commit

Permalink
Merge pull request #1460 from tilezen/zerebubuth/1387-business-and-sp…
Browse files Browse the repository at this point in the history
…ur-routes

Add route modifier information to network.
  • Loading branch information
zerebubuth authored Dec 18, 2017

Verified

This commit was signed with the committer’s verified signature. The key has expired.
BridgeAR Ruben Bridgewater
2 parents 04974a5 + 82e1f9a commit fcdbee2
Showing 3 changed files with 63 additions and 2 deletions.
29 changes: 28 additions & 1 deletion data/functions.sql
Original file line number Diff line number Diff line change
@@ -83,6 +83,33 @@ BEGIN
END;
$$ LANGUAGE plpgsql IMMUTABLE;

-- mz_modify_network returns an hstore of {route, network, ref}
-- where the network has been modified according to the
-- modifier tag, if there is any.
CREATE OR REPLACE FUNCTION mz_modify_network(
tags hstore)
RETURNS hstore AS $$
DECLARE
network text := tags->'network';
modifier text := tags->'modifier';
BEGIN
RETURN
tags ||
hstore('network',
CASE WHEN
network LIKE 'US:%' AND
modifier IN ('Business', 'Spur', 'Truck', 'Alternate', 'Bypass',
'Connector', 'Historic', 'Toll', 'Scenic') AND
POSITION(modifier IN network) = 0
THEN
network || ':' || modifier
ELSE
network
END
);
END;
$$ LANGUAGE plpgsql IMMUTABLE;

-- mz_get_rel_networks returns a list of triples of route type,
-- network and ref tags, or NULL, for a given way ID.
--
@@ -100,7 +127,7 @@ FROM (
unnest(tags) AS unnested
FROM (
SELECT
hstore(tags)->ARRAY['route','network','ref'] AS tags
mz_modify_network(hstore(tags))->ARRAY['route','network','ref'] AS tags
FROM
planet_osm_rels
WHERE
2 changes: 1 addition & 1 deletion docs/layers.md
Original file line number Diff line number Diff line change
@@ -1048,7 +1048,7 @@ To improve performance, some road segments are merged at low and mid-zooms. To f
* `min_zoom`: a suggestion for which zoom to draw a feature. The value is a float.
* `ref`: Commonly-used reference for roads, for example "I 90" for Interstate 90. To use with shields, see `network` and `shield_text`. Related, see `symbol` for pistes.
* `all_networks` and `all_shield_texts`: All the networks of which this road is a part, and all of the shield texts. See `network` and `shield_text` below. **Note** that these properties will not be present on MVT format tiles, as we cannot currently encode lists as values.
* `network`: eg: `US:I` for the United States Interstate network, useful for shields and road selections. This only contains _road_ network types. Please see `bicycle_network` and `walking_network` for bicycle and walking networks, respectively.
* `network`: eg: `US:I` for the United States Interstate network, useful for shields and road selections. This only contains _road_ network types. Please see `bicycle_network` and `walking_network` for bicycle and walking networks, respectively. Note that networks may include "modifier" information, for example `US:I:Business` for a business route or `US:I:Truck` for a truck route. The whitelist of "modifier" values is; `Alternate`, `Business`, `Bypass`, `Connector`, `Historic`, `Scenic`, `Spur`, `Toll` and `Truck`.
* `shield_text`: Contains text to display on a shield. For example, I 90 would have a `network` of `US:I` and a `shield_text` of `90`. The `ref`, `I 90`, is less useful for shield display without further processing. For some roads, this can include non-numeric characters, for example the M1 motorway in the UK will have a `shield_text` of `M1`, rather than just `1`.

#### Road properties (common optional):
34 changes: 34 additions & 0 deletions integration-test/1387-business-and-spur-routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from . import FixtureTest


class BusinessAndSpurRoutes(FixtureTest):

def _check_route_relation(
self, rel_id, way_id, tile, shield_text, network):
z, x, y = map(int, tile.split('/'))

self.load_fixtures([
'https://www.openstreetmap.org/relation/%d' % (rel_id,),
], clip=self.tile_bbox(z, x, y))

# check that First Capitol Dr, part of the above relation, is given
# a network that includes the "business" extension.
self.assert_has_feature(
z, x, y, 'roads',
{'id': way_id, 'shield_text': shield_text, 'network': network})

def test_first_capitol_dr_i70_business(self):
self._check_route_relation(
1933234, 12276055, '16/16294/25097', '70', 'US:I:Business')

def test_business_loop(self):
self._check_route_relation(
1935116, 5807439, '16/12285/23316', '15', 'US:I:Business:Loop')

def test_nj_essex(self):
self._check_route_relation(
945855, 221295008, '16/19267/24623', '672', 'US:NJ:Essex:Spur')

def test_nj_cr(self):
self._check_route_relation(
941526, 60523740, '16/19192/24767', '526', 'US:NJ:CR:Spur')

0 comments on commit fcdbee2

Please sign in to comment.