Select to view content in your preferred language

batch polygon to raster python script

3689
1
02-21-2012 12:59 PM
torukumagai
New Contributor
Hello,
I'm a student trying to process some shapefiles into raster Grid data using the polygon to raster conversion.

My goal is to batch process multiple shapefiles and save the last 12 input numbers from the shapefile name into the outputname.

I ran into a problem on python.

I get this error= ERROR 000725: Output Raster Dataset: Dataset F:\Project Folder\NCDC Toolkit Radar imagae\processed data\2006\01\01\Result\Raster_out\ already exists. Failed to execute (PolygonToRaster)

Here is the script:

# Import arcpy module
import arcpy

# Local variables:
project_input = "F:\\Project Folder\\NCDC Toolkit Radar imagae\\processed data\\2006\\01\\01\\Result\\Reproject_out\\"
raster_output = "F:\\Project Folder\\NCDC Toolkit Radar imagae\\processed data\\2006\\01\\01\\Result\\Raster_out\\"

# List features
arcpy.env.workspace = project_input
fcList = arcpy.ListFeatureClasses()

# Loop
for featureClass in fcList:

                          # Output
                           raster_outputpath = raster_output + featureClass[:-12]
   
                         # Process: Polygon to Raster
                           arcpy.PolygonToRaster_conversion(featureClass, "Value", raster_output, "CELL_CENTER", "NONE", "100")
print "finished polygon to raster"
0 Kudos
1 Reply
StevePeaslee
Deactivated User
Toru,

It looks like you are using the wrong output raster variable in your PolygonToRaster command. You probably want to use 'raster_outputpath' since that is where you create the unique raster name.

Also make sure you've indented everything under the loop. I assume you have, but can't tell from your message.

A print statement within your loop that lists your variable values would be helpful in diagnosing problems.

-Steve
0 Kudos