The unexpected deprecation of the WebMap class has broken a couple of my scripts. I have tried to follow the guidelines here (https://developers.arcgis.com/python/latest/guide/overview24/) for refactoring, but I cannot get it work. I am just trying to add a layer to a webmap.
wm_item = gis.content.get([webmap ID])
m = Map(wm_item)
fs_item = gis.content.get([feature service id])
m.content.add(fs_item)
When I do this, I get the following error:
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py", line 18855, in _hydrate
self._refresh()
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py", line 18829, in _refresh
raise e
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py", line 18818, in _refresh
dictdata = self._con.post(
^^^^^^^^^^^^^^^
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1504, in post
return self._handle_response(
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 979, in _handle_response
self._handle_json_error(data["error"], errorcode)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1002, in _handle_json_error
raise Exception(errormessage)
Exception: Invalid URL
Invalid URL
(Error Code: 400)
What am I doing wrong here?
Hi @TrishPeller
Still getting to grips with the update myself, but here's what I know...
1. If the Feature Service contains a single Feature Layer, the single layer is added to the WebMap.
2. If the Feature Service contains multiple Feature Layers, all layers are added to the WebMap as a Group Layer.
3. If the Feature Service contains a Feature Layer(s) and a Table, the add will fail as a Table cannot be added to a Group Layer.
I have tested the above scenarios with the script below
from arcgis.gis import GIS
from arcgis.map import Map
## access agol
agol = GIS("home")
## get the WebMap item as an Item object
wm_item = agol.content.get("WM_ITEM_ID")
## create the Map object
m = Map(wm_item)
## get the feature service to add as an Item object
fs_item = agol.content.get("FS_ITEM_ID")
## add the Feature Service to the Map
m.content.add(fs_item)
## update the Map object
m.update()
4. You can grab an individual Feature Layer from a Feature Service and add to the WebMap.
from arcgis.gis import GIS
from arcgis.map import Map
## access agol
agol = GIS("home")
## get the WebMap item as an Item object
wm_item = agol.content.get("WM_ITEM_ID")
## create the Map object
m = Map(wm_item)
## get the feature service to add as an Item object
fs_item = agol.content.get("FS_ITEM_ID")
## get a single Feature Layer from teh Feature Service
fl = fs_item.layers[0]
## add the Feature Layer to the Map
m.content.add(fl)
## update the Map object
m.update()
I don't think you are doing anything wrong. I see you have another post up where you are receiving the same error message when you try to access the content property. It seems that any time you call a Map property or method you are getting your Invalid URL error. How did you update to 2.4.0, was it with an ArcGIS Pro update to 3.4 or did you update the API separately?
It was with an ArcGIS Pro update to 3.4
I only get that error with the content property. This works just fine:
wm_item = gis.content.get('0bfbcdfc20874915bc2837f9364d791f')
wm = Map(item=wm_item)
extent = wm.extent