0

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"
    try:
        try:
            arcpy.RasterToPolygon_conversion(ras, outras, "NO_SIMPLIFY","Class_Name")
        except:
            arcpy.RasterToPolygon_conversion(ras, outras, "NO_SIMPLIFY","Class_Names")  
    except:
        #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)
2
  • Try putting a back slash after C: so it should be c:\data
    – Hornbydd
    Commented 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
    Commented Nov 14, 2014 at 19:08

0

Your Answer

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