Select to view content in your preferred language

Automate Changing Mosaic Dataset Definition query with ArcPy in ArcGISPro

09-06-2019 11:20 AM
New Contributor III

I have a mosaic dataset with 10 images with different Acquistion Dates. I want to populate a layout with a time-lapse series of images, so that I can show how an area changes over time. 

I have written the following code to Make a new image layer by querying the Mosaic Dataset's Footprint for a specific acquisition date.

#initialize arcpy and create project / map objects

import arcpy"Current")

#get unique values from field

def unique_values(table, field): #returns all the unique values in a field
    with arcpy.da.SearchCursor(table, [field]) as cursor:
        return sorted({row[0] for row in cursor})

vals=unique_values("S_Mosaic_Vendor_ComSat\\Footprint","Acquisition_Date") # Grab the unique acquisition dates

#Create new raster layer from Definition Query 

def_query = "Acquisition_Date = timestamp '" + vals[5].strftime("%Y-%m-%d %H:%M:%S")+"'" #definition query string
lyr_name="Image_"+vals[5].strftime("%b-%d-%Y") #layer name string

The problem is I only get the first image date to show up regardless of what Date I query for. Am I missing something or is this part of ArcPy still buggy? I am running ArcPro 2.3.4. I am going to try upgrading to 2.4 next week.

0 Kudos
0 Replies