Skip to content

Commit

Permalink
Merge pull request #1994 from tilezen/travisg/20211115-ref-can-be-empty
Browse files Browse the repository at this point in the history
If ref is missing, we should not export text or text_length fields
  • Loading branch information
tgrigsby-sc authored Nov 15, 2021
2 parents d135e35 + c26d64c commit 2eb4486
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
29 changes: 23 additions & 6 deletions integration-test/1979-shield-text-length.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,41 @@ def test_create_shield_text_length(self):
# make sure text length is encoded as a string
self.assert_no_matching_feature(z, x, y, 'roads', {'id': 417097119, 'shield_text_length': 2})

def test_missing_ref_does_not_report_length_or_text(self):
rel_bus_missing = rel23Bus.copy()
del rel_bus_missing['ref']

self.generate_fixtures(
# https://www.openstreetmap.org/way/417097119
dsl.way(417097119, dsl.tile_diagonal(z, x, y), way35),
dsl.relation(3002741, rel_bus_missing, ways=[417097119])
)

self.assert_no_matching_feature(
z, x, y, 'roads', {
'id': 417097119,
'bus_shield_text': 'None',
'bus_shield_text_length': '4'
})

# empty strings and route refs over 6 chars in length don't report length
def test_lengths_over_6_or_empty_are_not_reported(self):

rel123456 = rel35.copy()
rel123456['ref'] = '123456'

relCycleTooLong = rel50Cycle.copy()
relCycleTooLong['ref'] = '1234567'
rel_cycle_too_long = rel50Cycle.copy()
rel_cycle_too_long['ref'] = '1234567'

relBusEmpty = rel23Bus.copy()
relBusEmpty['ref'] = ''
rel_bus_empty = rel23Bus.copy()
rel_bus_empty['ref'] = ''

self.generate_fixtures(
# https://www.openstreetmap.org/way/417097119
dsl.way(417097119, dsl.tile_diagonal(z, x, y), way35),
dsl.relation(1976278, rel123456, ways=[417097119]),
dsl.relation(32312, relCycleTooLong, ways=[417097119]),
dsl.relation(3002741, relBusEmpty, ways=[417097119])
dsl.relation(32312, rel_cycle_too_long, ways=[417097119]),
dsl.relation(3002741, rel_bus_empty, ways=[417097119])
)

self.assert_has_feature(
Expand Down
8 changes: 5 additions & 3 deletions vectordatasource/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -8220,9 +8220,11 @@ def network_key(t):
# expose first network as network/shield_text
network, ref = tuples[0]
properties[prefix + 'network'] = network
properties[prefix + 'shield_text'] = str(ref)
if 0 < len(ref) <= 7:
properties[prefix + 'shield_text_length'] = str(len(ref))

if ref is not None:
properties[prefix + 'shield_text'] = ref
if 0 < len(ref) <= 7:
properties[prefix + 'shield_text_length'] = str(len(ref))

# replace properties with sorted versions of themselves
properties[all_networks] = [n[0] for n in tuples]
Expand Down

0 comments on commit 2eb4486

Please # to comment.