Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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)

Thanks for your help

Javier

share|improve this question
add comment

5 Answers

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")
share|improve this answer
    
This is definitely the biggest issue with the code, but the suggestions below are also worth exploring. –  ccn Nov 21 '12 at 17:36
    
Yes, I fixed that silly mistake, thanks, but the ERROR 999999 still appeared. –  user12975 Nov 22 '12 at 16:37
add comment

Try the following suggestions:

Lines 4 and 5 Your files have characters such as "-" and " " which can lead to bugs. I rearranged your script--hopefully these changes will help.

# Import arcpy module
import arcpy
from arcpy import env

#Set working environment
env.workspace = "D:\\RESEARCH_PROJECTS\\NORD-STAR\\AMAZONIA\\1-RAW_DATA\\INPE\\PRODES DIGITAL\\2004"
Dir = env.workspace

#List FCs
fcList = arcpy.ListFeatureClasses() 

# Loop
for fc in fcList:

     output = Dir + "\\" + fc + "_ras"

     # Process: Polygon to Raster
     arcpy.PolygonToRaster_conversion(fc, "CLASS", output, "CELL_CENTER", "", "30")

print "finished polygon to raster" 
share|improve this answer
    
Thanks a lot. I get a Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 999999: Error executing function. Failed to execute (PolygonToRaster). –  user12975 Nov 22 '12 at 13:38
    
@user12975 When you run the script line by line, does it fail only at the arcpy.PolygonToRaster_conversion? Are you able to list your files with arcpy.ListFeatureClasses? –  Aaron Nov 22 '12 at 14:57
1  
Thanks all you guys for the help, very impressive. Aside from the initial mistake (outputpath was not called) I kept having an error. It was somehow related to the installation of SP4, I got the hint from gis.stackexchange.com/questions/24962/… The code of Aaron works perfectly now. –  user12975 Nov 22 '12 at 16:44
add comment

When I look ESRI online help it looks like arcpy.PolygonToRaster_conversion() expects a number for the cell_size and it looks like you are passing it a string. Try this instead and see if it works. arcpy.PolygonToRaster_conversion(featureClass, "CLASS",raster_output, "CELL_CENTER", "NONE", 30)

share|improve this answer
    
Thanks, but that did not solve the problem. Same ERROR 999999: Error executing function. Failed to execute (PolygonToRaster). –  user12975 Nov 21 '12 at 14:50
add comment

EDIT

I just ran a test using the following on a polygon representing the CA boundary:

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

It worked fine, so the problem may be with your polygon or your directory structure. I would try running Repair Geometry on your polygon features and ensure that your directories have no spaces in them (it sounds dumb, but having spaces in SOME directories can cause problems). Additionally, if you're running this in ArcMap as opposed to an IDE, disable background processing.

Initial reply:

I couldn't find anything on the proper input values for the priority_filed parameter (the fifth parameter). Try replacing "NONE" with empty double quotes ("") as it is an optional parameter and can thus be left at default if you don't have specific use for it:

arcpy.PolygonToRaster_conversion(featureClass, "CLASS", raster_output, "CELL_CENTER", "", "30")
share|improve this answer
add comment

I had a similar issue using the same tool.

I often use a .tif format as the output and that solves issues that arise with the GRID format.

JJH

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.