Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Apologies that I have not posted an image of my model, I am away from my computer for a while but am trying to sort this out anyways.

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.

Thanks in advance, and if you need any more information please let me know. I tend to leave things out by mistake when I ask questions on here.

Edit - 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.

Also, at home now so here is the tool I created. It runs through but doesn't successfully "Add Field" because its 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

share|improve this question
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 '13 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. –  HeidelbergSlide May 20 '13 at 16:53
    
Oh, and I'm running ArcGIS for Desktop 10.0 –  HeidelbergSlide May 20 '13 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. –  RyanDalton May 20 '13 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. –  HeidelbergSlide May 20 '13 at 18:59
add comment

1 Answer

up vote 3 down vote accepted

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'
share|improve this answer
    
Ah perfect! That did it, thanks so much for this. I really need to learn Python better, I tried Calculate Value for a while but just couldn't figure out the code to do this. Thanks again! –  HeidelbergSlide May 20 '13 at 18:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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