<?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: How to style (color) a polygon based on a field value in a feature layer in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-style-color-a-polygon-based-on-a-field/m-p/1593851#M11218</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/696297"&gt;@Ef&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;It seems you are quite close here. From the information provided it looks like you are trying to add a Layer to a WebMap (operationalLayers) and set the symbology (renderer).&lt;/P&gt;&lt;P&gt;Check the commented code below for the workflow.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS

## access ArcGIS Online
agol = GIS("home")

## get the WebMap Item as an Item object
wm_item = agol.content.get("WM_ITEM_ID")

## get the WebMap Definition
wm_def = wm_item.get_data()

## get the current opetaionalLayers as a list
ol = wm_def["operationalLayers"]

## create the renderer definition
my_renderer = {...}

## create the new layer definition with the renderer
## notice the path to the renderer in the layerDefinition property
new_lyr_def = {
        "url": f"{FEATURE_LAYER_URL}/0",
        "type": "FeatureLayer",
        "title": "ProjectBoundaries",
        "token": SOME_TOKEN,
        "opacity": 0.4,
        "minScale": 0,
        "maxScale": 0,
        "layerDefinition": {
            "drawingInfo" : {
                "renderer" : my_renderer
            }
        }
}

## append the new layer to the ol list
ol.append(new_lyr_def)

## test print to make sure the layer has been added
print(ol)

## if not adding try the below
#ol = ol + [new_lyr_def]

## assign the new ol to the WebMap OL Definition
wm_def["operationalLayers"] = ol

## create a dictionary to hold the new update info
update_properties = {"text" : wm_def}

