<?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 How to add a filter to an ArcGIS Online item using the Python API? in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/791674#M1610</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to add a filtered view of an ArcServer map service (or feature service, if necessary) to ArcGIS Online by REST service URL using the API for Python. I can create the item in ArcGIS online using the url, but how do I add a filter? When I do this manually, I add the item to my content, go to the item details page, got the Visualization tab, click filter, add the filter, and save. Can this be done programmatically, using the Python API? Any help would be appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: Perhaps layer definition or definition expression are better terms than filter.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 Dec 2017 23:42:04 GMT</pubDate>
    <dc:creator>GregMcNamee</dc:creator>
    <dc:date>2017-12-05T23:42:04Z</dc:date>
    <item>
      <title>How to add a filter to an ArcGIS Online item using the Python API?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/791674#M1610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to add a filtered view of an ArcServer map service (or feature service, if necessary) to ArcGIS Online by REST service URL using the API for Python. I can create the item in ArcGIS online using the url, but how do I add a filter? When I do this manually, I add the item to my content, go to the item details page, got the Visualization tab, click filter, add the filter, and save. Can this be done programmatically, using the Python API? Any help would be appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: Perhaps layer definition or definition expression are better terms than filter.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Dec 2017 23:42:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/791674#M1610</guid>
      <dc:creator>GregMcNamee</dc:creator>
      <dc:date>2017-12-05T23:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a filter to an ArcGIS Online item using the Python API?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/791675#M1611</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Greg,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code below shows how you could update the filter for a FeatureService with 1 FeatureLayer in its collection.&lt;/P&gt;&lt;P&gt;It could be expanded to multiple layers within the collection if needed using a loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just modify the Username, Password, and the title of the FeatureService to modify.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take a look and let me know how it goes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jeff&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;import &lt;/SPAN&gt;copy,json&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;from &lt;/SPAN&gt;arcgis.gis &lt;SPAN style="color: #000080; font-weight: bold;"&gt;import &lt;/SPAN&gt;GIS&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;gis = GIS(&lt;SPAN style="color: #008080; font-weight: bold;"&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fwww.arcgis.com" target="_blank"&gt;https://www.arcgis.com&lt;/A&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;, &lt;SPAN style="color: #008080; font-weight: bold;"&gt;"&amp;lt;USERNAME&amp;gt;"&lt;/SPAN&gt;, &lt;SPAN style="color: #008080; font-weight: bold;"&gt;"&amp;lt;PASSWORD&amp;gt;"&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;srcResults = gis.content.search(&lt;SPAN style="color: #008080; font-weight: bold;"&gt;"title:ServiceAreas"&lt;/SPAN&gt;,&lt;SPAN style="color: #660099;"&gt;item_type &lt;/SPAN&gt;= &lt;SPAN style="color: #008080; font-weight: bold;"&gt;"Feature Layer"&lt;/SPAN&gt;)
featCollection = srcResults[&lt;SPAN style="color: #0000ff;"&gt;0&lt;/SPAN&gt;]&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #808080;"&gt;#update a featurecollection layer filter
&lt;/SPAN&gt;featCollD = featCollection.get_data(&lt;SPAN style="color: #660099;"&gt;try_json&lt;/SPAN&gt;=&lt;SPAN style="color: #000080; font-weight: bold;"&gt;True&lt;/SPAN&gt;)

&lt;SPAN style="color: #808080;"&gt;#make a copy to manipulate the properties
&lt;/SPAN&gt;featCollDCopy = copy.deepcopy(featCollD)

sql = &lt;SPAN style="color: #008080; font-weight: bold;"&gt;'ServArNu = 2'
&lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #808080;"&gt;#The code below assumes that 1 FeatureLayer was found within the collection
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;#Modify the number or loop on the layers for more&lt;/SPAN&gt;&lt;/PRE&gt;featCollDCopy[&lt;SPAN style="color: #008080; font-weight: bold;"&gt;'layers'&lt;/SPAN&gt;][&lt;SPAN style="color: #0000ff;"&gt;0&lt;/SPAN&gt;][&lt;SPAN style="color: #008080; font-weight: bold;"&gt;'layerDefinition'&lt;/SPAN&gt;][&lt;SPAN style="color: #008080; font-weight: bold;"&gt;'definitionExpression'&lt;/SPAN&gt;] = sql&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #808080;"&gt;#send the update to modify the Feature Layers within the FeatureCollection&lt;/SPAN&gt;&lt;/PRE&gt;&lt;BR /&gt;featCollection.update(&lt;SPAN style="color: #660099;"&gt;item_properties&lt;/SPAN&gt;={&lt;SPAN style="color: #008080; font-weight: bold;"&gt;'text'&lt;/SPAN&gt;:json.dumps(featCollDCopy)})&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:04:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/791675#M1611</guid>
      <dc:creator>JeffBigos</dc:creator>
      <dc:date>2021-12-12T09:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a filter to an ArcGIS Online item using the Python API?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/791676#M1612</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jul 2018 13:30:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/791676#M1612</guid>
      <dc:creator>GregMcNamee</dc:creator>
      <dc:date>2018-07-18T13:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a filter to an ArcGIS Online item using the Python API?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/791677#M1613</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for the input, it works great. If that's not too much to ask, maybe you could help me out!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I ran this code to apply a filter to a web feature layer hosted on my web server and it works great. The problem is when i create a view (create_view) made from this parenting layer, the filter is not carried with it. And re-using this code doesn't work as the layer as no properties for some reason. Here's the code :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;srcResults = gis.content.search(&lt;SPAN style="color: #aa4926;"&gt;query&lt;/SPAN&gt;=&lt;SPAN style="color: #6a8759;"&gt;'ENERGEREGLOBALE_V2'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #aa4926;"&gt;item_type&lt;/SPAN&gt;=&lt;SPAN style="color: #6a8759;"&gt;'Feature Layer'&lt;/SPAN&gt;)
featCollection = srcResults[&lt;SPAN style="color: #6897bb;"&gt;0&lt;/SPAN&gt;]

&lt;SPAN style="color: #808080;"&gt;# update a featurecollection layer filter
&lt;/SPAN&gt;featCollD = featCollection.get_data(&lt;SPAN style="color: #aa4926;"&gt;try_json&lt;/SPAN&gt;=&lt;SPAN style="color: #cc7832;"&gt;True&lt;/SPAN&gt;)

&lt;SPAN style="color: #808080;"&gt;# make a copy to manipulate the properties
&lt;/SPAN&gt;featCollDCopy = copy.deepcopy(featCollD)

sql = &lt;SPAN style="color: #6a8759;"&gt;'Municipalité IS NULL'
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;# The code below assumes that 1 FeatureLayer was found within the collection
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;# Modify the number or loop on the layers for more
&lt;/SPAN&gt;featCollDCopy[&lt;SPAN style="color: #6a8759;"&gt;'layers'&lt;/SPAN&gt;][&lt;SPAN style="color: #6897bb;"&gt;0&lt;/SPAN&gt;][&lt;SPAN style="color: #6a8759;"&gt;'layerDefinition'&lt;/SPAN&gt;][&lt;SPAN style="color: #6a8759;"&gt;'definitionExpression'&lt;/SPAN&gt;] = sql

&lt;SPAN style="color: #808080;"&gt;# send the update to modify the Feature Layers within the FeatureCollection
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;featCollection.update(&lt;SPAN style="color: #aa4926;"&gt;item_properties&lt;/SPAN&gt;={&lt;SPAN style="color: #6a8759;"&gt;'text'&lt;/SPAN&gt;: json.dumps(featCollDCopy)})
&lt;SPAN style="color: #8888c6;"&gt;print&lt;/SPAN&gt;(featCollection.get_data(&lt;SPAN style="color: #aa4926;"&gt;try_json&lt;/SPAN&gt;=&lt;SPAN style="color: #cc7832;"&gt;True&lt;/SPAN&gt;))



