Create a new layer of mosaic dataset with definition query in ArcMap.

929
6
03-31-2020 06:37 AM
BenasPekarskis1
New Contributor II

Hello GISesrs,

Hope you are keeping safe in current events. 

Im trying to Save new mosaic dataset with new definition query. But it seems that the script below saves new mosaic dataset, but without a query. Any advise would be appreciated. 

import arcpy
mxd = arcpy.mapping.MapDocument(\Historic_Maps.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
field = 'Date'
values = "'1950'"
query=str(field) +" "+ "=" + str(values)

for lyr in arcpy.mapping.ListLayers(mxd, "*"):
     if lyr.name == "Sacle_1250":
        lyr.definitionQuery = query
        arcpy.mapping.AddLayer(df, lyr, "BOTTOM")

arcpy.RefreshActiveView()
arcpy.RefreshTOC()
mxd.saveACopy (\my_mxd3.mxd")
del mxd

0 Kudos
6 Replies
DavidPike
MVP Frequent Contributor
field = "Date"
values = "1950"
query = '"' + field + " = " + values + '"'

Is it Sacle_1250 or Scale_1250 maybe?

0 Kudos
BenasPekarskis1
New Contributor II

Thanks David.  

The typo happened while copying the code into Geonet. 

I have tried your suggested query. unfortunately it doesnt do the trick. 

Mosaic datsets have three component: Boundary, Footprint and Image. 

Definition queries are set in Footprint. 

The naming of footprint is a mystery for me as well. 

For instance I have some possible options in 

if lyr.name == "Sacle_1250":

I have tried Scale_1250\Footprint, I have tried Scale_1250\AMD_Scale_1250_CAT

Nothing seems to work. 

Regards,

Ben

0 Kudos
DavidPike
MVP Frequent Contributor

I'll try it on a dummy mosaic and get the syntax right for you.

The data type on your screenshot is FGdb Raster Catalog not Mosaic Dataset?

0 Kudos
BenasPekarskis1
New Contributor II

This is what confusing me.   When I view properties it is Mosaic dataset. I also created a new from scratch as a mosaic dataset. 

But when I view properties of Footprint, it says its Raster catalog: 

0 Kudos
DavidPike
MVP Frequent Contributor

Hi Benas,

I've tried multiple syntax but no avail. I've been able to apply definition queries to feature classes using your code, but not a MD. 

wrt the raster catalog footprints, it seems this is correct for a mosaic dataset (I think the MD is a repackaged raster catalog rolled in glitter)

Look forward to someone solving this.

0 Kudos
BenasPekarskis1
New Contributor II

Thanks David, 

I think it might be related to this bug- NIM067173: A definition query applied to a Mosaic Dataset is no.. 

Regards,

Ben

0 Kudos