-
Notifications
You must be signed in to change notification settings - Fork 1
/
AddressCorrector.py
42 lines (34 loc) · 1.32 KB
/
AddressCorrector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import arcpy
#Obtain filepath of table or database that contains address data:
db = "C:/Addresses.dbf"
fields = ["Direction", "Number", "Street", "Address"]
oldName = "Invalid Address"
#Attempt to format direction properly
def Direction(street, direction, oldName):
abbreviations = ["N ", "S ", "E ", "W "]
directions = ["NORTH", "SOUTH", "EAST", "WEST"]
suffixes = ["TH", "ST", "DR", "CIR", "BLVD", "AVE"]
#print direction
firstTwoStreet = row[2][:2]
#If direction is empty, attempt to parse full address for direction
if street != " ":
if any(x in firstTwoStreet for x in abbreviations):
print street
return street
elif direction in directions:
tempDir = direction[0]
print tempDir + " " + street
return tempDir + " " + street
else:
return "Invalid Address"
#All other values are invalid, so return empty string
else:
return oldName
with arcpy.da.UpdateCursor(db, fields) as cursor:
for row in cursor:
#Concatenate string using parsed values
newStreet = Direction(row[2], str(row[0]), oldName)
row[3] = str(int(row[1])) + " " + newStreet
cursor.updateRow(row)
oldName = newStreet
print row[3]