[GIS] Python loop Polygon to raster not working

arcpyerror-999999polygonraster

I want to convert a large number of different shp polygons to raster in ArcGIS 10.1, using an existing field column "class" for the new raster classes. I am not very fluent in python but I thought this would work, and it doesn´t:


 # Import arcpy module
 import arcpy
... # Local variables:
... project_input = "D:\\RESEARCH_PROJECTS\\NORD-STAR\\AMAZONIA\\1-RAW_DATA\\INPE\\PRODES DIGITAL\\2004\\"
... raster_output = "D:\\RESEARCH_PROJECTS\\NORD-STAR\\AMAZONIA\\1-RAW_DATA\\INPE\\PRODES DIGITAL\\2004\\convert\\"
... # List features
... arcpy.env.workspace = project_input
... fcList = arcpy.ListFeatureClasses() 
... # Loop
... for featureClass in fcList:
... # Output
...     raster_outputpath = raster_output + featureClass
... 
... # Process: Polygon to Raster
...     arcpy.PolygonToRaster_conversion(featureClass, "CLASS", raster_output, "CELL_CENTER", "NONE", "30")
...     print "finished polygon to raster" 
...     
Runtime error  Traceback (most recent call last):   File "", line 20, in    File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\conversion.py", line 2436, in PolygonToRaster     raise e ExecuteError: ERROR 999999: Error executing function. Failed to execute (PolygonToRaster). 

The script actually calls the first polygon, but that is it:

Executing: PolygonToRaster
"D:\RESEARCH_PROJECTS\NORD-STAR\AMAZONIA\1-RAW_DATA\INPE\PRODES
DIGITAL\2004\PDigital2004_00157_pol.shp" CLASS
"D:\RESEARCH_PROJECTS\NORD-STAR\AMAZONIA\1-RAW_DATA\INPE\PRODES
DIGITAL\2004\convert\" CELL_CENTER NONE 30 Start Time: Wed Nov 21
15:17:11 2012 ERROR 999999: Error executing function. Failed to
execute (PolygonToRaster). Failed at Wed Nov 21 15:17:11 2012 (Elapsed
Time: 0,00 seconds)

Best Answer

The problem is that your code defines raster_outputpath but you try to save the raster in raster_output.

Change this line:

arcpy.PolygonToRaster_conversion(featureClass, "CLASS", raster_output, "CELL_CENTER", "NONE", "30")

To:

arcpy.PolygonToRaster_conversion(featureClass, "CLASS", raster_outputpath, "CELL_CENTER", "NONE", "30")
Related Question