I have written a stand-alone Python script to perform an ExtractByMask operation on numerous raster files in ArcMap, that have a .bil extension format. However, when I try to save my output, I get the following runtime error:

enter image description here

Below is what my code looks like currently:

    #Import necessary system modules
    import arcpy,os
    from arcpy import env
    from arcpy.sa import *

    #Location where raster (.bil) files are located.  

    #Location where output files should go after "for" loop has completed.

    #Location of the shapefile used to mask the PRISM raster(.bil) files

    #Only search for files that have .bil extension.  

    #Print the list of raster files that have a .bil extension
    print rasterlist

    #for i in rasterlist, perform an ExtractByMask function on each raster.      
    for i in rasterlist:
    outExtractByMask=ExtractByMask(i, mask)
    outname=os.path.join(outws, str(i))

I believe the error has something to do with the format that it's trying to save the output format raster with. [Note: Actually, I would prefer to save the output in a TIFF format (.tif).] Can anyone confirm whether that is the issue with my code, and how I can then modify it to save the output with a .tif extension?

  • Please provide error messages as text rather than pictures so that they are available to future searches. – PolyGeo Oct 27 '17 at 7:51

Yeah the error is coming up because you're trying to export each masked raster as a BIL. If exporting as a TIF is preferable anyway, it's an easy fix:

for i in rasterlist:
outExtractByMask=ExtractByMask(i, mask)
filename = str(i)[:-3] + 'tif'
outname=os.path.join(outws, filename)

Then it should run fine, exporting GeoTIFFs. Obviously you can change that to match whatever raster format (supported by Arc) you might want.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.