Use Python API to get drawing info (symbology/renderer) of a hosted feature layer and apply it to a view layer.

286
1
Jump to solution
06-21-2021 02:03 PM
Kaz
by
New Contributor II

Hi everyone, 

I am writing some code using the Python API that will get the symbology of a hosted feature layer and apply that symbology to a view layer. The view layer data is referencing the hosted feature layer (so an exact copy). There are 30 view layers, so we need to be able to automate this process rather than updating the symbology of each view layer in ArcGIS Online. 

I am testing this with some Earthquake data from an ESRI training course. My idea is to get the JSON renderer/drawingInfo from the main Earthquake layer and update the service definition of the view layer with the main layer. See code below. 

I do get a "Success: True" message when I run this, however the drawingInfo properties don't actually update. I have also tried updating a more simple part of the properties (such as description) and that also doesn't update the properties even when the message returns "Success: True". This makes me wonder if I need higher privileges to run this code? I am currently a Publisher, not an Admin in my organization. 

I'm sure there are also a few ways to write this code so happy to hear recommendations if I'm going down a path that is too complex...

 

Kaz_0-1624309329442.png

 

0 Kudos
1 Solution

Accepted Solutions
Kaz
by
New Contributor II

I've figured this out myself but I will keep this post up so others can reference!

The problem was that layer.properties.drawingInfo returns the symbology as type PropertyMap, but update_definition requires the input is a dictionary

This same code will work and update symbology if you first get the properties:

EQ_properties = EQ_layer.properties

Then access the drawing info section of the property map, which will return a dictionary:

EQ_symbology = (EQ_properties['drawingInfo'])

Now you have the correct data type to update the definition of the view layer: 

EQ_view_layer.manager.update_definition({'drawingInfo': EQ_symbology})

Screenshot of the code:

Kaz_1-1624327375640.png

 

 

View solution in original post

1 Reply
Kaz
by
New Contributor II

I've figured this out myself but I will keep this post up so others can reference!

The problem was that layer.properties.drawingInfo returns the symbology as type PropertyMap, but update_definition requires the input is a dictionary

This same code will work and update symbology if you first get the properties:

EQ_properties = EQ_layer.properties

Then access the drawing info section of the property map, which will return a dictionary:

EQ_symbology = (EQ_properties['drawingInfo'])

Now you have the correct data type to update the definition of the view layer: 

EQ_view_layer.manager.update_definition({'drawingInfo': EQ_symbology})

Screenshot of the code:

Kaz_1-1624327375640.png

 

 

View solution in original post