I am using Jupyter Notebooks to automate some AGOL tasks. I have also tested this code in ArcGIS Pro and in Spyder with no luck. All using the same cloned environment. Cloned using ArcGIS Pro.
This specific section of my workflow involves creating offline areas to be used in Explorer for ArcGIS. The layers and maps do not have Editing enabled, but they do have Sync enabled. There are two layers that are Layer Views, each with a definition query applied.
Manually, using the AGOL: Manage Areas interface, I am able to easily draw and create an offline area that is downloadable in Explorer.
However, I cannot seem to get this to work reliably with the Python API.
from arcgis.gis import GIS
from arcgis.mapping import WebMap
from arcgis import env
env.verbose = True
#sign into gis
gis = GIS("My_GIS", "My_Username")
print("Successfully logged in as: " + gis.properties.user.username)
wm_item = gis.content.get('My_AGOL_Item')
wm_item
wm = WebMap(wm_item)
extentdict = {'xmin': -x,
'ymin': y,
'xmax': -x,
'ymax': y,
'spatialReference':{'wkid': 3857}}
offline_item_properties = {'title': 'Re21_App1_North',
'tags': ['Reassessment', 'Appraiser']}
A1_North = wm.offline_areas.create(area = extentdict,
item_properties = offline_item_properties,
folder='Appraiser Maps',
min_scale=160000,
max_scale=1500)
This is almost exactly following the API Reference except that I use an extent instead of a bookmark.
This exact code worked last week. But now it is throwing an error. The error is referencing Line 1755 'layer0_obj' in the _types.py script.
Note: The offline area is created without any packages and is stuck on "Packaging" indefinitely.
Submitted.
Executing...
Start Time: Friday, May 29, 2020 3:42:58 PM
Running script CreateMapArea...
Completed script CreateMapArea...
Succeeded at Friday, May 29, 2020 3:42:59 PM (Elapsed Time: 1.22 seconds)
CreateMapArea GP Job: x_____xTwPeRg5tQfrLowkK0gxr-Q..x_____xj0aedb71fa5af431ab38f6ae4be4bfd2a finished successfully.
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-6-f1b0325e3428> in <module>
5 item_properties = offline_item_properties,
6 min_scale = 160000,
----> 7 max_scale = 1250)
~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\mapping\_types.py in create(self, area, item_properties, folder, min_scale, max_scale, layers_to_ignore, refresh_schedule, refresh_rates, enable_updates, ignore_layers, tile_services, future)
1334 enable_updates=enable_updates,
1335 ignore_layers=ignore_layers,
-> 1336 tile_services=tile_services)
1337
1338 #----------------------------------------------------------------------
~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\mapping\_types.py in _create(self, area, item_properties, folder, min_scale, max_scale, layers_to_ignore, refresh_schedule, refresh_rates, enable_updates, ignore_layers, tile_services, future)
1753 # LOD that is closest to min scale. Do similar for max_scale.
1754
-> 1755 sorted_lods = sorted(layer0_obj.properties.tileInfo.lods, key=lambda x:x['scale'])
1756 keys = [l['scale'] for l in sorted_lods]
1757
UnboundLocalError: local variable 'layer0_obj' referenced before assignment
If I remove the min_scale and max_scale, the tool runs. But the map area does not have a valid scale and the area is not downloadable in Explorer.
"mapAreas": {
"mapAreaTileScale": {
"minScale": null,
"maxScale": null
}
If I go into the AGOL: Manage Areas interface and 'edit' the Level of Detail to where I want it, everything seems to work and the map is downloadable in Explorer.
"mapAreas": {
"mapAreaTileScale": {
"minScale": 160000,
"maxScale": 1250
}
I understand the basic error. The variable is not assigned. The issue is that the error is referencing a script that is not generally modified. If it were my code, it wouldn't be so bad to figure out and rewrite. I believe I am following the API Reference near verbatim, so I am thinking that the issue is potentially with my install, map configs, or somewhere else other than directly in my code.
Is it an issue with my coding or maybe with my notebooks install? Should I try and run a clean Clone and conda? Issue with my map configurations?
What are my options here? Where to begin?
As one idea, I conda upgraded arcgis to 1.8.0.
Still no go.
Paul, I would raise the issue on github, you are more likely to get the attention of the people that deal with the api, than on geonet
Issues · Esri/arcgis-python-api · GitHub
Dan, thank you sir. I will inquire over on GitHub.