3

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\AMAZONIA1円-RAW_DATA\INPE\PRODES DIGITAL2004円\PDigital2004_00157_pol.shp" CLASS "D:\RESEARCH_PROJECTS\NORD-STAR\AMAZONIA1円-RAW_DATA\INPE\PRODES DIGITAL2004円\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)

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Nov 21, 2012 at 14:30
1
  • I just painfully realised, that a non existing outputpath throws the same error. Commented Jun 29, 2020 at 7:21

5 Answers 5

6

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")
answered Nov 21, 2012 at 16:19
2
  • 1
    This is definitely the biggest issue with the code, but the suggestions below are also worth exploring. Commented Nov 21, 2012 at 17:36
  • Yes, I fixed that silly mistake, thanks, but the ERROR 999999 still appeared. Commented Nov 22, 2012 at 16:37
3

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" 
answered Nov 21, 2012 at 15:28
3
  • Thanks a lot. I get a Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 999999: Error executing function. Failed to execute (PolygonToRaster). Commented Nov 22, 2012 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? Commented Nov 22, 2012 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. Commented Nov 22, 2012 at 16:44
1

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)

answered Nov 21, 2012 at 14:46
1
  • Thanks, but that did not solve the problem. Same ERROR 999999: Error executing function. Failed to execute (PolygonToRaster). Commented Nov 21, 2012 at 14:50
1

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")
answered Nov 21, 2012 at 15:32
0

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

answered Feb 27, 2013 at 21:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.