Dear Andrew,
Based on your post, "I was able to use the Model Builder iterator with Topo To Raster"; I want to use the Model Builder iterator (For iterator) to run “Topo To Raster” on 200+ inputs. But, when I want to write a dynamic name ("***%value%") in the field part of topo to raster window (attached screenshot) to iterate the computations, it is automatically changed to the first column of dataset. I did the same way for other interpolation methods (IDW & Spline) and they totally worked. Is there any hint about using iterator for “Topo To Raster” tool in the Model Builder? Thank you in advance for your generous help.
try it as arcpy.sa.TopoContouryou will likely need it for arcpy.sa.Topolakeand arcpy.sa.TopoToRasterIf you use from arcpy.sa import *in your imports, you won't need to specify the module,but it can be confusing that way
The only issue is that you are looping through a list of all the feature classes. If that list includes both the topo and the water, then things might get confused. Use a wildcard on ListFeatureClasses so you only get the contours in the list. fcList = arcpy.ListFeatureClasses("topo_ras_input_topoSection*") Otherwise, there shouldn't be an issue with finding the right pairs of inputs. I would try a version of the process that does not do the actual TopoToRaster, but just prints out the names of the inputs instead. You can see if you are getting the right files for each itteration. something like: if waterBool: print "%s %s" % (myTopoContour, myTopoLake) else: print "%s" % (myTopoContour)
if waterBool: print "%s %s" % (myTopoContour, myTopoLake) else: print "%s" % (myTopoContour)
It sounds like you have two 'optional if present' inputs to the process.You want to run the process on ALL the topos present, although some of the tiles may be missing (so there would be nothing to run)If there is a water layer present, you would want to include it.I recall that the topos are features and the waters are rastersThe code I suggested already cycles through the vector features, so it naturally weeds out missing tiles.I would test for the existance of the water raster immidietly after the name is setmyTopoLake= 'topo_ras_input_watersecSection%s' % (str(fcNUM)) waterBool = arcpy.Exists(myTopoLake)Then use the existance boolean to decide which version of the command you need, with or without water.if waterBool: arcpy.TopoToRaster_sa([myTopoContour, myTopoLake], 2) else: arcpy.TopoToRaster_sa([myTopoContour], 2)
myTopoLake= 'topo_ras_input_watersecSection%s' % (str(fcNUM)) waterBool = arcpy.Exists(myTopoLake)
if waterBool: arcpy.TopoToRaster_sa([myTopoContour, myTopoLake], 2) else: arcpy.TopoToRaster_sa([myTopoContour], 2)
Try being explict with setting the names. Even if inputing the bald wildcards worked, you would get one output from all 519 input pairs, not 519 outputs...This is not tested, but may point you in the right direction.It assumes there are fc and raster pairs numbered the same.It itterates through the feature classes, assuming there is a matching raster.It uses the same 'contour' fc input for each loop.It outputs a twraster<number> where <number> matches the input number.# --------------------------------------------------------------------------- # Listdata.py # # Description: # Lists data sets in a workspace and then runs Topo to Raster on each feature # --------------------------------------------------------------------------- # Import arcpy module import arcpy # Check out any necessary licenses arcpy.CheckOutExtension ("Spatial") # Set the workspace for the ListFeatureClass function arcpy.env.workspace = "D:/GIS_data/Topo_Water" # Use the ListFeatureClasses function to return a list of # all shapefiles and feature classes. fcList = arcpy.ListFeatureClasses() # Process each file with loop in topo to raster for fc in fcList: fcBase = fc.rstrip(".shp") #strips off the '.shp.' fcNUM = fcBase .lstrip("topo_ras_input_topoSection") # should leave just the digits rasIN = 'topo_ras_input_watersecSection%s' % (str(fcNUM)) # output for this iteration myTopoContour = TopoContour([[fc,'contour']]) myTopoLake = TopoLake([rasIN]) # does not check if this exists.... # Execute TopoToRaster outTopoToRaster = TopoToRaster([myTopoContour, myTopoLake]) # Save the output outTopoToRaster.save("D:/GIS_data/Raster/twraster%s" % (fcNUM)) # saves each one ... and I see that as I was typing, someone else answered too....
# --------------------------------------------------------------------------- # Listdata.py # # Description: # Lists data sets in a workspace and then runs Topo to Raster on each feature # --------------------------------------------------------------------------- # Import arcpy module import arcpy # Check out any necessary licenses arcpy.CheckOutExtension ("Spatial") # Set the workspace for the ListFeatureClass function arcpy.env.workspace = "D:/GIS_data/Topo_Water" # Use the ListFeatureClasses function to return a list of # all shapefiles and feature classes. fcList = arcpy.ListFeatureClasses() # Process each file with loop in topo to raster for fc in fcList: fcBase = fc.rstrip(".shp") #strips off the '.shp.' fcNUM = fcBase .lstrip("topo_ras_input_topoSection") # should leave just the digits rasIN = 'topo_ras_input_watersecSection%s' % (str(fcNUM)) # output for this iteration myTopoContour = TopoContour([[fc,'contour']]) myTopoLake = TopoLake([rasIN]) # does not check if this exists.... # Execute TopoToRaster outTopoToRaster = TopoToRaster([myTopoContour, myTopoLake]) # Save the output outTopoToRaster.save("D:/GIS_data/Raster/twraster%s" % (fcNUM)) # saves each one
Can you please explain why there was no need to list features and loop? I thought that was the proper way to approach the problem? Is your approach something that can be used in other cases where I have many files in the same directory?
Assuming that all your shapefiles are in one catalog and the follow naming convention "topo_ras_input_topoSection1","topo_ras_input_topoSection2", ... , "topo_ras_input_topoSection519", the following script should work:import arcpy arcpy.env.workspace = "D:/GIS_data/Topo_Water" arcpy.CheckOutExtension("Spatial") cellSize = 30 #adjust this value to your data #assume there's 519 sections in workspace(you can test script with smaller value, eg. 3) for i in range(1, 520): myTopoContour = arcpy.sa.TopoContour([['topo_ras_input_topoSection'+str(i) + '.shp','contour']]) myTopoLake = arcpy.sa.TopoLake(['topo_ras_input_watersecSection'+str(i) + '.shp']) outTopoToRaster = arcpy.sa.TopoToRaster([myTopoContour, myTopoLake], cellSize) outTopoToRaster.save("D:/GIS_data/Raster/twraster" + str(i).zfill(3))The output raster name follow the rule: twraster001, twraster002, ...You can try running the script for testing for few shapefiles - adjust number in range(1, x) part.You may need to test to find optimal cell size of output raster.
import arcpy arcpy.env.workspace = "D:/GIS_data/Topo_Water" arcpy.CheckOutExtension("Spatial") cellSize = 30 #adjust this value to your data #assume there's 519 sections in workspace(you can test script with smaller value, eg. 3) for i in range(1, 520): myTopoContour = arcpy.sa.TopoContour([['topo_ras_input_topoSection'+str(i) + '.shp','contour']]) myTopoLake = arcpy.sa.TopoLake(['topo_ras_input_watersecSection'+str(i) + '.shp']) outTopoToRaster = arcpy.sa.TopoToRaster([myTopoContour, myTopoLake], cellSize) outTopoToRaster.save("D:/GIS_data/Raster/twraster" + str(i).zfill(3))
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.