Batch process to find nodata values = 0

1102
7
04-23-2014 07:33 AM
NathanWest1
New Contributor II
I am wondering if it is possible to query a directory, returning results of any raster that has no data values of 0. I have been building mosaics, making the nodata values = 1. However, some have been built with nodata values= 0. Is there a way to find these 0 values without checking each one individually?

Thanks for any and all input.
Tags (2)
0 Kudos
7 Replies
JamesCrandall
MVP Frequent Contributor
Check if the ANYNODATA or ALLNODATA properties of GetRasterPorperties_management will do what you want:

http://resources.arcgis.com/en/help/main/10.1/index.html#//0017000000m7000000

Here is an exmple of running thru the Default.gdb on my system and reporting the raster name and ANYNODATA value


ws = r'H:\Documents\ArcGIS\Default.gdb'
arcpy.env.workspace = ws
rasters = arcpy.ListRasters()
for raster in rasters:
    nodatval = arcpy.GetRasterProperties_management(raster, "ANYNODATA")
    print str(raster) + " NoData = " + str(nodatval)
    
sys.exit()

0 Kudos
MathewCoyle
Frequent Contributor
If they are single band rasters this should work.
desc = arcpy.Describe(raster)
desc.noDataValue
0 Kudos
NathanWest1
New Contributor II
They are multiple bands. Neither of the above seemed to work. Is there a way to query rasters for pixel values of 0 instead of going the nodata route?
0 Kudos
NathanWest1
New Contributor II
Check if the ANYNODATA or ALLNODATA properties of GetRasterPorperties_management will do what you want:

http://resources.arcgis.com/en/help/main/10.1/index.html#//0017000000m7000000

Here is an exmple of running thru the Default.gdb on my system and reporting the raster name and ANYNODATA value


ws = r'H:\Documents\ArcGIS\Default.gdb'
arcpy.env.workspace = ws
rasters = arcpy.ListRasters()
for raster in rasters:
    nodatval = arcpy.GetRasterProperties_management(raster, "ANYNODATA")
    print str(raster) + " NoData = " + str(nodatval)
    
sys.exit()



This seems to give me a "nodata = 1" no matter whether the nodata values are 0 or 1. is there a way to query for pixel value? If i could query for pixel values of 0 then that would solve my problems competely. Thanks for the input!
0 Kudos
MathewCoyle
Frequent Contributor
If they are multiple bands what are your no data values you are looking for? 0,0,0?
0 Kudos
NathanWest1
New Contributor II
If they are multiple bands what are your no data values you are looking for? 0,0,0?


yes. and would it have to be done from within a GDB?  Thanks!
0 Kudos
MathewCoyle
Frequent Contributor
You can try searching each band. And no it shouldn't matter if it is in a GDB or not, but I can't speak to every raster format possible. I'm sure some formats don't support this. Give this a try, assuming you are dealing with bands 1,2,3.
bands = ['Band_1', 'Band_2', 'Band_3']
for band in bands:
    desc = arcpy.Describe(os.path.join(raster, band))
    desc.noDataValue
0 Kudos