Skip to content

Instantly share code, notes, and snippets.

@stdavis
Last active April 16, 2020 21:44
Show Gist options
  • Save stdavis/165a58136a0beabeb2201089dceb86f3 to your computer and use it in GitHub Desktop.
Save stdavis/165a58136a0beabeb2201089dceb86f3 to your computer and use it in GitHub Desktop.
def cleanAddresses():
print(' * Cleaning Addresses')
def IsProblem(value):
ex = ['NO.', 'ST. JOSEPH', 'NORTH WAY']
return any(value.find(e) > -1 for e in ex)
def SkipName(value):
skipNameList = ['RIVER BEND WAY', 'CANYON CREST', 'WATER MILL WAY',
'UNIT', 'BLDG']
return any(value.find(e) > -1 for e in skipNameList)
exp = "{0} <> '' AND {0} IS NOT NULL".format('PARCEL_ADD')
print('Where Clause is', exp)
with arcpy.da.UpdateCursor(newParcels, ['PARCEL_ADD', 'OrigAddress', 'OID@'], exp) as rows:
for row in rows:
print ('ObjectID is:', row[2], '| Original Address is:', row[0])
if IsProblem(row[1]):
row[0] = row[1].replace('NO.', '').replace('ST. JOSEPH', 'ST JOSEPH').replace('NORTH WAY', 'N')
print ('IsProblem')
elif SkipName(row[1]):
row[0] = row[1].replace("ROAD", "RD").replace("LANE", "LN").replace("DRIVE", "DR").replace("STREET","ST").replace("CIRCLE", "CIR")
row[0] = row[1].replace("NORTH", "N").replace("SOUTH", "S").replace("EAST", "E").replace("WEST", "W")
row[0] = row[1].strip().upper().replace(" ", " ")
print('SkipName')
else:
# if not (IsProblem(row[1]) or SkipName(row[1])):
print('else')
address = address_parser.Address(row[1])
row[0] = address.normalized
rows.updateRow(row)
cleanAddresses()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment