Retrieve url of a basemap/web map layer used in Arc GIS pro with arcpy
I would like to have the possibility to retrieve automatically (by using python) the url of a basemap/web layer which is in ArcGIS pro . As you can see in the image below, from the 'source' of the basemap layer I can manually retrieve the url of the basemap (web map layer).
- I tried to retrieve the properties of the web layer by using arcpy.Describe but there was no method to evoke in order to retrieve the url of the web layer. I could retrieve though the name of the basemap and its dataType (InternetTiledLayer):
- I looked in the documentation for arcpy.Describe but it seems there are no specific methods that can be applied on web layers (ArcInfo Workstation Item properties—ArcPy Functions | ArcGIS Desktop ).
- I also tried to access the CONNECTIONPROPERTIES of the basemap layer but it appers that the connection properties are not applicable for web layers (Layer—ArcPy | ArcGIS Desktop ).
If I could automatically (using ArcPy) extract the url of the basemap from ArcGIS Pro, then I could use the url to specify the basemap I want to have when publishing a web map automatically (by using ArcPy).
They used to have the information you are looking for under service properties in ArcMap but removed it in Pro. Given that ArcGIS Pro is supposed to be more web GIS integrated, it is ridiculous getting this kind of information is more difficult or impossible.
Have your tried layer.dataSource? We have made improvements to service layers.
p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('Map')[0]
l = m.listLayers('World Topographic Map')[0]
l.dataSource
'https:\\\\www.arcgis.com\\sharing\\rest\\content\\items\\7dc6cea0b1764a1f9af2e679f642f0f5\\resources\\styles\\root.json'
Layer.dataSource will give you the URL of basemaps, or any service layer. There is also a new feature available with ArcGIS Pro version 3.2 that will help with your workflow - the ArcGISProject class now has a listBasemaps function that will return all the basemaps that are available in a project. You can then use the return object from listBasemaps in Map.addBasemap(). Note that addBasemap is available in version 3.1 and earlier.
In regards to Layer.serviceProperties available in ArcMap 10x, all the service properties for any service layer are available by reading the the layer's CIM using ArcGIS Pro. There will be new code samples added to the help soon for this workflow. For more information, see these topics: https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/updatingandfixingdatasources.htm and https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/python-cim-access.htm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.