From 17b3458983250254552714d773378d0841037c58 Mon Sep 17 00:00:00 2001 From: Ian Dees Date: Sun, 15 Mar 2026 22:13:31 -0500 Subject: [PATCH] Add centerline fields and mph_to_kph function --- openaddr/conform.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/openaddr/conform.py b/openaddr/conform.py index cc1a29ef..111486be 100644 --- a/openaddr/conform.py +++ b/openaddr/conform.py @@ -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" @@ -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 @@ -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)