I am trying to convert IMG classified rasters to polygons. I created a code using the Raster to Polygon tool and it worked for 8 of the 50 files; for the rest, I get errors 010157 (Unable to open feature class C:Data\NewLayers\ClassifiedRaster. Failed to execute (RasterToPolygon).) and 010010 (Field not found. Invalid field index obtained. Failed to execute (RasterToPolygon)). What is weird about the first error is that the folder NewLayers is actually the output folder and the workspace is set to C:Data so I don't understand why it is looking for the input file in the output folder. The weird thing about the second error is that field does exist in every raster that the error occurs in. Does anyone have any suggestions? Here is my code:

arcpy.env.workspace = r"C:Data"
arcpy.env.overwriteOutput = True
listras = arcpy.ListRasters("*", "IMG")
for ras in listras:
    name = ras.split(".")[0]
    outws = r"C:Data\NewLayer"
    outras = outws + "\\" + name + ".shp"
            arcpy.RasterToPolygon_conversion(ras, outras, "NO_SIMPLIFY","Class_Name")
            arcpy.RasterToPolygon_conversion(ras, outras, "NO_SIMPLIFY","Class_Names")  
        #If the field does not exist, then list the fields so I can see what it might be called.
        #So far each raster that comes into the Except prints a field called Class_Name or Class_Names
        flist = arcpy.ListFields(ras)
        whatfields = []
        for f in flist:
            whatfields = f.name
            print str(name) + ": " + str(whatfields)
  • Try putting a back slash after C: so it should be c:\data
    – Hornbydd
    Nov 14, 2014 at 18:59
  • The path here isn't the actual path and the path I am using is copied directly from Windows Explorer into my code. NewLayers is the actual folder that sits in the folder containing the data.
    – Tiffany
    Nov 14, 2014 at 19:08


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.