Skip to content

Commit 9ce4f6b

Browse files
feat(conform): pass building_name attribute through to output
1 parent d1f85bf commit 9ce4f6b

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

openaddr/conform.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def gdal_error_handler(err_class, err_num, err_msg):
4646
# We add columns to the extracted CSV with our own data with these names.
4747
GEOM_FIELDNAME = 'oa:geom'
4848

49-
ADDRESSES_SCHEMA = [ 'hash', 'number', 'street', 'unit', 'city', 'district', 'region', 'postcode', 'id' ]
49+
ADDRESSES_SCHEMA = [ 'hash', 'number', 'street', 'unit', 'building_name', 'city', 'district', 'region', 'postcode', 'id' ]
5050
BUILDINGS_SCHEMA = [ 'hash']
5151
PARCELS_SCHEMA = [ 'hash', 'pid' ]
5252
RESERVED_SCHEMA = ADDRESSES_SCHEMA + BUILDINGS_SCHEMA + PARCELS_SCHEMA + [
@@ -1025,6 +1025,7 @@ def row_canonicalize_unit_and_number(sc, row):
10251025
row["unit"] = (row.get("unit", '') or '').strip()
10261026
row["number"] = (row.get("number", '') or '').strip()
10271027
row["street"] = (row.get("street", '') or '').strip()
1028+
row["building_name"] = (row.get("building_name", '') or '').strip()
10281029

10291030
if row.get("number", '').endswith('.0'):
10301031
row["number"] = row["number"][:-2]

openaddr/tests/conform.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def test_row_convert_to_out(self):
5757
"type": "Feature",
5858
"properties": {
5959
"unit": "",
60+
"building_name": "",
6061
"number": "123",
6162
"street": "MAPLE LN",
6263
"city": "",
@@ -375,6 +376,7 @@ def test_transform_and_convert(self):
375376
"region": "",
376377
"district": "",
377378
"postcode": "",
379+
"building_name": "",
378380
'hash': 'b3af08e447c7ed16',
379381
"id": ""
380382
},
@@ -405,6 +407,7 @@ def test_transform_and_convert(self):
405407
"region": "",
406408
"district": "",
407409
"postcode": "",
410+
"building_name": "",
408411
"id": "",
409412
'hash': 'd4681f7e1d34e6ed'
410413
},
@@ -453,6 +456,7 @@ def test_transform_and_convert(self):
453456
"district": "",
454457
"postcode": "",
455458
"id": "",
459+
"building_name": "",
456460
'hash': '591d7970b5753b0d'
457461
}
458462
}, r)
@@ -491,6 +495,7 @@ def test_transform_and_convert(self):
491495
"district": "",
492496
"postcode": "",
493497
"id": "",
498+
"building_name": "",
494499
'hash': '7b1dc0b74cbc0162'
495500
}
496501
}, r)
@@ -510,6 +515,44 @@ def test_row_canonicalize_unit_and_number(self):
510515
r = row_canonicalize_unit_and_number({}, {"number": a, "street": "", "unit": ""})
511516
self.assertEqual(e, r["number"])
512517

518+
def test_row_canonicalize_building_name(self):
519+
r = row_canonicalize_unit_and_number({}, {"number": "", "street": " OAK DR.", "unit": "", "building_name": " Rose Cottage "})
520+
self.assertEqual("Rose Cottage", r["building_name"])
521+
522+
# Missing building_name canonicalizes to empty string
523+
r = row_canonicalize_unit_and_number({}, {"number": "", "street": "OAK DR.", "unit": ""})
524+
self.assertEqual("", r["building_name"])
525+
526+
def test_row_transform_and_convert_building_name(self):
527+
"A BUILDING_NAME source column flows through to the output building_name attribute"
528+
d = SourceConfig(dict({
529+
"schema": 2,
530+
"layers": {
531+
"addresses": [{
532+
"name": "default",
533+
"conform": {
534+
"street": "STREET",
535+
"number": "NUMBER",
536+
"building_name": "BUILDING_NAME",
537+
"lon": "LON",
538+
"lat": "LAT"
539+
}
540+
}]
541+
}
542+
}), "addresses", "default")
543+
544+
feat = row_transform_and_convert(d, {
545+
"STREET": "HIGH STREET",
546+
"NUMBER": "",
547+
"BUILDING_NAME": "Rose Cottage",
548+
"LON": "-1.25",
549+
"LAT": "51.75"
550+
})
551+
552+
self.assertEqual("Rose Cottage", feat["properties"]["building_name"])
553+
self.assertEqual("", feat["properties"]["number"])
554+
self.assertEqual("HIGH STREET", feat["properties"]["street"])
555+
513556
def test_row_canonicalize_street_and_no_number(self):
514557
r = row_canonicalize_unit_and_number({}, {"number": None, "street": " OAK DR.", "unit": None})
515558
self.assertEqual("", r["number"])

0 commit comments

Comments
 (0)