Symbology for AGOL hosted feature layer created from upload?

296
1
Jump to solution
05-27-2020 04:56 PM
dcafdg
by
Occasional Contributor

Subject: setting and updating the symbology for a hosted feature layer created from a zipped FGDB. 

Background: I uploaded a zipped FGDB to AGOL and created a hosted feature layer from it. In the visualization tab of that hosted feature layer, I can manually set the symbology and save the layer. When I look at the description or data for the layer (either in Python or in the ArcGIS Online Assistant), I don't see any symbology. For hosted feature layers, it is usually in the data dict in ['layers'][0]['layerDefinition']['drawingInfo']['renderer'] (replace '0' with layer ID, as needed).

Problem: In my hosted feature layer, however, the layerDefinition only contains defaultVisibility (even after I've set symbology). I have several more of these to create and want to automate setting the symbology. 

Question: Where is that symbology stored and can I update it with Python? I attempted to set it based on another hosted feature layer that has the symbology I want. 

# Hosted feature layer created by uploading a zipped FGDB
hfl_item = portal.get_item_by_id(<id>)
hfl_data = hfl_item.get_data()

# Hosted feature layer created in Pro with fancy symbology
sym_item = portal.get_item_by_id(<id>)
sym_data = sym_item.get_data()

# Copy data from one and save to the other
drawingInfo = sym_data['layers'][0]['layerDefinition']['drawingInfo']
hfl_data['layers'][0]['layerDefinition']['drawingInfo'] = drawingInfo
result = hfl_item.update(data=hfl_data)‍‍‍‍‍‍‍‍‍‍‍‍

The last line produces the following exception:

Traceback (most recent call last):
File "C:\eclipse\plugins\org.python.pydev.core_7.3.0.201908161924\pysrc\pydevd.py", line 2643, in <module>
main()
File "C:\eclipse\plugins\org.python.pydev.core_7.3.0.201908161924\pysrc\pydevd.py", line 2636, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\eclipse\plugins\org.python.pydev.core_7.3.0.201908161924\pysrc\pydevd.py", line 1920, in run
return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
File "C:\eclipse\plugins\org.python.pydev.core_7.3.0.201908161924\pysrc\pydevd.py", line 1927, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\eclipse\plugins\org.python.pydev.core_7.3.0.201908161924\pysrc\_pydev_imps\_pydev_execfile.py", line 25, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:\Users\daskov\eclipse-workspace\Python Prototypes\src\geoprocessing\upload_zip.py", line 47, in <module>
result = hfl_item.update(data=hfl_data)
File "C:\Users\daskov\AppData\Local\ESRI\conda\envs\gis-dev\lib\site-packages\arcgis\gis\__init__.py", line 7874, in update
large_thumbnail)
File "C:\Users\daskov\AppData\Local\ESRI\conda\envs\gis-dev\lib\site-packages\arcgis\_impl\portalpy.py", line 2176, in update_item
if _is_http_url(data):
File "C:\Users\daskov\AppData\Local\ESRI\conda\envs\gis-dev\lib\site-packages\arcgis\_impl\connection.py", line 1308, in _is_http_url
return urlparse(url).scheme in ['http', 'https']
File "C:\Users\daskov\AppData\Local\ESRI\conda\envs\gis-dev\lib\urllib\parse.py", line 367, in urlparse
url, scheme, _coerce_result = _coerce_args(url, scheme)
File "C:\Users\daskov\AppData\Local\ESRI\conda\envs\gis-dev\lib\urllib\parse.py", line 123, in _coerce_args
return _decode_args(args) + (_encode_result,)
File "C:\Users\daskov\AppData\Local\ESRI\conda\envs\gis-dev\lib\urllib\parse.py", line 107, in _decode_args
return tuple(x.decode(encoding, errors) if x else '' for x in args)
File "C:\Users\daskov\AppData\Local\ESRI\conda\envs\gis-dev\lib\urllib\parse.py", line 107, in <genexpr>
return tuple(x.decode(encoding, errors) if x else '' for x in args)
AttributeError: 'dict' object has no attribute 'decode'
0 Kudos
1 Solution

Accepted Solutions
dcafdg
by
Occasional Contributor

I used the Python debugger to delve into the Esri source code and it was sending the data dict input to urllib's parse method. Predictably, that produced the error above. If you look at the stack trace, the bottom line is in urllib\parse.py.

Through pure serendipity, I had this in a folder of random dev scripts. I was working in the same folder on another project, which is running in a different conda environment. Forgetting to switch my conda environment back, I ran this code, and it worked! 

It appears the solution is to upgrade your arcgis module from 1.6.x (I'm not 100% sure what version I was on, but I think it shipped with Pro 2.4) to 1.8.0.

> activate <your_conda_env>
> conda upgrade -c esri arcgis --no-pin‍‍‍‍

View solution in original post

0 Kudos
1 Reply
dcafdg
by
Occasional Contributor

I used the Python debugger to delve into the Esri source code and it was sending the data dict input to urllib's parse method. Predictably, that produced the error above. If you look at the stack trace, the bottom line is in urllib\parse.py.

Through pure serendipity, I had this in a folder of random dev scripts. I was working in the same folder on another project, which is running in a different conda environment. Forgetting to switch my conda environment back, I ran this code, and it worked! 

It appears the solution is to upgrade your arcgis module from 1.6.x (I'm not 100% sure what version I was on, but I think it shipped with Pro 2.4) to 1.8.0.

> activate <your_conda_env>
> conda upgrade -c esri arcgis --no-pin‍‍‍‍

View solution in original post

0 Kudos