1

I have a python script that allows users to parse addresses when batch-editing a table.

The script 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).

Unfortunately, traditional user interfaces are not possible in the Field Calculator tool that we use. The only way I know of that the user can configure a script is to manually adjust the code.

def addressParser(inString):

    ###Note to users: 
    ###Comment-out the ReturnType option that does not apply. 
    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!)

The script seems simple enough to me, as a novice programmer.

However, when I write up the release notes for the script, it starts sounding awfully complicated for something that is really quite simple.

Step #3 is the one that I'm most concerned about.

Release Notes:

I’ve made a field calculator tool (python) that can be used to parse address fields. The tool works similarly to how we use the Text to Columns tool in Excel to parse addresses.

For example, 123 Main St E can get parsed to return either the house number or the street name:

  • 123
  • Main St E

The tool works by splitting the text at the first instance of a space (‘ ‘).

Steps:

  1. Load the tool into the Field Calculator by clicking the Load button.
  2. Switch the Field Calculator mode from VB Script to Python.
  3. Specify which part of the address (house number or street name) that the tool will return to your field by removing or adding the number sign (#) in front of the appropriate line.

    • Hint: the number sign (#) is the ‘comment out/cancel out’ symbol in python.
    • Example: To return the house number, you would leave the code as-is:

      returnType = "House Number"
      #returnType = "Street Name"
      

      Or, to return the street name, you would switch the number sign (#) from the street name line to the house number line:

      #returnType = "House Number" 
      returnType = "Street Name"
      
  4. Specify the field that the un-parsed address is coming from:

    • Example: Change addressParser( !YourUnparsedAddressFieldHere!)
    • To addressParser( !ADDRESS!)
  5. Click OK to run the tool.

How can I make this configurable script be more user-friendly for non-programmers?

  • Modify the script so that the configuration is easier?
  • Modify the instructions?

1 Answer 1

1

(I would rather answer you on Gis.se, but I'll answer here it's not illogical regarding the end user side you need to enhance)

I suggest you have a look at Python Toolboxes making for Arcgis, or in the case you are using QGIS, Writing new Processing algorithms as python scripts. You will see the parameters of your script can also be issued from gui interfaces you can generate from within your code. You will then be able to use lists of values or check-boxes for example. Those check boxes would help passing variables into your script instead of putting them hard in the code.

If you have any problems with the way to make scripts, please read this related documents and dig the subject following this lead, try things in your software then post again (maybe rather in GIS.SE as it's arcpy related) for your precise question on the subject.

For a more general answer that fits this SE area, the important thing is that you need to find a way to create a GUI (Graphical User Interface) with external tools or build-in tools and pass on the parameter inside your code, depending on what the user has choosen.

Your script will then have more then one parameter, for example :

def addressParser(inString,  returnType):

After that, you will be able to use your "if ....then :" type condition check to know which value was chosen by the user prior to running the code.

Not the answer you're looking for? Browse other questions tagged or ask your own question.