Error when saving raster ouput using iterator item in the raster name

779
7
06-05-2012 12:21 PM
toddsams
New Contributor III
I am running into this error: "ERROR 010093: Output raster format UNKNOWN is unsupported" while attempting to save an output raster from the extract by mask function. Code snippet is below:

Main = sys.path[0]
env.workspace = Main

MainFdr = Main + os.sep + "fdr_combo"

HucPolys = Main + os.sep + "polys"

env.workspace = HucPolys

HUCs = arcpy.ListFeatureClasses()

for HUC in HUCs:
    try:
        env.workspace = HucPolys
        FDRpath = Main + os.sep + "fdr"
        FACpath = Main + os.sep + "fac"

        # Execute ExtractByMask
        FdrOut = ExtractByMask(MainFdr, HUC)
        # Save the output
        env.workspace = FDRpath
        FdrOut.save("fdr_" + HUC)
        
    except:
        print "error_" + HUC
        continue


It works if I remove the iterator item ID (+ HUC) from the save name. However, I need to keep this in as a unique identifier so I do not overwrite my previous output.

Does anyone have thoughts on how to resolve this?
Tags (2)
0 Kudos
7 Replies
NareshPai
New Contributor
Try:

"fdr_" + str(HUC)


--Naresh
0 Kudos
toddsams
New Contributor III
Thanks for the suggestion Naresh! However, I still receive the error.

Might you have another thought?
0 Kudos
toddsams
New Contributor III
I made a variable i = 1 outside the For loop

Then increased it by 1 (i = i +1) at the end of the for loop and then added "i" to "fdr_" as: "fdr_" + str(i)

This worked.

(Although, it would be better if they were named with the value for whichever HUC was being operated on!!!)
0 Kudos
toddsams
New Contributor III
Although, it would be better if they were named with the value for whichever HUC was being operated on!!!
0 Kudos
NareshPai
New Contributor
I would examine the hydrological unit codes closely. In the for loop, try putting:

print str(HUC)

to see if anything looks unusual.

Naresh
0 Kudos
MarcinGasior
Occasional Contributor III
I suppose that your polygon features are in shapefiles.
If so, the HUCs variable contains list of shapefiles names with extension.
That's why script cannot create raster with .shp extension:)

To fix this, just remove ".shp" from the string (and make sure that composed name do not exceed 13 character length):
FdrOut.save("fdr_" + HUC[:-4])
0 Kudos
toddsams
New Contributor III
Indeed they ARE shapefiles, and YES that makes complete sense! I normally work with feature classes, so have not run into this problem before.

Many thanks.
0 Kudos