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 have two steps here. First select layer by attributes. Second convert polygon to raster. It failed when it goes to second step and kept giving me error 999999: Error executing function. I pasted my codes below. Is there anyone who has the same problem. I am now using Arcgis 10.1 and has SP1 installed.

exec('''
import arcpy
from arcpy import env
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("spatial")
import string
env.workspace = "G:\\countoverlap"


# Local variables:
FRAP_Fire111 = "G:\\countoverlap\\FRAP_Fire111.shp"

fldName = 'Year'
fcName = 'FRAP_Fire111.shp'
#set creates a unique value iterator from the value field
yearList = list(set([row.getValue(fldName) for row in arcpy.SearchCursor(fcName)]))
print(yearList)

 ''')


env.workspace = "G:\\countoverlap"
env.scratchWorkspace = "G:\\countoverlap\\overlap.gdb"
arcpy.MakeFeatureLayer_management(FRAP_Fire111, "lyr")

for year in yearList[1:len(yearList)]:

    print(str(year))

    # Process: Select Layer By Attribute
    arcpy.SelectLayerByAttribute_management("lyr","NEW_SELECTION", '"Year" = year' )
    print('Layer_Seclected')

    # Process: Polygon to Raster
    # Set local variables
    inFeatures = "lyr"
    valField = "Year"
    outRaster = "str(env.workspace)+'\\'+str(year)+'.tif'"
    assignmentType = "MAXIMUM_AREA"
    priorityField = "NONE"
    cellSize = 1080
    # Execute PolygonToRaster
    arcpy.PolygonToRaster_conversion(inFeatures, valField, outRaster, assignmentType, priorityField, cellSize)
    print('Raster_Created')
share|improve this question
    
This is just a guess, but try removing the "+ '.tif'" from your outRaster string. If that doesn't work, try creating an entirely new feature class from your selection to pass to "inFeatures", instead of just passing your selection. You can programatically delete the feature class afterwards. –  Conor Aug 28 '13 at 16:43
    
Also, you may want to check your folder privileges where you have your shapefiles stored. I sometimes encounter that error when trying to run raster operations either reading or storing in folders that have limited read/write privileges or are subfolders of folders with limited read/write privileges. Does the problem still persist if you move your folders to the desktop? –  Conor Aug 28 '13 at 16:52
add comment

1 Answer

I think the problem is this line:

outRaster = "str(env.workspace)+'\\'+str(year)+'.tif'"

It probably needs to be this:

outRaster = env.workspace + '\\' + str(year) + '.tif'

In fact I would avoid starting the name of your file with a number so if it was me it would be something like this so my files are starting with an "r":

outRaster = env.workspace + '\\r' + str(year) + '.tif'

This line is also incorrect (you have enclose your year variable within the string):

arcpy.SelectLayerByAttribute_management("lyr","NEW_SELECTION", '"Year" = year' )

It should be:

arcpy.SelectLayerByAttribute_management("lyr","NEW_SELECTION", '"Year" = ' + str(year) )
share|improve this answer
    
Yeah! It works! Thanks! –  Jing Lu Aug 29 '13 at 3:57
    
It works, but the raster files created are all the same, which means that there is something wrong with the layers selected .. –  Jing Lu Aug 29 '13 at 5:08
    
Have updated main answer –  Hornbydd Aug 29 '13 at 9:05
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.