Select to view content in your preferred language

Extract list of content in a specific Portal webmap using ArcGIS API for Python

1473
3
06-17-2023 11:46 AM
Janakiraman
New Contributor

I would like to extract the lists of content (Feature & Map Image Service) including the type of base map. Also, wanted to know if all the layers are loading correctly using ArcGIS API for Python.

import arcgis
portal = arcgis.gis.GIS("Portal URL", "Portal Username", "Portal Password")
maps = gis.content.search("WebMap item id")
for webmap in maps
    for lyr in webmap.get_data()['operationalLayers']
        print(lyr['title'])

I've extracted the layers but I would like to know the base map layers in the web map and the layer loading status

Tags (3)
0 Kudos
3 Replies
JoshuaSharp-Heward
Frequent Contributor

Hi,

A few comments!

First of all, you don't need to use content.search when just accessing a single web map, do:

webmap = gis.content.get(itemid)

Although if you want to do it for all your maps you would do it like that:

webmaps = gis.content.search(query="", item_type="Web Map", max_items=10000)

And you don't need to use get_data to pull out the layers, as there are .layers and .basemap properties that store that info without having to pull it from the dictionary returned by get_data. I'd do something like this:

for web_map in webmaps:
    print(web_map.title)
    for layer in web_map.layers:
        print(layer.name)
    print(web_map.basemap_title)

If you want to extract all the layers in the basemap I think web_map.basemap returns these as a list that you can iterate over too.

As for checking the loading status of the layer, do you mean whether the layer is broken or not?

Janakiraman
New Contributor

Hi @JoshuaSharp-Heward

Thank you so much for your valuable suggestions. I apologize for the delay in my response.

I am now able to successfully print the Basemap layer using the following code

print (WebMap(web_map).basemap.title)

In the upcoming steps, it is crucial for me to determine the loading statuses of all the layers within a specific Web Map. This will allow me to investigate each layer individually and identify any potential issues.

I am inquiring about the loading status of the base map's layer because there have been recent deprecations of some base maps in the portal. By understanding the status of each web map, I will be able to provide a report on which maps require corrections.

0 Kudos
JoshuaSharp-Heward
Frequent Contributor

Hi,

No worries, glad I could help so far! Presuming you are mainly dealing with ESRI Rest services, you should be able to query each layer in a "try" and "except" clause as a proxy for finding whether the web service for the layer is accessible or not. Fair warning: I haven't tried or tested this, but I think it would work in theory.

 

for layer in layers:
    try:
        layer.query(return_count_only=True)
        print("query successful")
    except:
        print("query unsuccessful")

 

Probably printing the layer name and web map so you can find which ones aren't working. Note I'm using return_count_only=True as I think it will be faster as it doesn't have to return all the feature info. It'd be great to use "where="OBJECTID = 1" but It's not always a given that a feature service will have a feature with OID =1 if it's updated regularly.

0 Kudos