Control query def of Image service

267
1
04-04-2023 01:28 AM
mody_buchbinder
Occasional Contributor III

This problem connects to other community but I would like to get a python answer.

I am creating an image service with query def.

I just create an image service (based on Mosaic). I load it into classic web map, set a query def and do a Save Layer.

When I show this image service in Web Map (classic) and Pro I can see the query def.

When I show the rest information I cannot see the query def.

I found no way in Python api or rest to change (or even see) the query def.

My understanding was that EVERYTHING is shown in the rest.

I do not see such operation in REST or property in ImageLayer for python.

Thanks

0 Kudos
1 Reply
Clubdebambos
Occasional Contributor III

Hi @mody_buchbinder 

I have no Image Service to test this on. If you have set a filter (definition query) in the WebMap it can be accessed via the Python API. The below works for layers in a WebMap. The code is commented. I hope it helps.

 

from arcgis import GIS

## connect to the AGOL instance
agol = GIS("home")

## reference the webamp through the id provided
item = agol.content.get("INSERT_WM_ID")

## reference the webmap content/config
item_data = item.get_data()

## the title of the layer in the webmap
wm_lyr_title = ""

## for each operationalLayer in the webmap
for lyr in item_data["operationalLayers"]:
    ## if the layer matches the title of interest
    if lyr["title"] == wm_lyr_title:
        ## if a filter is set in the webmap the ['layerDefinition']['definitionExpression'] can be accessed
        try:
            print(lyr['layerDefinition']['definitionExpression'])
        ## if no filter set a Key Error will be thrown
        ## ['layerDefinition']['definitionExpression'] only exists in JSON when a filter set
        except KeyError:
            print(wm_lyr_title,"has no definition query / filter set")

 

 

You can also find the JSON using AGO Assistant https://ago-assistant.esri.com/

From the banner at the top of the screen click on the I want to... dropdown and select View an Item's JSON

 

~ learn.finaldraftmapping.com
0 Kudos