Skip to main content
1 of 3
TrevP
  • 611
  • 5
  • 13

Finding raster files inn a directory that contain noData pixels/cells

I am trying to find a way of looping through Rasters in a directory, (a collection of individual tiff images in a folder) and selecting by name only those rasters that contain noData values and passing those tiff file names into a list. By inspection most of the tiff files do not have noData values in them. However a number do and I would like to be able to achieve this programmatically. I am trying to do this using arcpy / ArcGIS tools and modules

My code so far is below, but it is not picking out the rasters where I lnow there are no data values

Can anyone offer some advice please

import arcpy
arcpy.env.workspace = r'C:\myRasters\...'

rasterList = arcpy.ListRasters()

incompleteRasters = []

for raster in rasterList:
    rasterObj = arcpy.Raster(raster)
    print(rasterObj.name)

    if rasterObj.noDataValue == True:
        incompleteRasters.append(rasterObj)           
        print("NoData Value: %s \n" %noData, "in ", rasterObj.name)
    else:
        print("all ok")

print('All', len(rasterList), 'tifs have been checked')

TrevP
  • 611
  • 5
  • 13