Simple way to export a Layer List for a Web Map to Text

3136
15
05-25-2017 09:47 AM
BrianO_keefe
Occasional Contributor III

Is there a simple way to export the layer list from a web map (built with WAB) to a text file?

15 Replies
Lake_Worth_BeachAdmin
Occasional Contributor III

open the feature service in arcmap (in catalog you will see an option for feature services, then use arcpy to list the layers

0 Kudos
LindsyHales_Bentley
New Contributor III

Is there a way to do this for all services at once? Thanks!

0 Kudos
JoshuaSharp-Heward
Occasional Contributor III

Do you have access to ArcGIS Pro or ArcGIS Notebook (in AGOL or enterprise)? If so this can be done using the ArcGIS API for Python pretty easily!

LindsyHales_Bentley
New Contributor III

Yes, I have both of those.  Any help is appreciated!! Thank you!

0 Kudos
JoshuaSharp-Heward
Occasional Contributor III

Easy then!

from arcgis.gis import GIS
from arcgis.mapping import WebMap
gis = GIS('pro')# if running this from Notebook for ArcGIS in AGOL/Enterprise, replace this line with gis = GIS('home')
wmItemId = "" #put the id of the webmap in here
wmItem = gis.content.get(wmItemId)
wm = WebMap(wmItem)
for lyr in wm.layers:
    print(lyr.title)

I wrote that to be run from the Python window in Pro, but see my note in line 3 about using it in ArcGIS Notebook. Just put the ID of the web map item into line 4 and it should print out all the layers for the given webmap.

LindsyHales_Bentley
New Contributor III

Thank you so much!!

JoshuaSharp-Heward
Occasional Contributor III

Glad to help out! 

0 Kudos
Kayden75
New Contributor III

Hi,

I took your script and tried adding in a lyr.url to get the url of the layers and it worked but sometimes it comes up with an exception saying "layer" instance has no attribute 'url' and I was wondering if you know what I can do to put an exception in there. Thanks!

0 Kudos
JoshuaSharp-Heward
Occasional Contributor III

Hi Kayden, sorry for the delay, didn't see your message until now. I've had this issue in the past with vector tile layers (possibly from the basemap?) as they have an attribute called "styleUrl" instead of "url", which you could handle with some code like this:

if layer['layerType'] == "VectorTileLayer":
    print(layer.styleUrl)
else:
    print(layer.url)

 

0 Kudos