1

I know nothing on scripts- learning as I go, I have a point shp file that has a column named SUFFIX in the column the words are spelled out AVENUE, ROAD, STREET, SQUARE and so on. Therefore I'm using the simple format individually for each word.. gets the job done but would like to do a big batch or all of them at the same time I have not found a format that would string them together. If someone can give me a field calculator string or arcpy with a few lines I can build out from there.

!SUFFIX!.replace("ROAD","Rd") 
!SUFFIX!.replace("AVENUE","Ave")
!SUFFIX!.replace("BOULEVARD","Blvd")
!SUFFIX!.replace("CRESCENT","Cres")
1

A very simple solution is to use modelbuilder. Create one field calculate tool that says replaces ROAD with Rd, then duplicate the tool in the model updating the calculate expression. You can then run the model and it will execute the tool as many times as you have specified. Save the model and run that when ever you like. Avoids the need to write anything more complex.

An example is shown below.

Example

2

If you do not want to go to deep into python just make all of that a one liner in the Field Calculator using the Python Parsor option:

!SUFFIX!.replace(" ROAD"," Rd").replace(" AVENUE"," Ave").replace(" BOULEVARD"," Blvd").replace(" CRESCENT"," Cres")

You can save out the expression as a .cal file and load/reuse it.

  • 1
    Ha! Never occurred to me chain the functions like that, simple, like it. Of cause all these approaches, including mine, suffer from the issue of sub-strings, for example road is a sub-string of "broad street", but original poster did not seem too concerned about that issue. – Hornbydd Aug 15 '17 at 19:54
  • 1
    @Hornbydd, good point about sub-string. I've updated my answer to handle for those cases. Essentially, assuming the word replaced should include an empty space before its first character. – artwork21 Aug 15 '17 at 20:09
0

You could also make use of case statements that loop over files for future use if you are looking to stick with the Python approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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