## apply the update to the WebMap Item object
wm_itm.update(
    "item_properties" : update_properties
)&lt;/LI-CODE&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;Glen&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Mar 2025 16:11:45 GMT</pubDate>
    <dc:creator>Clubdebambos</dc:creator>
    <dc:date>2025-03-10T16:11:45Z</dc:date>
    <item>
      <title>How to style (color) a polygon based on a field value in a feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-style-color-a-polygon-based-on-a-field/m-p/1557298#M10870</link>
      <description>&lt;P&gt;I have a method to create a feature layer. it consists of polygons. Each represent a unit. these units have a field of unit_type. Based on the type I would the polygon to have a different color.&lt;BR /&gt;I created a renderer to handle the logic&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;my_renderer &lt;/SPAN&gt;= {&lt;BR /&gt;    &lt;SPAN&gt;"type"&lt;/SPAN&gt;: &lt;SPAN&gt;"uniqueValue"&lt;/SPAN&gt;,&lt;BR /&gt;    &lt;SPAN&gt;"field1"&lt;/SPAN&gt;: &lt;SPAN&gt;"unit_type"&lt;/SPAN&gt;,&lt;BR /&gt;    &lt;SPAN&gt;"uniqueValueInfos"&lt;/SPAN&gt;: [&lt;BR /&gt;        {&lt;BR /&gt;            &lt;SPAN&gt;"value"&lt;/SPAN&gt;: &lt;SPAN&gt;"YES_WORK"&lt;/SPAN&gt;,&lt;BR /&gt;            &lt;SPAN&gt;"symbol"&lt;/SPAN&gt;: {&lt;BR /&gt;                &lt;SPAN&gt;"type"&lt;/SPAN&gt;: &lt;SPAN&gt;"esriSFS"&lt;/SPAN&gt;,&lt;BR /&gt;                &lt;SPAN&gt;"style"&lt;/SPAN&gt;: &lt;SPAN&gt;"esriSFSSolid"&lt;/SPAN&gt;,&lt;BR /&gt;                &lt;SPAN&gt;"color"&lt;/SPAN&gt;: [&lt;SPAN&gt;0&lt;/SPAN&gt;, &lt;SPAN&gt;0&lt;/SPAN&gt;, &lt;SPAN&gt;255&lt;/SPAN&gt;, &lt;SPAN&gt;128&lt;/SPAN&gt;],  &lt;SPAN&gt;# Blue&lt;BR /&gt;&lt;/SPAN&gt;                &lt;SPAN&gt;"outline"&lt;/SPAN&gt;: {&lt;BR /&gt;                    &lt;SPAN&gt;"type"&lt;/SPAN&gt;: &lt;SPAN&gt;"esriSLS"&lt;/SPAN&gt;,&lt;BR /&gt;                    &lt;SPAN&gt;"style"&lt;/SPAN&gt;: &lt;SPAN&gt;"esriSLSSolid"&lt;/SPAN&gt;,&lt;BR /&gt;                    &lt;SPAN&gt;"color"&lt;/SPAN&gt;: [&lt;SPAN&gt;255&lt;/SPAN&gt;, &lt;SPAN&gt;255&lt;/SPAN&gt;, &lt;SPAN&gt;255&lt;/SPAN&gt;, &lt;SPAN&gt;255&lt;/SPAN&gt;],&lt;BR /&gt;                    &lt;SPAN&gt;"width"&lt;/SPAN&gt;: &lt;SPAN&gt;1&lt;BR /&gt;&lt;/SPAN&gt;                }&lt;BR /&gt;            },&lt;BR /&gt;            &lt;SPAN&gt;"label"&lt;/SPAN&gt;: &lt;SPAN&gt;"Yes Work"&lt;BR /&gt;&lt;/SPAN&gt;        },&lt;BR /&gt;        {&lt;BR /&gt;            &lt;SPAN&gt;"value"&lt;/SPAN&gt;: &lt;SPAN&gt;"NO_WORK"&lt;/SPAN&gt;,&lt;BR /&gt;            &lt;SPAN&gt;"symbol"&lt;/SPAN&gt;: {&lt;BR /&gt;                &lt;SPAN&gt;"type"&lt;/SPAN&gt;: &lt;SPAN&gt;"esriSFS"&lt;/SPAN&gt;,&lt;BR /&gt;                &lt;SPAN&gt;"style"&lt;/SPAN&gt;: &lt;SPAN&gt;"esriSFSSolid"&lt;/SPAN&gt;,&lt;BR /&gt;                &lt;SPAN&gt;"color"&lt;/SPAN&gt;: [&lt;SPAN&gt;255&lt;/SPAN&gt;, &lt;SPAN&gt;0&lt;/SPAN&gt;, &lt;SPAN&gt;0&lt;/SPAN&gt;, &lt;SPAN&gt;128&lt;/SPAN&gt;],  &lt;SPAN&gt;# Red&lt;BR /&gt;&lt;/SPAN&gt;                &lt;SPAN&gt;"outline"&lt;/SPAN&gt;: {&lt;BR /&gt;                    &lt;SPAN&gt;"type"&lt;/SPAN&gt;: &lt;SPAN&gt;"esriSLS"&lt;/SPAN&gt;,&lt;BR /&gt;                    &lt;SPAN&gt;"style"&lt;/SPAN&gt;: &lt;SPAN&gt;"esriSLSSolid"&lt;/SPAN&gt;,&lt;BR /&gt;                    &lt;SPAN&gt;"color"&lt;/SPAN&gt;: [&lt;SPAN&gt;255&lt;/SPAN&gt;, &lt;SPAN&gt;255&lt;/SPAN&gt;, &lt;SPAN&gt;255&lt;/SPAN&gt;, &lt;SPAN&gt;255&lt;/SPAN&gt;],&lt;BR /&gt;                    &lt;SPAN&gt;"width"&lt;/SPAN&gt;: &lt;SPAN&gt;1&lt;BR /&gt;&lt;/SPAN&gt;                }&lt;BR /&gt;            },&lt;BR /&gt;            &lt;SPAN&gt;"label"&lt;/SPAN&gt;: &lt;SPAN&gt;"NO_WORK"&lt;BR /&gt;&lt;/SPAN&gt;        }&lt;BR /&gt;    ],&lt;BR /&gt;    &lt;SPAN&gt;"defaultSymbol"&lt;/SPAN&gt;: {&lt;BR /&gt;        &lt;SPAN&gt;"type"&lt;/SPAN&gt;: &lt;SPAN&gt;"esriSFS"&lt;/SPAN&gt;,&lt;BR /&gt;        &lt;SPAN&gt;"style"&lt;/SPAN&gt;: &lt;SPAN&gt;"esriSFSSolid"&lt;/SPAN&gt;,&lt;BR /&gt;        &lt;SPAN&gt;"color"&lt;/SPAN&gt;: [&lt;SPAN&gt;0&lt;/SPAN&gt;, &lt;SPAN&gt;0&lt;/SPAN&gt;, &lt;SPAN&gt;255&lt;/SPAN&gt;, &lt;SPAN&gt;128&lt;/SPAN&gt;],  &lt;SPAN&gt;# Default color (Blue)&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;"outline"&lt;/SPAN&gt;: {&lt;BR /&gt;            &lt;SPAN&gt;"type"&lt;/SPAN&gt;: &lt;SPAN&gt;"esriSLS"&lt;/SPAN&gt;,&lt;BR /&gt;            &lt;SPAN&gt;"style"&lt;/SPAN&gt;: &lt;SPAN&gt;"esriSLSSolid"&lt;/SPAN&gt;,&lt;BR /&gt;            &lt;SPAN&gt;"color"&lt;/SPAN&gt;: [&lt;SPAN&gt;255&lt;/SPAN&gt;, &lt;SPAN&gt;255&lt;/SPAN&gt;, &lt;SPAN&gt;255&lt;/SPAN&gt;, &lt;SPAN&gt;255&lt;/SPAN&gt;],&lt;BR /&gt;            &lt;SPAN&gt;"width"&lt;/SPAN&gt;: &lt;SPAN&gt;1&lt;BR /&gt;&lt;/SPAN&gt;        }&lt;BR /&gt;    },&lt;BR /&gt;    &lt;SPAN&gt;"defaultLabel"&lt;/SPAN&gt;: &lt;SPAN&gt;"Default"&lt;BR /&gt;&lt;/SPAN&gt;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and to pass it here to create the layer&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;operational_layers.append(&lt;BR /&gt;    {&lt;BR /&gt;        &lt;SPAN&gt;"url"&lt;/SPAN&gt;: &lt;SPAN&gt;f"&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;FEATURE_LAYER_URL&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;/0"&lt;/SPAN&gt;,&lt;BR /&gt;        &lt;SPAN&gt;"type"&lt;/SPAN&gt;: &lt;SPAN&gt;"FeatureLayer"&lt;/SPAN&gt;,&lt;BR /&gt;        &lt;SPAN&gt;"title"&lt;/SPAN&gt;: &lt;SPAN&gt;"ProjectBoundaries"&lt;/SPAN&gt;,&lt;BR /&gt;        &lt;SPAN&gt;"token"&lt;/SPAN&gt;: &lt;SPAN&gt;SOME_TOKEN&lt;/SPAN&gt;,&lt;BR /&gt;        &lt;SPAN&gt;"opacity"&lt;/SPAN&gt;: &lt;SPAN&gt;0.4&lt;/SPAN&gt;,&lt;BR /&gt;        &lt;SPAN&gt;"minScale"&lt;/SPAN&gt;: &lt;SPAN&gt;0&lt;/SPAN&gt;,&lt;BR /&gt;        &lt;SPAN&gt;"maxScale"&lt;/SPAN&gt;: &lt;SPAN&gt;0&lt;/SPAN&gt;,&lt;BR /&gt;        &lt;SPAN&gt;"renderer"&lt;/SPAN&gt;: my_renderer  &lt;SPAN&gt;# Ensure the renderer is included here&lt;BR /&gt;&lt;/SPAN&gt;    }&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;export_map_task_payload = {&lt;BR /&gt;    &lt;SPAN&gt;"operationalLayers"&lt;/SPAN&gt;: operational_layers,&lt;BR /&gt;    &lt;SPAN&gt;"mapOptions"&lt;/SPAN&gt;: {&lt;BR /&gt;        &lt;SPAN&gt;"extent"&lt;/SPAN&gt;: extent,&lt;BR /&gt;        &lt;SPAN&gt;"spatialReference"&lt;/SPAN&gt;: {&lt;BR /&gt;            &lt;SPAN&gt;"latestWkid"&lt;/SPAN&gt;: &lt;SPAN&gt;3857&lt;/SPAN&gt;,&lt;BR /&gt;            &lt;SPAN&gt;"wkid"&lt;/SPAN&gt;: &lt;SPAN&gt;102100&lt;BR /&gt;&lt;/SPAN&gt;        },&lt;BR /&gt;        &lt;SPAN&gt;"showAttribution"&lt;/SPAN&gt;: &lt;SPAN&gt;True&lt;/SPAN&gt;,&lt;BR /&gt;    },&lt;BR /&gt;    &lt;SPAN&gt;"exportOptions"&lt;/SPAN&gt;: {&lt;BR /&gt;        &lt;SPAN&gt;"outputSize"&lt;/SPAN&gt;: [&lt;SPAN&gt;800&lt;/SPAN&gt;, &lt;SPAN&gt;800&lt;/SPAN&gt;]&lt;BR /&gt;    }&lt;BR /&gt;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;but it doesn't work. What is wrong. and if this is not not the way how to achieve the requirement&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2024 15:43:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-style-color-a-polygon-based-on-a-field/m-p/1557298#M10870</guid>
      <dc:creator>Ef</dc:creator>
      <dc:date>2024-11-11T15:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to style (color) a polygon based on a field value in a feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-style-color-a-polygon-based-on-a-field/m-p/1593851#M11218</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/696297"&gt;@Ef&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;It seems you are quite close here. From the information provided it looks like you are trying to add a Layer to a WebMap (operationalLayers) and set the symbology (renderer).&lt;/P&gt;&lt;P&gt;Check the commented code below for the workflow.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS

## access ArcGIS Online
agol = GIS("home")

## get the WebMap Item as an Item object
wm_item = agol.content.get("WM_ITEM_ID")

## get the WebMap Definition
wm_def = wm_item.get_data()

## get the current opetaionalLayers as a list
ol = wm_def["operationalLayers"]

## create the renderer definition
my_renderer = {...}

## create the new layer definition with the renderer
## notice the path to the renderer in the layerDefinition property
new_lyr_def = {
        "url": f"{FEATURE_LAYER_URL}/0",
        "type": "FeatureLayer",
        "title": "ProjectBoundaries",
        "token": SOME_TOKEN,
        "opacity": 0.4,
        "minScale": 0,
        "maxScale": 0,
        "layerDefinition": {
            "drawingInfo" : {
                "renderer" : my_renderer
            }
        }
}

## append the new layer to the ol list
ol.append(new_lyr_def)

## test print to make sure the layer has been added
print(ol)

## if not adding try the below
#ol = ol + [new_lyr_def]

## assign the new ol to the WebMap OL Definition
wm_def["operationalLayers"] = ol

## create a dictionary to hold the new update info
update_properties = {"text" : wm_def}

## apply the update to the WebMap Item object
wm_itm.update(
    "item_properties" : update_properties
)&lt;/LI-CODE&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;Glen&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2025 16:11:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-style-color-a-polygon-based-on-a-field/m-p/1593851#M11218</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2025-03-10T16:11:45Z</dc:date>
    </item>
  </channel>
</rss>

