1

I'm serializing portal data so two instances of arcgis portal can be compared and the serialized data can be searched for specific keywords. More specifically, I need to retrieve all layers (and their properties etc) included in each "Web Mapping Application" and "Web Map" running on each server.

So far with help from this site I've had luck doing this for Map Services and Feature Services, but I can't seem to find any documentation for how to retrieve layers belonging to a "Web Mapping Application" or a "Web Map"

I've tried using dependent_upon(), layers[] and a few other things but I haven't had any luck so far.

Below is a simplified example of how I'm doing it now (minus the looping over users and items)

from arcgis import GIS

source = GIS(url, username, password)
server_string=""

search_result = source.content.search(
    query="title:Data Feed App",
    item_type="Web Mapping Application")
item=search_result[0]
itemstring = str(item.__dict__)

layers=[]
try:
    layers=getattr(item, "layers",[])
except Exception as layerError:
    print('"layer_error":"unable to fetch layers"')
if(layers != []):
    if isinstance(item.layers,list):
        itemstring+="["
        for layer in layers:
            try:
                itemstring+=str(layer.__dict__)
                if(hasattr(layer, 'properties')):
                    itemstring+="\n"+str(layer.properties.__dict__)
            except Exception as ex:
                print('"layer_error":"'+str(ex)+'"')
        itemstring+="]"
  • 1
    In the case of maps and apps the information you are looking for is stored on the item data. For each item You will need to download the item data (json) and look for layer references there. – Ben S Nadler Apr 7 '18 at 5:44
  • @BenSNadler Thanks! So how do I retrieve the JSON for an 'arcgis.gis.Item'? – gnarbarian Apr 7 '18 at 5:54
  • 1
    text = source_item.get_data(False) developers.arcgis.com/python/sample-notebooks/… – Ben S Nadler Apr 9 '18 at 14:04
1

Building on the code of gnarbarian and Ben S' suggestion

for lyr in item.get_data()['operationalLayers']:
    print(lyr['id'])

https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.Item.get_data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.