Skip to content
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
17 changes: 16 additions & 1 deletion openaddr/conform.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def gdal_error_handler(err_class, err_num, err_msg):
ADDRESSES_SCHEMA = [ 'hash', 'number', 'street', 'unit', 'city', 'district', 'region', 'postcode', 'id', 'accuracy' ]
BUILDINGS_SCHEMA = [ 'hash', 'height', 'levels']
PARCELS_SCHEMA = [ 'hash', 'pid' ]
CENTERLINES_SCHEMA = [ 'hash', 'id', 'name' ]
CENTERLINES_SCHEMA = [ 'hash', 'id', 'name', 'oneway', 'speed', 'classification', 'surface', 'addr_from_left', 'addr_to_left', 'addr_from_right', 'addr_to_right', 'zip_left', 'zip_right' ]
RESERVED_SCHEMA = ADDRESSES_SCHEMA + BUILDINGS_SCHEMA + PARCELS_SCHEMA + CENTERLINES_SCHEMA + [
"lat",
"lon"
Expand Down Expand Up @@ -880,6 +880,8 @@ def row_function(sc, row, key, fxn):
row = row_fxn_constant(sc, row, key, fxn)
elif function == "map":
row = row_fxn_map(sc, row, key, fxn)
elif function == "mph_to_kph":
row = row_fxn_mph_to_kph(sc, row, key, fxn)

return row

Expand Down Expand Up @@ -1077,6 +1079,19 @@ def row_fxn_constant(sc, row, key, fxn):

return row

def row_fxn_mph_to_kph(sc, row, key, fxn):
"Convert a miles-per-hour value to kilometers-per-hour"
field = fxn.get('field', False)

if field and field in row:
try:
mph = float(row[field])
row['oa:{}'.format(key)] = str(round(mph * 1.60934))
except (ValueError, TypeError):
row['oa:{}'.format(key)] = ''

return row

def row_fxn_map(sc, row, key, fxn):
"Map a value from a source column to a new value using a dictionary"
field = fxn.get('field', False)
Expand Down
Loading