Skip to content

Commit

Permalink
use dict.get(key) more
Browse files Browse the repository at this point in the history
  • Loading branch information
mtmail committed Aug 27, 2021
1 parent 94bb497 commit 3e03dc3
Showing 1 changed file with 18 additions and 38 deletions.
56 changes: 18 additions & 38 deletions tiger_address_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def addressways(waylist, nodelist, first_id):
distance = float(ADDRESS_DISTANCE)
csv_lines = []

for waykey, segments in waylist.items():
waykey = dict(waykey)
for tags, segments in waylist.items():
tags = dict(tags)
for segment in segments:
lsegment = []
rsegment = []
Expand All @@ -51,27 +51,16 @@ def addressways(waylist, nodelist, first_id):
pullback = seglength / 3.0
else:
pullback = float(ADDRESS_PULLBACK)
if "tiger:lfromadd" in waykey:
lfromadd = waykey["tiger:lfromadd"]
else:
lfromadd = None
if "tiger:ltoadd" in waykey:
ltoadd = waykey["tiger:ltoadd"]
else:
ltoadd = None
if "tiger:rfromadd" in waykey:
rfromadd = waykey["tiger:rfromadd"]
else:
rfromadd = None
if "tiger:rtoadd" in waykey:
rtoadd = waykey["tiger:rtoadd"]
else:
rtoadd = None

lfromadd = tags.get("tiger:lfromadd")
ltoadd = tags.get("tiger:ltoadd")
rfromadd = tags.get("tiger:rfromadd")
rtoadd = tags.get("tiger:rtoadd")

right = check_if_integers([rfromadd, rtoadd])
left = check_if_integers([lfromadd, ltoadd])

if left == False and right == False:
if not left and not right:
continue

first = True
Expand Down Expand Up @@ -167,29 +156,20 @@ def addressways(waylist, nodelist, first_id):
id += 1

# Generate the tags for ways and nodes
zipr = ''
zipl = ''
name = ''
county = ''
state = ''
if "tiger:zip_right" in waykey:
zipr = waykey["tiger:zip_right"]
if "tiger:zip_left" in waykey:
zipl = waykey["tiger:zip_left"]
if "name" in waykey:
name = waykey["name"]
if "tiger:county" in waykey:
result = re.match('^(.+), ([A-Z][A-Z])', waykey["tiger:county"]) # e.g. 'Perquimans, NC'
county = result[1]
state = result[2]
zipr = tags.get("tiger:zip_right", '')
zipl = tags.get("tiger:zip_left", '')
name = tags.get("name", '')
result = re.match('^(.+), ([A-Z][A-Z])', tags.get("tiger:county", ",")) # e.g. 'Perquimans, NC'
county = result[1]
state = result[2]

# Write the nodes of the offset ways
if right:
interpolationtype = interpolation_type(rfromadd, rtoadd, lfromadd, ltoadd)

csv_lines.append({
'from': int(rfromadd),
'to': int(rtoadd),
'from': rfromadd,
'to': rtoadd,
'interpolation': interpolationtype,
'street': name,
'city': county,
Expand All @@ -202,8 +182,8 @@ def addressways(waylist, nodelist, first_id):
interpolationtype = interpolation_type(lfromadd, ltoadd, rfromadd, rtoadd)

csv_lines.append({
'from': int(lfromadd),
'to': int(ltoadd),
'from': lfromadd,
'to': ltoadd,
'interpolation': interpolationtype,
'street': name,
'city': county,
Expand Down

0 comments on commit 3e03dc3

Please sign in to comment.