ModelBuilder iterator and filenames

4527
6
Jump to solution
04-16-2012 01:32 PM
WadeGivens
New Contributor II
Got a weird problem that I can't track down.  I'm using an iterator in ModelBuilder to step through a list of rasters in a workspace and and apply a set of filters.  I'm getting the file mae of the raster (%Value%) and using it to name the results from the last slice result "3 Class Smoothed Output" (%Value%cl).  The problem is the filenames are 1 off.  It appears to be naming my results by the file name ahead of the one the results are based on.  I'm sure I need to but in a precondition somewhere, but I've looked at it until I'm cross-eyed and can't find the right spot.  Pic of the model is attached in case it is plainly obvious to someone other than me 🙂

Thanks ahead,
Wade[ATTACH=CONFIG]13563[/ATTACH]
0 Kudos
1 Solution

Accepted Solutions
ShitijMehta
Esri Regular Contributor
Ok. I see the you are iterating over tif. Try this:
Create a precondition from output of the Parse Path tool to the "Slice to Equal Area 8 classes" tool. such that Parse path tool run before the Slice tool.

View solution in original post

0 Kudos
6 Replies
ShitijMehta
Esri Regular Contributor
You do not need to use the Parse Path tool. The cyan color output oval from the iterator called Name is the name of the input raster. Just use %Name% in your downstream tool output.
0 Kudos
WadeGivens
New Contributor II
That's what I started out using, but since the rasters I am processing are geoTIFF's, the Name variable gives me the file name plus the .tif extension.  When using %Name% for raster.tif in my results (%Name%_result.tif) I end up with raster.tif_result.tif.  I need to drop the .tif extension because the multiple .tif's in the resulting filenames are causing me headaches downstream.

Thanks for the suggestion though,
Wade
0 Kudos
ShitijMehta
Esri Regular Contributor
Ok. I see the you are iterating over tif. Try this:
Create a precondition from output of the Parse Path tool to the "Slice to Equal Area 8 classes" tool. such that Parse path tool run before the Slice tool.
0 Kudos
curtvprice
MVP Esteemed Contributor
Wade, Parse Path is new at 10.0 and a very nifty tool that avoids you having to get into Calculate Value and python coding like the example I posted to do that simple task.
0 Kudos
WadeGivens
New Contributor II
Thanks for the replies guys.  Adding the precondition in that spot did the trick Shitij.

Curtis, I'm using the Parse path tool extensively and it's pretty slick.  The problem I'm running in to is that I'm generating individual clipped raster files for a list shapefiles (bnd1_raster, bnd2_raster, etc.).  Due to some downstream processing, my rasters end up with names like bnd1_raster_tpi, bnd2_raster_tpi, etc.  I need to clip these again by the perspective shapefile feature.  Was thinking that using calculate field on %Value% (%Value% = bnd1_raster_tpi) and stripping the "_raster_tpi" and adding ".shp" would be the easiest way to specify the right shapefile to clip by in each iteration.

I know this would be MUCH easier if I would just script it in Python, but now the Calculate Field tool is gettign the best of me and I can't have that happen... 🙂

Wade
0 Kudos
curtvprice
MVP Esteemed Contributor
Due to some downstream processing, my rasters end up with names like bnd1_raster_tpi, bnd2_raster_tpi, etc.  I need to clip these again by the perspective shapefile feature.  Was thinking that using calculate field on %Value% (%Value% = bnd1_raster_tpi) and stripping the "_raster_tpi" and adding ".shp" would be the easiest way to specify the right shapefile to clip by in each iteration.


Calculate Value can do this for you, using an expression like this

r"%temp_raster%".replace("_raster_tpi","")


Set the output to String type set it as a precondition to the clip, and you can use that varaible embedded in the pathname for the shapefile.

I know this would be MUCH easier if I would just script it in Python, but now the Calculate Field tool is gettign the best of me and I can't have that happen... 🙂


There is a point where you have to hang it up and write a Python script, but a good grasp of Calculate Value makes ModelBuilder much more flexible and useful.
0 Kudos