3

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. 
 arcpy.env.workspace=r"D:\Mike_Daily_PRISM_PPT_from_2007_through2016\
 2007_Test"
 arcpy.CheckOutExtension('Spatial')
 #Location where output files should go after "for" loop has completed.
 outws=r"D:\Mike_Daily_PRISM_PPT_from_2007_through20162007円_Test\Output"
 #Location of the shapefile used to mask the PRISM raster(.bil) files
 mask=r"D:\Mike_Daily_PRISM_PPT_from_2007_through20162007円_Test\
 MissouriBound.shp"
 #Only search for files that have .bil extension. 
 rasterlist=arcpy.ListDatasets("*.bil","Raster")
 #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))
 outExtractByMask.save(outname)

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Oct 26, 2017 at 16:51
1
  • Please provide error messages as text rather than pictures so that they are available to future searches. Commented Oct 27, 2017 at 7:51

1 Answer 1

2

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)
outExtractByMask.save(outname)

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

answered Oct 26, 2017 at 18:06
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.