Split unit designators (UNIT/APT/STE/etc) out of combined address strings into addr:unit instead of leaving them in addr:street

This commit is contained in:
zyphlar
2026-07-29 22:28:32 -07:00
parent 2c8a67ac15
commit 6a56c3edfe
2 changed files with 40 additions and 3 deletions
+20 -2
View File
@@ -52,14 +52,17 @@ def process_address_fields(gdf, exceptions):
mapping['addr:housenumber'] = series.round().astype('Int64')
break
# Unit
# Unit (a dedicated column takes priority; otherwise fall back to a unit
# designator embedded in a combined street+unit address string below)
unit_from_column = [None] * len(processed)
for field in ['UNIT', 'UnitNumber', 'UNIT_NUM', 'APT']:
if field in processed.columns:
series = processed[field].copy().replace(['nan', 'None', '', None], None)
mapping['addr:unit'] = series.where(series.notna(), None)
unit_from_column = list(series.where(series.notna(), None))
break
# Street name
unit_from_address = [None] * len(processed)
if 'SADD' in processed.columns:
# Sumter: full address string in SADD
mapping['addr:street'] = [
@@ -67,6 +70,11 @@ def process_address_fields(gdf, exceptions):
if pd.notna(v) else None
for v in processed['SADD']
]
unit_from_address = [
qgis_functions.title(qgis_functions.getunitfromaddress(str(v), None, None) or '') or None
if pd.notna(v) else None
for v in processed['SADD']
]
elif 'FullAddres' in processed.columns:
# Lake: full address string in FullAddres
mapping['addr:street'] = [
@@ -74,6 +82,11 @@ def process_address_fields(gdf, exceptions):
if pd.notna(v) else None
for v in processed['FullAddres']
]
unit_from_address = [
qgis_functions.title(qgis_functions.getunitfromaddress(str(v), None, None) or '') or None
if pd.notna(v) else None
for v in processed['FullAddres']
]
elif 'BaseStreet' in processed.columns:
# Lake alternative: assemble from components
street_names = []
@@ -85,6 +98,11 @@ def process_address_fields(gdf, exceptions):
street_names.append(qgis_functions.title(' '.join(parts)) if parts else None)
mapping['addr:street'] = street_names
mapping['addr:unit'] = [
col if col is not None else addr
for col, addr in zip(unit_from_column, unit_from_address)
]
# Apply street name exceptions
if 'addr:street' in mapping and exceptions:
mapping['addr:street'] = [