[GIS] Finding Band Count in Rasters using ArcPy

arcpyraster

I'm having troubles finding the band count for my raster files using ArcPy.

I need to first list all the raster files in a directory, and then display the band count for each file. I am able to list the files, but when it gets to the band count, it gives me an error stating that Method Band Count does not exist.

The following is what I have for my code so far:

import os
import arcpy

arcpy.env.workspace = "C:\\Rasters" # Contains TIFF, IMG, GRID formats
filePath = arcpy.env.workspace

rasterList = arcpy.ListRasters("*", "ALL")
desc = arcpy.Describe(filePath)

for names in rasterList:
    print names
    print desc.bandCount

Any ideas where I'm going wrong? I was using the Geoprocessor Programming Model as a reference.

Best Answer

Your Describe() is referencing the workspace (a folder) rather than the individual images contained within it. Try this:

import os 
import arcpy 

arcpy.env.workspace = "C:\\Rasters" # Contains TIFF, IMG, GRID formats 
filePath = arcpy.env.workspace 

rasterList = arcpy.ListRasters("*", "ALL") 

for name in rasterList:
    desc = arcpy.Describe(filePath + "\\" + name)
    print name
    print desc.bandCount
Related Question