Search for Web Maps which contain a specific basemap

298
3
09-03-2021 05:11 AM
Labels (1)
Daniel_Hardwick
New Contributor III

Hello, 

I am trying to do something quite trivial, but I am relatively new to Notebooks so wondered if someone could help. 

Essentially all I want to do is find web maps which contain a specific basemap. I have used Notebook previously to do things like find web maps which contain a keyword, such as Planning, using:

webmap_search = gis.content.search("Planning", item_type="Web Map")
webmap_search

And I have searched through particular groups to find content within, but I don't know how to search for web maps which contain a certain basemap, for example OS_Open_Carto. Is this possible? 

Thanks

 

0 Kudos
3 Replies
xlt208
by Esri Contributor
Esri Contributor

Hello Daniel!

We can loop through the items in the search result and use WebMap.basemap to check their basemaps. 

In the code snippet below, if the basemap of a web map item matches the basemap we are looking for ("Topographic"), we will display the item in the cell output.  

 

from arcgis.gis import GIS

from arcgis.mapping import WebMap

gis = GIS("home")

 

items_from_search = gis.content.search(query="Redlands", item_type="Web Map", max_items=15, outside_org=True) 

 

for item in items_from_search:

    try: 

        if WebMap(item).basemap.title=="Topographic":

            display(item)

    except Exception as e:

        print("Unable to check basemap for '{}': {}".format(item.title, e))

 

I hope this is helpful! Please let me know if you have any questions about this. 

 

Thanks,

Lingtao

Daniel_Hardwick
New Contributor III

Thanks @xlt208 , that's fantastic.

I have the code now setup as follows:

 

items_from_search = gis.content.search(query="", item_type="Web Map",outside_org=False , max_items=1000)

for item in items_from_search:

try:

if WebMap(item).basemap.title=="GB Light Grey":

display(item)

except Exception as e:

print("Unable to check basemap for '{}': {}".format(item.title, e))

 

And it works. Is there a way to amend this further to only show webmaps which are shared publicly? Also by Map owner? If there is a some sort of guide with the list of available methods then please feel free to point me towards it :) As I have tried a few with trial and error but can't quite get what I want in terms of only publicly available maps create by a certain user. 

Thanks

Dan

 

0 Kudos
xlt208
by Esri Contributor
Esri Contributor

@Daniel_Hardwick Yes! Here is how we can only show web maps that are shared publicly and owned by a specific user. Please let me know if this works for you!

items_from_search = gis.content.search(query="owner:<AGOL username>", item_type="Web Map", outside_org=False, max_items=1000) 

 

for item in items_from_search:

    try: 

        if (WebMap(item).basemap.title=="GB Light Grey")&(item.access=='public'):

            display(item)

    except Exception as e:

        print("Unable to check basemap for '{}': {}".format(item.title, e))

 

Here are some links related to this topic:

1. Search reference–ArcGIS REST API https://developers.arcgis.com/rest/users-groups-and-items/search-reference.htm

2. gis.content.search https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager.sea...

3. How To: Find specific items using queries in the arcgis.gis module with the ArcGIS Python API https://support.esri.com/en/technical-article/000024383

4. Accessing and creating content–ArcGIS API for Python https://developers.arcgis.com/python/guide/accessing-and-creating-content/

 

0 Kudos