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:
+20
-1
@@ -21,13 +21,32 @@ def title(s):
|
||||
result = re.sub(pattern, replacement, result)
|
||||
return result
|
||||
|
||||
# Secondary unit designators that may appear inline in a full address string,
|
||||
# e.g. "123 ROLLING ACRES RD UNIT 208" - everything from the designator on is
|
||||
# the unit, not part of the street name.
|
||||
_UNIT_DESIGNATORS = {'UNIT', 'APT', 'APARTMENT', 'STE', 'SUITE', 'BLDG', 'BUILDING', 'LOT'}
|
||||
|
||||
def _splitunit(parts):
|
||||
for i, part in enumerate(parts):
|
||||
if part.upper().rstrip('.') in _UNIT_DESIGNATORS:
|
||||
return parts[:i], (" ".join(parts[i + 1:]) or None)
|
||||
return parts, None
|
||||
|
||||
# @qgsfunction(args='auto', group='Custom', referenced_columns=[])
|
||||
def getstreetfromaddress(value1, feature, parent):
|
||||
parts = value1.split()
|
||||
parts.pop(0) # Ignore the first bit (i.e. "123" in "123 N MAIN ST")
|
||||
street_parts, _ = _splitunit(parts)
|
||||
#parts = map(formatstreetname, parts)
|
||||
#return " ".join(parts)
|
||||
return formatstreet(" ".join(parts), None, None)
|
||||
return formatstreet(" ".join(street_parts), None, None)
|
||||
|
||||
# @qgsfunction(args='auto', group='Custom', referenced_columns=[])
|
||||
def getunitfromaddress(value1, feature, parent):
|
||||
parts = value1.split()
|
||||
parts.pop(0) # Ignore the first bit (i.e. "123" in "123 N MAIN ST")
|
||||
_, unit = _splitunit(parts)
|
||||
return unit
|
||||
|
||||
# @qgsfunction(args='auto', group='Custom', referenced_columns=[])
|
||||
def formatstreet(value1, feature, parent):
|
||||
|
||||
Reference in New Issue
Block a user