Gathering raster properties for multiple datasets using Python

06-11-2013 04:33 AM
Labels (2)
Esri Notable Contributor
0 0 1,056
Raster datasets have a large assortment of information beyond the basic pixel display. This information is stored in the properties and is helpful in understanding more about the data. Locating the properties of a raster dataset can be a tedious process if you are trying to compile information for a lot of datasets. This is because the workflow to find the properties of a raster dataset in the Catalog is to right click on each dataset and choose Properties > General tab.


For example, you are working on a project that requires an elevation image service to be created.  The image service foundation is a mosaic dataset that references source rasters for each county in the state.  You create the mosaic dataset, add the rasters, build the overviews, and add it to the map document.  The mosaic dataset looks great until you begin zooming into the source data.  In one spot you find that the elevation appears very dark instead of a consistent grayscale.ElevationDark.jpg

After investigating the source raster you find that the dataset is an 4-bit integer instead of the normal 32-bit float.  This makes you wonder if there are other datasets that were created incorrectly.  To find those datasets you can either zoom into small scale areas across the entire state, or you can open the properties for each individual raster.  Either way the process would be very time consuming as each raster would need to be reviewed individually.

Another option is to access the raster properties through a Python loop.  This process presents a more efficient and simplified solution.  The information can be queried through the python Raster object and the Get Raster Properties geoprocessing tool.

import arcpy
arcpy.env.workspace = r"C:\temp"

rasterList = arcpy.ListRasters()

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

bands = arcpy.GetRasterProperties_management(raster, "BandCount")
print "Band count: %s" %bands

noData = rasterObj.noDataValue
print "NoData Value: %s \n" %noData

The returned values can be written to a table to easily identify which datasets are incorrect.RasterPropertiesTable-1024x279.jpg

Additional Resources

A Python script tool example of getting the raster properties can be download from Write Raster Properties to Table.Timothy H. – Senior Support Analyst
About the Author
Education Specialist for Esri Training. Former Enterprise Community Manager for GeoNet and Senior Support Analyst for Esri Technical Support. Passion for technology, social media, and debt free living. Enjoy spending time with my family and running obstacle course races (completed my first Spartan Trifecta in 2015).