Select to view content in your preferred language

iteration

1090
8
05-31-2014 09:47 AM
BadenCross
Emerging Contributor
I am new to modelbuilder and am trying to convert many USGS dems to raster using the iteration process but not having any luck, having tried variables, wildcards etc.

I am used to using Script language so maybe my head is stuck in that logic and can't get the'flow' of the modelbuilder process arranged properly

any help with this would be appreciated

cheers

Baden
0 Kudos
8 Replies
CPoynter
Frequent Contributor
Wrote this quickly, but try:


import arcpy, os
from arcpy import env

env.workspace = r"<your workspace>"

for dem_file in arcpy.ListFiles('*.DEM'):

 dem, ext = os.path.splitext(dem_file)

 print dem_file
 print dem

 arcpy.DEMToRaster_conversion(env.workspace + dem_file, env.workspace + "\\output\\" + dem + ".tif", "FLOAT", 1)



Iterators added within ModelBuilder can only be run in ModelBuilder itself.

Regards,

Craig
0 Kudos
BadenCross
Emerging Contributor
Thanks Craig, I was hoping to just work within Modelbuilder. The code you indicated looks like another learning curve beyond the old 'script' language I programmmed with in ArcView........
0 Kudos
IanMurray
Honored Contributor
Baden if you could post your model thus far, and a screenshot on what inputs you are using on your iterator, that would be helpful.

Also all your raster need to be in the same folder, or if they are in subfolders, you need to select a parent folder in which they are located, and select the recursive option so it will iterate through all subfolders.

Your iterator should be at the beginning of the model, with the folder that contains the rasters being the input.  the output "Raster" from that should then be the input of the DEM to Raster tool. 

Hope this helps.
0 Kudos
BadenCross
Emerging Contributor
Thanks for your help with this. All my dems are in the temp folder and begin with 092o so I use the wild card "092o*" in the dialogue box that opens when I double click the iterate feature symbol. The oval green shape indicates 'feature class' with no option to change this; same with the blue name oval. I can't seem to connect the "dem to raster" part to the reiterate part ( as you can see from the 'white' colouring......
0 Kudos
IanMurray
Honored Contributor
I see the problem. 

You selected the iterate feature classes iterator, you need to select the iterate raster iterator.  The output of that you should be able to connect to the dem to raster, as they are the correct data type for that tool.
0 Kudos
CPoynter
Frequent Contributor
Had a bit of a test with all of the iterator types in ModelBuilder and found 'Iterate Files' will feed into the DEMtoRaster tool correctly.

[ATTACH=CONFIG]34284[/ATTACH]

The other option you might try, although time consuming, is to right click on the DEMtoRaster tool and select Batch and manually add you DEM datasets.

If you modify the Python script I posted, you can run that within ArcMap itself.

Regards,

Craig
0 Kudos
BadenCross
Emerging Contributor
here's the best I can do with modelbuilder ( see attachment)

thanks to both of you trying to solve my problem. Doing the conversion by 'hand', one at a time, works. The programming "scipt"  language I worked with previously using ArcView was quite reasonable and understandable  but I suspect the new versions of ESRI just get too complicated ( and full of bugs that do not get addressed- just the old 'get it out there' syndrome - typical in today's world) and more and more folks who relied on ESRI for real world solutions, are just getting fed up with the complicity of the evolution of the software.....
such is the way.....maybe if there are ESRI techies monitoring these forums, they might feel some embarrassment....

cheers

Baden....
0 Kudos
BadenCross
Emerging Contributor
Hi Craig, the 'files' iterator let me connect the DEM to raster to the iterator - big step! however when the iterator runs through all the dems it simply overwrites the output file from the DEM to raster tool with the same name - and can't seem to find out how to produce a separate raster file for each input DEM....any idea how to get separate names for the raster outputs that would match the input DEM file names??

thanks again for your efforts...

Baden
0 Kudos