Batch processing of polygon to raster with multliple fields

2863
2
Jump to solution
05-05-2016 10:23 AM
EstebanBarbosa
New Contributor

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")

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

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

View solution in original post

2 Replies
JakeSkinner
Esri Esteemed Contributor

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
DanPatterson_Retired
MVP Esteemed Contributor

Jake caught it, Esteban.... for future reference Code Formatting... the basics++