Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Error: 'NoneType' object is not iterable (arcpy.ListRasters)

$
0
0

I am trying to extract a raster through a particular shapefile.

   import arcpy
   from arcpy import env
   from arcpy.sa import *
   arcpy.CheckOutExtension("Spatial")
   env.overwriteOutput = True

   #Set the current workspace
   env.workspace = ("C:thesisForests Only Percent Treecover2003 BSWM Forest")
   env.nodata = "MINIMUM"
   env.compression = "LZ77"

   #This is for extracting the forest areas of hansen percent treecover
   for raster in arcpy.ListRasters("*0E.tif", "TIFF"):
       print raster #checking the presence of raster
       outputRasterExtractbyMask = ExtractByMask(raster, "NAMRIA.shp")
       outputRasterExtractbyMask_Name = "forests_only"+raster
       outputRasterExtractbyMask.save(outputRasterExtractbyMask_Name)

   print "Finish"

As I print the raster in arcpy.ListRasters to check the presence of raster, this error shows up:

 Traceback (most recent call last):
 File "C:UsersbrentiebarkDropboxPython Scripts and mxdsextractbymask.py", line 14, in <module>
 for raster in arcpy.ListRasters("*0E.tif", "TIFF"):
 TypeError: 'NoneType' object is not iterable

I double checked the directory, and my files are really there. Is there something wrong with my code?


Viewing all articles
Browse latest Browse all 767

Trending Articles