-
Notifications
You must be signed in to change notification settings - Fork 119
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
Add 'shield_text' property on roads #966
Changes from 6 commits
3d90278
945273f
594b0e2
3686b08
8a5e132
09be38e
861ac6d
99ea802
62375da
bba8a95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- drop no longer used single-network version of this function | ||
DROP FUNCTION mz_get_rel_network(bigint); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# US 101, "James Lick Freeway" | ||
# http://www.openstreetmap.org/way/27183379 | ||
# http://www.openstreetmap.org/relation/108619 | ||
assert_has_feature( | ||
16, 10484, 25334, 'roads', | ||
{ 'kind': 'highway', 'network': 'US:US', 'id': 27183379, | ||
'shield_text': '101' }) | ||
|
||
# I-77, I-81, US-11 & US-52 all in one road West Virginia. | ||
# | ||
# http://www.openstreetmap.org/way/51388984 | ||
# http://www.openstreetmap.org/relation/2309416 | ||
# http://www.openstreetmap.org/relation/2301037 | ||
# http://www.openstreetmap.org/relation/2297359 | ||
# http://www.openstreetmap.org/relation/1027748 | ||
assert_has_feature( | ||
16, 18022, 25522, 'roads', | ||
{ 'kind': 'highway', 'network': 'US:I', 'id': 51388984, | ||
'shield_text': '77' }) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3676,3 +3676,68 @@ def normalize_operator_values(shape, properties, fid, zoom): | |
return (shape, properties, fid) | ||
|
||
return (shape, properties, fid) | ||
|
||
|
||
def network_importance(route_type, network, ref): | ||
""" | ||
Returns an integer representing the numeric importance of the network, | ||
where lower numbers are more important. | ||
|
||
This is to handle roads which are part of many networks, and ensuring | ||
that the most important one is displayed. For example, in the USA many | ||
roads can be part of both interstate (US:I) and "US" (US:US) highways, | ||
and possibly state ones as well (e.g: US:NY:xxx). In addition, there | ||
are international conventions around the use of "CC:national" and | ||
"CC:regional:*" where "CC" is an ISO 2-letter country code. | ||
|
||
Here we treat national-level roads as more important than regional or | ||
lower, and assume that the deeper the network is in the hierarchy, the | ||
less important the road. Roads with lower "ref" numbers are considered | ||
more important than higher "ref" numbers, if they are part of the same | ||
network. | ||
""" | ||
|
||
if network == 'US:I' or ':national' in network: | ||
network_code = 1 | ||
elif network == 'US:US' or ':regional' in network: | ||
network_code = 2 | ||
else: | ||
network_code = len(network.split(':')) + 3 | ||
|
||
try: | ||
ref = max(int(ref), 0) | ||
except ValueError: | ||
ref = 0 | ||
|
||
return network_code * 10000 + min(ref, 9999) | ||
|
||
|
||
def choose_most_important_network(shape, properties, fid, zoom): | ||
""" | ||
Use the `network_importance` function to select any road networks from | ||
`mz_networks` and take the most important one. | ||
""" | ||
|
||
networks = properties.pop('mz_networks', None) | ||
|
||
if networks is not None: | ||
networks = networks.split('|') | ||
|
||
# take the list and make triples out of it | ||
itr = iter(networks) | ||
triples = zip(itr, itr, itr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! ⚡ |
||
|
||
def is_road_network(t): | ||
return t[0] == 'road' | ||
|
||
triples = filter(is_road_network, triples) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see you were in a functional mood ;) If this function is just used in this one location, list comprehension instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that would be more readable... but what would it look like? Can I do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, fixed in 99ea802. And 🍄 level up for me, learned new Python syntax 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops, yea I missed that it's |
||
|
||
if len(triples) > 0: | ||
def network_key(t): | ||
return network_importance(*t) | ||
|
||
route_type, network, ref = sorted(triples, key=network_key)[0] | ||
properties['network'] = network | ||
properties['shield_text'] = ref | ||
|
||
return (shape, properties, fid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it easy to have this return back an array, hstore, or json with the values instead of a delimited string? This is just meant for the python transform to consume and process right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes! Good point! I had forgotten that was JSON and thought it had to be stringly to fit in an hstore. Fixed in 861ac6d.