1

I have a number of different animal GPS location points, and a bunch of different habitat characteristics. I have built a simple model that uses the Near tool to calculate the distance from each point, create a new field using Add Field, naming it after the habitat characteristic shapefile name (using Parse Path and inline variable substitution), and then populates that added field with the NEAR_DIST values. It then continues on for all of my habitat characteristics.

I built the model a while ago and have since changed the names of the habitat characteristics (and there are a bunch of them) and unfortunately in the renaming them they are all now above the 10 character limit for a field name. What I was wondering is if there was any way to truncate the habitat characteristic shapefile title to 10 characters so that the add field tool doesn't error out.

Examples of habitat names are - 2001 Upland, 2001 Harvest, 2001 Deciduous

Essentially I need to remove the year and the space and they will all be under 10 characters.

The tool I created runs through but doesn't successfully "Add Field" because it is trying to name it after the "Near Feature" (the habitats whose names are too long) and so it just skips it.

enter image description here

5
  • 1
    Can you provide some examples of the "habitat characteristic shapefile title[s]" that you are using? It is very easy to just chop anything past 10 characters but if they all start with the same 10 characters then that will be of no use. Also, are you using ArcGIS for Desktop 10.0 or 10.1?
    – PolyGeo
    May 20, 2013 at 8:40
  • That makes sense @PolyGeo I've edited the question to include examples of the titles and a bit more description plus a screenshot of my tool. Thanks for the help. May 20, 2013 at 16:53
  • Oh, and I'm running ArcGIS for Desktop 10.0 May 20, 2013 at 17:51
  • Are you trying to edit field NAMES (ie- column headers) or field VALUES (the data in the row/cell)? These 2 questions have very different answers. May 20, 2013 at 18:38
  • Hey, I was trying to edit the name (column headers). The answer by blah238 sorted it out. Thanks for taking a look at it though. May 20, 2013 at 18:59

1 Answer 1

4

You can do this using Calculate Value and a bit of Python:

  • Expression:

    make_fieldname(%Points%)
    

    (where Points is the value you actually want to use, I just guessed)

  • Code Block:

    def make_fieldname(input):
        return '_'.join(input.split(' ')[1:])[:10]
    

This will take your input value, split it at the spaces, strip off the first element (the year in your examples), join the rest with underscores, and finally truncate it at 10 characters to be safe.

Test results:

>>> make_fieldname("2001 Upland")
'Upland'
>>> make_fieldname("2001 Harvest")
'Harvest'
>>> make_fieldname("2001 Deciduous")
'Deciduous'
>>> make_fieldname("1999 Party Time")
'Party_Time'
>>> make_fieldname("2013 A Really Long Year")
'A_Really_L'
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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