Sunday 21 June 2015

arcgis desktop - Field Calculator: Split address into house number, street name


I have an ADDRESS field in a table with values like:



  • 1 MAIN ST

  • 20 SIDE AVE W

  • 300 JOHN DOE JR RD S



I want to use the field calculator to split the addresses and insert the parts into HOUSE_NUMBER and STREET_NAME fields. Example:



  • 300 into HOUSE_NUMBER

  • JOHN DOE JR RD S into STREET_NAME


I also want the tool to check if the value that will be put into HOUSE_NUMBER is a valid integer (and ignore it if it isn't).


How can I do this?



Answer



This python script seems to do the trick. It allows the user to choose whether to return the house number or the street name to the field (by commenting-out the non-applicable ReturnType line).



def addressParser(inString):
returnType = "House Number"
#returnType = "Street Name"

splitString = inString.split(' ',1)
houseNumber = splitString[0]
streetName = splitString[1]

if returnType == "House Number":
if houseNumber.isdigit():

return houseNumber
else:
return
if returnType == "Street Name":
return streetName
else:
return
__esri_field_calculator_splitter__
addressParser(!ADDRESS!)


Sources:



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...