<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Control query def of Image service in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/control-query-def-of-image-service/m-p/1279175#M8603</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/413050"&gt;@mody_buchbinder&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also find the JSON using AGO Assistant&amp;nbsp;&lt;A href="https://ago-assistant.esri.com/" target="_blank"&gt;https://ago-assistant.esri.com/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;From the banner at the top of the screen click on the &lt;EM&gt;&lt;STRONG&gt;I want to...&lt;/STRONG&gt;&lt;/EM&gt; dropdown and select &lt;EM&gt;&lt;STRONG&gt;View an Item's JSON&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Apr 2023 09:40:52 GMT</pubDate>
    <dc:creator>Clubdebambos</dc:creator>
    <dc:date>2023-04-17T09:40:52Z</dc:date>
    <item>
      <title>Control query def of Image service</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/control-query-def-of-image-service/m-p/1275120#M8577</link>
      <description>&lt;P&gt;This problem connects to other community but I would like to get a python answer.&lt;/P&gt;&lt;P&gt;I am creating an image service with query def.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;When I show this image service in Web Map (classic) and Pro I can see the query def.&lt;/P&gt;&lt;P&gt;When I show the rest information I cannot see the query def.&lt;/P&gt;&lt;P&gt;I found no way in Python api or rest to change (or even see) the query def.&lt;/P&gt;&lt;P&gt;My understanding was that EVERYTHING is shown in the rest.&lt;/P&gt;&lt;P&gt;I do not see such operation in REST or property in ImageLayer for python.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 08:28:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/control-query-def-of-image-service/m-p/1275120#M8577</guid>
      <dc:creator>mody_buchbinder</dc:creator>
      <dc:date>2023-04-04T08:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Control query def of Image service</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/control-query-def-of-image-service/m-p/1279175#M8603</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/413050"&gt;@mody_buchbinder&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also find the JSON using AGO Assistant&amp;nbsp;&lt;A href="https://ago-assistant.esri.com/" target="_blank"&gt;https://ago-assistant.esri.com/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;From the banner at the top of the screen click on the &lt;EM&gt;&lt;STRONG&gt;I want to...&lt;/STRONG&gt;&lt;/EM&gt; dropdown and select &lt;EM&gt;&lt;STRONG&gt;View an Item's JSON&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 09:40:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/control-query-def-of-image-service/m-p/1279175#M8603</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2023-04-17T09:40:52Z</dc:date>
    </item>
  </channel>
</rss>

