Iterate through rasters in a mosaic

2438
2
05-26-2016 03:10 AM

Iterate through rasters in a mosaic

I struggled to find a simple solution to this, so thought I'd put it up to help the next person.

What I was trying to do was iterate through the rasters which formed my mosaic and retrieve the acquisition date from each of them. In ArcMap, you would find this by opening the attribute table and clicking through the little arrow within the raster field for each record.

import arcpy
arcpy.env.workspace = r'D:\example.gdb'
rows = arcpy.SearchCursor(r'D:\example.gdb\my_mosaic', fields='ObjectID')

ObjectIDs = []
for row in rows:
     ObjectIDs.append(row.getValue('ObjectID'))

for ObjectID in ObjectIDs:
     raster = 'my_mosaic\Raster.OBJECTID = ' + str(ObjectID)
     aquisition_date = arcpy.GetRasterProperties_management(in_raster=raster, property_type='ACQUISITIONDATE')
     print 'Aquisition Date = {}'.format(aquisition_date)

Hope this helps someone out.

Comments

I was looking for this.. thank you!

Would this work with a Raster Catalog too? I'm trying to query for bit depth of thousands of rasters I have, if there's a better method too, I'm all ears.

Version history
Last update:
‎12-12-2021 03:38 AM
Updated by: