<?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 API for Python: How to query a layer, add symbology to it, then add layer to webmap/error in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/api-for-python-how-to-query-a-layer-add-symbology/m-p/1380577#M57401</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I'm trying to do something which I feel should be easy:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1. bringing in a feature layer from a service API. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. Querying it.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. Adding symbology to this&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4.. Then adding this to a webmap.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I can run steps 1,2 and 4 fine. But adding the symbology (which will categorise the data) I'm finding very tricky, there seems to be no documentation at all on how to convert a featureset to a featurelayer with applied symbology. I feel I have achieved this, but now when I try and add this to the map it causes an error that says my file is too big (100mb+) to add, even though when I don't add the symbology and jsut add the featureset, it works fine.&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;import json&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;from arcgis.gis import GIS&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;from arcgis.features import FeatureLayer, FeatureSet,FeatureCollection&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;from arcgis.mapping import WebMap&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;import arcpy&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;gis = GIS("pro")&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;#get webmap&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;webmap_search = gis.content.search(&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;query = "test_webmap",&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;item_type="Web Map"&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;webmap_item = WebMap(webmap_search[0])&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;#get service layer&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;azure_layer = FeatureLayer(&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;"&lt;A href="https://arcgis.dalcourmaclaren.com/server/rest/services/GeostoreAzure/NGET_AzureInterestTasks/FeatureServer/0" target="_blank" rel="nofollow noopener"&gt;https://arcgis.anon.com/server/rest/services/GeoAzure/NGE_AzureTasks/FeatureServer/0&lt;/A&gt;"&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;#get symbology of service layer&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;renderer_ = azure_layer.properties["drawingInfo"]["renderer"]&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;#&lt;/STRONG&gt;&lt;/EM&gt;Query this service layer&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;where_clause = "(Scheme = 2205505698) AND (TaskCode = 'A')"&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;results = azure_layer.query(&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;where = where_clause,&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;result_record_count = 10&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;#the query returns a featureset - so we convert it to a feature collection&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;results_publish = FeatureCollection.from_featureset(results)&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;#add layer with renderer to webmap&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;webmap_item.add_layer(results,{'renderer':renderer_} )&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;webmap_item.update()&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;At the very last line - webmap_item.update()...&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I get this error:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Exception: The size of text cannot be more than 100Mb.&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;(Error Code: 400)&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;But when I run the code without all the renderer stuff, it works fine.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Plus I have queried the data layer to be 10 rows... so it should be small. I have also added it not to the map but as a standalone layer in My Content and it works fine.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Feb 2024 20:12:13 GMT</pubDate>
    <dc:creator>Obstreperous</dc:creator>
    <dc:date>2024-02-09T20:12:13Z</dc:date>
    <item>
      <title>API for Python: How to query a layer, add symbology to it, then add layer to webmap/error</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/api-for-python-how-to-query-a-layer-add-symbology/m-p/1380577#M57401</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I'm trying to do something which I feel should be easy:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1. bringing in a feature layer from a service API. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. Querying it.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. Adding symbology to this&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4.. Then adding this to a webmap.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I can run steps 1,2 and 4 fine. But adding the symbology (which will categorise the data) I'm finding very tricky, there seems to be no documentation at all on how to convert a featureset to a featurelayer with applied symbology. I feel I have achieved this, but now when I try and add this to the map it causes an error that says my file is too big (100mb+) to add, even though when I don't add the symbology and jsut add the featureset, it works fine.&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;import json&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;from arcgis.gis import GIS&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;from arcgis.features import FeatureLayer, FeatureSet,FeatureCollection&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;from arcgis.mapping import WebMap&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;import arcpy&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;gis = GIS("pro")&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;#get webmap&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;webmap_search = gis.content.search(&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;query = "test_webmap",&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;item_type="Web Map"&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;webmap_item = WebMap(webmap_search[0])&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;#get service layer&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;azure_layer = FeatureLayer(&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;"&lt;A href="https://arcgis.dalcourmaclaren.com/server/rest/services/GeostoreAzure/NGET_AzureInterestTasks/FeatureServer/0" target="_blank" rel="nofollow noopener"&gt;https://arcgis.anon.com/server/rest/services/GeoAzure/NGE_AzureTasks/FeatureServer/0&lt;/A&gt;"&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;#get symbology of service layer&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;renderer_ = azure_layer.properties["drawingInfo"]["renderer"]&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;#&lt;/STRONG&gt;&lt;/EM&gt;Query this service layer&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;where_clause = "(Scheme = 2205505698) AND (TaskCode = 'A')"&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;results = azure_layer.query(&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;where = where_clause,&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;result_record_count = 10&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;#the query returns a featureset - so we convert it to a feature collection&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;results_publish = FeatureCollection.from_featureset(results)&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;#add layer with renderer to webmap&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;webmap_item.add_layer(results,{'renderer':renderer_} )&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;webmap_item.update()&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;At the very last line - webmap_item.update()...&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I get this error:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Exception: The size of text cannot be more than 100Mb.&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;(Error Code: 400)&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;But when I run the code without all the renderer stuff, it works fine.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Plus I have queried the data layer to be 10 rows... so it should be small. I have also added it not to the map but as a standalone layer in My Content and it works fine.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 20:12:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/api-for-python-how-to-query-a-layer-add-symbology/m-p/1380577#M57401</guid>
      <dc:creator>Obstreperous</dc:creator>
      <dc:date>2024-02-09T20:12:13Z</dc:date>
    </item>
  </channel>
</rss>

