Select to view content in your preferred language

How to find a id for a web map object in arcgis Python API?

1117
2
09-26-2022 04:54 AM
LeePark
New Contributor

Hi, I am struggling with finding the id of a web map object. 

Suppose I search web maps using contentManager.search('', item_type = 'Web Map'), how can I find ids of each web maps in the list? 

0 Kudos
2 Replies
DominicRobergeIADOT
Frequent Contributor

hello

would this works for you:

search_result = gis.content.search("*", item_type = "Web Map", max_items=2000) 

print(len(search_result))
t = len(search_result)

while i <t:
    print(i)
    print(search_result[0])
    print("        "+str(search_result[0]['title']) +"  "+ str(search_result[0].id) + " -- "+ str(len(search_result))) 
    search_result.pop(0)
    i+=1

 

 

0 Kudos
jcarlson
MVP Esteemed Contributor

You could use advanced_search to return a dict, then convert that to a DataFrame:

pandas.DataFrame(gis.content.advanced_search('type:map', max_items=-1, as_dict=True)['results'])

The resulting frame has id as one of its columns:

jcarlson_0-1664203668159.png

If you just wanted a list, though, you could use list comprehension together with the search method:

[f'{i.id} | {i.title}' for i in gis.content.search('', item_type='Web Map', max_items=-1)]

 

jcarlson_1-1664204063069.png

 

- Josh Carlson
Kendall County GIS
0 Kudos