I am attempting to create a script that will use the polygon to raster conversion in a batch processing function that creates multiple rasters based on different fields specified. I am wanting to do this for multiple feature classes within a folder. So far I have been able to get it to run for only one of the desired feature classes but not both.( There are two within the folder). Here is my script.
import arcpy
from arcpy import env
#Set environment settings
env.workspace = r"E:\GISC605GISDevelopment\Python Project\RivCounty"
#Set local variables
valField = ["TOTAL_PRO","OWN","COLLEGE_ED","Foreign","Per_INC2","TOTAL_25MI"]
outRaster = r"E:\GISC605GISDevelopment\Python Project\RivCounty\Group"
#List features
fcList = arcpy.ListFeatureClasses()
print fcList
for fc in fcList:
for field in valField:
arcpy.PolygonToRaster_conversion(fc, field, outRaster+str(valField.index(field))+".img")
Solved! Go to Solution.
Hi Esteban,
I believe you are overwriting the first outputs with your for loop. Try the following:
x = 1 for fc in fcList: for field in valField: arcpy.PolygonToRaster_conversion(fc, field, outRaster+str(x)+"_"+str(valField.index(field))+".img") x += 1
Hi Esteban,
I believe you are overwriting the first outputs with your for loop. Try the following:
x = 1 for fc in fcList: for field in valField: arcpy.PolygonToRaster_conversion(fc, field, outRaster+str(x)+"_"+str(valField.index(field))+".img") x += 1
Jake caught it, Esteban.... for future reference Code Formatting... the basics++