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

Update road sort key values #117

Merged
merged 4 commits into from
Mar 2, 2016
Merged
Changes from all 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
87 changes: 40 additions & 47 deletions TileStache/Goodies/VecTiles/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,89 +291,82 @@ def road_classifier(shape, properties, fid, zoom):
def road_sort_key(shape, properties, fid, zoom):
# Note! parse_layer_as_float must be run before this filter.

# Calculated sort value is in the range 0 to 39
sort_val = 0
floor = 300
ceiling = 447
sort_val = floor

# Base layer range is 15 to 24
highway = properties.get('highway', '')
railway = properties.get('railway', '')
aeroway = properties.get('aeroway', '')
aerialway = properties.get('aerialway', '')
service = properties.get('service')
service = properties.get('service', '')
ne_type = properties.get('type', '')

is_railway = railway in ('rail', 'tram', 'light_rail', 'narrow_guage', 'monorail')
is_railway = railway in (
'rail', 'tram', 'light_rail', 'narrow_guage', 'monorail')

if highway == 'motorway':
sort_val += 24
if (highway == 'motorway' or
ne_type in ('Major Highway', 'Beltway', 'Bypass')):
sort_val += 81
elif is_railway:
sort_val += 23
elif highway == 'trunk':
sort_val += 22
elif highway == 'primary':
sort_val += 21
sort_val += 80
elif highway == 'trunk' or ne_type == 'Secondary Highway':
sort_val += 79
elif highway == 'primary' or ne_type == 'Road':
sort_val += 78
elif highway == 'secondary' or aeroway == 'runway':
sort_val += 20
elif highway == 'tertiary' or aeroway == 'taxiway':
sort_val += 19
sort_val += 77
elif highway == 'tertiary' or aeroway == 'taxiway' or ne_type == 'Track':
sort_val += 76
elif highway.endswith('_link'):
sort_val += 18
elif highway in ('residential', 'unclassified', 'road', 'living_street'):
sort_val += 17
elif highway in ('unclassified', 'service', 'minor'):
sort_val += 16
sort_val += 75
elif (highway in ('residential', 'unclassified', 'road', 'living_street')
or ne_type == 'Unknown'):
sort_val += 60
elif highway in ('service', 'minor'):
sort_val += 58
elif aerialway in ('gondola', 'cable_car'):
sort_val += 27
sort_val += 92
elif aerialway == 'chair_lift':
sort_val += 26
elif aerialway != '':
sort_val += 25
sort_val += 91
elif aerialway:
sort_val += 90
else:
sort_val += 15
sort_val += 55

if is_railway and service is not None:
if is_railway and service:
if service in ('spur', 'siding'):
# make sort val more like residential, unclassified which
# also come in at zoom 12
sort_val -= 6
sort_val -= 19
elif service == 'yard':
sort_val -= 7
sort_val -= 21
else:
sort_val -= 8
sort_val -= 23

if highway == 'service' and service is not None:
if highway == 'service' and service:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-2 (since railway would be -1 after everything else is said and done)

# sort alley, driveway, etc... under service
sort_val -= 1
sort_val -= 2

if zoom >= 15:
# Bridges and tunnels add +/- 10
bridge = properties.get('bridge')
tunnel = properties.get('tunnel')
if bridge in ('yes', 'true'):
sort_val += 10
if bridge in ('yes', 'true') or aerialway:
sort_val += 50
elif (tunnel in ('yes', 'true') or
(railway == 'subway' and tunnel not in ('no', 'false'))):
sort_val -= 10

# Keep aerialways above (almost) everything else, including bridges,
# but make sure it doesn't go beyond the 0-34 range. (still need to
# leave space for explicit layer).
if aerialway != '':
sort_val = min(34, sort_val + 10)
sort_val -= 50

# Explicit layer is clipped to [-5, 5] range. Note that
# the layer, if present, will be a Float due to the
# parse_layer_as_float filter.
layer = properties.get('layer')
if layer is not None:
layer = max(min(layer, 5), -5)
# The range of values from above is [5, 34]
# For positive layer values, we want the range to be:
# [34, 39]
if layer > 0:
sort_val = int(layer + 34)
# For negative layer values, [0, 5]
sort_val = int(layer + ceiling - 5)
elif layer < 0:
sort_val = int(layer + 5)
sort_val = int(layer + floor + 5)

properties['sort_key'] = sort_val

Expand Down