How to list which feature layers are being used by which web maps and apps?

3639
5
10-30-2020 11:53 AM
ConorMacNaughton
New Contributor II

Anybody got any tips or hints on how this can be done?

I've been able export lists of items by user and user folder using the following:
pd.DataFrame(list_items).transpose().to_excel(str(user.username)+'.xlsx')

But it would be more useful to see which web maps and web apps throughout my organization are using which feature layers.

5 Replies
DavidPike
MVP Frequent Contributor

I'm still learning this one myself, quite painfully in fact...

Accessing and creating content | ArcGIS for Developers 

Working with web maps and web scenes | ArcGIS for Developers 

here's what I could glean from the documentation (such as it is..)

from arcgis.gis import GIS
from arcgis.mapping import WebMap

gis = GIS(url='https://pythonapi.playground.esri.com/portal', 
username='arcgis_python', 
password='amazing_arcgis_123')

search_my_contents = gis.content.search(query="owner:[owner name]", 
item_type="Web Map", max_items = 1000)

#create web map objects from search results and print the web map title and layer name
for webmap_item in search_my_contents:
    webmap_obj = WebMap(webmap_item)
    for layer in webmap_obj:
        print(webmap_item.title, layer.title)
ConorMacNaughton
New Contributor II

Thanks! This worked for me after the following change to line 14:
 

for layer in webmap_obj.layers:
anonymous55
Occasional Contributor II

Hello I changed line 14 but I am getting this error

  Input In [1]
    print(webmap_item.title, layer.title)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
                                         ^
SyntaxError: invalid non-printable character U+200D

I am running this code in AGOL notebook.
Basically, I want my code scan web maps in my portal and list all layers and there map services url

0 Kudos
ZakBaron
New Contributor II

I got the same error,

SyntaxError: invalid non-printable character U+200D

and found this:

https://www.decodingweb.dev/solved-syntaxerror-invalid-non-printable-character-in-python

 

I removed the non-printable characters using Notepad++ with this method from StackOverflow (https://stackoverflow.com/questions/20889996/how-do-i-remove-all-non-ascii-characters-with-regex-and...)

'In Notepad++, if you go to menu Search  Find characters in range  Non-ASCII Characters (128-255) you can then step through the document to each non-ASCII character.

Be sure to tick off "Wrap around" if you want to loop in the document for all non-ASCII characters.'

After that, it worked like a charm!

 

0 Kudos
JosephRoberts2
New Contributor II

Hi David, 
Have you figured out how to access the properties of a sublayer of a service?  For instance, I'm iterating through a map that has the entire service. When my script hits this layer, it does not iterate through the sublayer of the services. It simply prints the name of the main service.

JosephRoberts2_0-1651692536548.png

 



Any insight would be greatly appreciated. 

0 Kudos