For a large number of rasters, I need to define a pixel value less than zero as being Null and output the rasters. However, my simple SetNull loop (below) only processes the first raster in my list as Null, before stopping and not looping through the rest.
Triple commented ### is a dummy ExtractByMask function which I used to test the loop. When commented in, the ExtractByMask does loop successfully through all my rasters, indicating the loop itself seems okay. Can someone please advise, is there something specific I am not doing with SetNull please?
import arcpy, os, sys from arcpy import env from arcpy.sa import * arcpy.CheckOutExtension("Spatial") arcpy.env.overwriteOutput = True arcpy.env.workspace = "C:\\GIS\\in" # set up a folder containing rasters to clip outws = "C:\\GIS\\out" # set up a folder to output clipped rasters to #mask = "C:\\GIS\\dump\\pan.shp" # shapefile that defines clip rasterlist = arcpy.ListRasters("*", "tif") print(len(rasterlist)) for i in rasterlist: print i temp_nulled = SetNull(i,i,"VALUE < 0") ####temp_extracted = ExtractByMask(i, mask) rastername = str(i) # converts loop(i) raster name into a string rastername_crop = rastername[:7] # takes first n characters of raster name outname = os.path.join(outws, rastername_crop + '_NULL.tif') # Create the full out path ####outname = os.path.join(outws, rastername_crop + '_EXTRACT.tif') print outname temp_nulled.save(outname) ###temp_extracted.save(outname)