&lt;SPAN style="color: #808080;"&gt;################################################################# #Generate View
&lt;/SPAN&gt;flc = arcgis.features.FeatureLayerCollection.fromitem(featCollection)
view = flc.manager.create_view(&lt;SPAN style="color: #aa4926;"&gt;name&lt;/SPAN&gt;=&lt;SPAN style="color: #6a8759;"&gt;'TEST'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #aa4926;"&gt;spatial_reference&lt;/SPAN&gt;=&lt;SPAN style="color: #cc7832;"&gt;None, &lt;/SPAN&gt;&lt;SPAN style="color: #aa4926;"&gt;extent&lt;/SPAN&gt;=&lt;SPAN style="color: #cc7832;"&gt;None, &lt;/SPAN&gt;&lt;SPAN style="color: #aa4926;"&gt;allow_schema_changes&lt;/SPAN&gt;=&lt;SPAN style="color: #cc7832;"&gt;False, &lt;/SPAN&gt;&lt;SPAN style="color: #aa4926;"&gt;updateable&lt;/SPAN&gt;=&lt;SPAN style="color: #cc7832;"&gt;True, &lt;/SPAN&gt;&lt;SPAN style="color: #aa4926;"&gt;capabilities&lt;/SPAN&gt;=&lt;SPAN style="color: #6a8759;"&gt;'Query, Update, Delete'&lt;/SPAN&gt;) &lt;SPAN style="color: #808080;"&gt;#view_layers= [flc.layers[0]]
&lt;/SPAN&gt;&lt;SPAN style="color: #8888c6;"&gt;print&lt;/SPAN&gt;(view)&lt;/PRE&gt;&lt;P&gt;If you guys have any idea on how to make the filter follow the view, or how to apply a new filter to the view, that would be very appreciated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;R.Muller&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:04:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/791677#M1613</guid>
      <dc:creator>MaximeCampeau</dc:creator>
      <dc:date>2021-12-12T09:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a filter to an ArcGIS Online item using the Python API?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/791678#M1614</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/migrated-users/322651"&gt;Maxime Campeau&lt;/A&gt;‌,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you can update a view layer with a new definition query but I don't think you can create a view layer from another view layer.&lt;/P&gt;&lt;P&gt;For more information about how to&amp;nbsp;update the viewDefinitionQuery property you can refer to the link below about "Using the ArcGIS API for Python to create a view from a Hosted Feature Layer and to define a view definition" by Earl Medina&lt;SPAN style="color: #8b8b8b;"&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #8b8b8b;"&gt;&lt;A href="https://community.esri.com/groups/arcgis-python-api/blog/2019/02/11/using-the-arcgis-api-for-python-to-create-a-view-from-a-hosted-feature-layer-and-to-define-a-view-fefinition"&gt;https://community.esri.com/groups/arcgis-python-api/blog/2019/02/11/using-the-arcgis-api-for-python-to-create-a-view-from-a-hosted-feature-layer-and-to-define-a-view-fefinition&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #8b8b8b;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Aug 2019 08:09:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/791678#M1614</guid>
      <dc:creator>MehdiPira1</dc:creator>
      <dc:date>2019-08-19T08:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a filter to an ArcGIS Online item using the Python API?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/1291591#M8713</link>
      <description>&lt;P&gt;How does this work for layers that not Hosted Featurelayers instead they are hosted in User managed Enterprise Geodatabase (e.g ArcSDE)&lt;/P&gt;</description>
      <pubDate>Mon, 22 May 2023 14:17:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/1291591#M8713</guid>
      <dc:creator>imranrajjad_cc</dc:creator>
      <dc:date>2023-05-22T14:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a filter to an ArcGIS Online item using the Python API?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/1398125#M9790</link>
      <description>&lt;P&gt;You can also filter the layer using update definition and the property you're adjusting via admin REST api.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this case, a view layer required a filter view from the parent host layer:&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;"viewDefinitionQuery": "fieldname = value"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2024 22:35:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-a-filter-to-an-arcgis-online-item-using/m-p/1398125#M9790</guid>
      <dc:creator>RyanDickinson1</dc:creator>
      <dc:date>2024-03-19T22:35:00Z</dc:date>
    </item>
  </channel>
</rss>

