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.

Does anyone have a script I can use in modelbuilder that will?:

  • parse an "_" from a filename

  • usable in modelbuilder with an inline variable (%name%) and Feature class iterator

  • transfer or copy the actual renamed shapefiles to another folder?

Any help or suggestions will be greatly appreciated.

enter image description here

share|improve this question
3  
You can use a bit of Python and simply call string.replace('_', '') to remove the underscore. –  Radar Jun 18 '13 at 17:07
    
I downvoted because this was asking someone else to do research for them. –  Pete Jun 18 '13 at 18:23
3  
I would say the question is well within the bounds of the rules and format of GIS SE. –  Radar Jun 18 '13 at 19:07
    
@Pete this is the kind of thing which is hard to find if you don't know what words to use when searching, and eyes-closed easy when you do know the words. –  matt wilkie Jun 18 '13 at 22:52
    
related: gis.stackexchange.com/questions/25584/… –  matt wilkie Jun 18 '13 at 22:57
show 2 more comments

2 Answers

Rather than writing a Python script tool you should be able to use a Calculate Value tool with the Python code recommended by @blah238:

r"%name%".replace("_","")

The next step will be to use the Rename tool to use the text string this creates to rename the feature class.

share|improve this answer
2  
A slight clarification. There is a distinction between the string methods of built-in sequence types like str and unicode, and methods of the actual string module. Use of the built-in methods is preferred. So in the Calculate Value tool's expression box, you would enter something like r"%name%".replace("_",""). –  blah238 Jun 18 '13 at 21:02
    
The calculate value with the expression r"%name%".replace("_","") still doesn't work. This operation seems simple enough but still no luck. Do I need to define the workspace or parse a path? –  galindo Jun 18 '13 at 21:47
    
Actually, I take that back; the Calculate Value tool works with the expression r"%name%".replace("_","") but how do you transfer or copy the actual renamed shapefiles to another folder? I can see the renamed shapefiles with the Collect Values. Almost there! –  galindo Jun 18 '13 at 22:08
1  
I would suggest using Copy Features instead, as the OP would like to copy the shapefiles over to a new folder. –  Arabella Jun 19 '13 at 5:22
add comment

Building on PolyGeo's answer above, the Collect Values tool is not necessary, because as you iterate over the shapefiles, each one should be renamed and copied once only.

enter image description here

In the image above, the shapefiles are renamed and copied one at a time as the iterator iterates over them. Make sure to check the recursive checkbox in the iterator dialog if your folder contains subfolders.

share|improve this answer
    
Renaming as part of the copy makes sense (+1) but I think when you said "the Collect Values tool is not necessary" you meant "the Rename tool is not necessary". –  PolyGeo Jun 19 '13 at 11:39
    
I duplicated the model above but I'm still getting the the "_" underscore in the filename for my output files. Any suggestions? –  galindo Jun 19 '13 at 15:21
1  
@PolyGeo I meant that if the recursive checkbox is ticked, the Collect Values is not necessary because it will iterate over each shapefile anyway, therefore Copy Features will run for each iteration and copy each shp. –  Arabella Jun 20 '13 at 4:55
    
@galindo If you used PolyGeo's string replacement in the Calculate Value tool, then your parsed_filename contains the new shp name without underscores. –  Arabella Jun 20 '13 at 4:58
    
I see what you mean - I had been talking about Calulate Value and had not noticed that @Galinda had a Collect Values tool in his/her model. –  PolyGeo Jun 20 '13 at 9:08
show 1 more 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.