ArcGIS API for Python: Change limit of 10 on the number of results returned?

785
1
10-28-2020 07:34 AM
DanielGermroth1
New Contributor

I understand that the GIS.content.search() has a max_items parameter, but what about all of the other tools? Is there a property that can be set in the GIS object or anywhere else?

Take the item.dependent_to() method for example. The documentation does not list any parameters or make any mention that a limit exists in the first place:

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

Returns items, urls, etc that are dependent to this item. This capability (item dependencies) is not yet available on ArcGIS Online. Currently it is available only with an ArcGIS Enterprise.

A python example:

from arcgis.gis import GIS

g = GIS(profile='xxx')
print("Connected to: {}\nConnected as: {}".format( g.url ,g.users.me.username))


id_of_interest = 'bd9902d1c85c4bfab5636af782a89219'
item_of_Interest = g.content.get(id_of_interest)

dep_to = item_of_Interest.dependent_to()
print(len(dep_to['list']))
### Returns 10 ###

Returns 10 items.

My workaround function is relatively slow but proves that there are 44 dependencies:

def Find_WMs_using_layer(layer_item, webmaps_list=[]):
    if not webmaps_list:
        webmaps_list = g.content.search("*", item_type="Web Map", max_items = 300, outside_org=False)
    print('%s webmaps found in portal' % len(webmaps_list))
    
    id_of_interest = layer_item.id

    out_webmaps = []
    print("{:-<50}".format(""))
    lyr = None
    for wm in webmaps_list:
        raw_data = wm.get_data()
        lyrs = raw_data['operationalLayers']
        for lyr in lyrs:
            if 'itemId' in lyr.keys() and lyr['itemId'] == id_of_interest:
                print("\t %s contains layer of interest as %s" % ( wm.title, lyr['title']))
                
                out_webmaps.append(wm)
                
    return out_webmaps


id_of_interest = 'bd9902d1c85c4bfab5636af782a89219'
item_of_Interest = g.content.get(id_of_interest)


webmaps = Find_WMs_using_layer(item_of_Interest, webmaps_list=[])
len(webmaps)

Returns 44 webmaps that contain a layer using the item ID provided.

The same behavior is displayed for the dependent_upon() method.

Does anyone know a way to alter the 10 item max?

Are there any other methods that display this behavior we can compile a list of tools?

Thank you!

0 Kudos
1 Reply
Glasnost
New Contributor

Hi! I ran into the same problem. I needed to reliably get a list of *all* dependencies of an item, not just maximum 10. I was very surprised also, that the Docs does not mention this. The returned structure of Item.dependent_to() does hint or somehow suggest, that it must be called repeatedly to build up the full results. My workaround was to use the Item.dependencies property:

deps = dict(self.item.dependencies.properties)['items']
deps = [d['id'] for d in deps if 'id' in d.keys()]
deps = [webgis.content.get(id) for id in deps]

Btw clicking text formatting buttons in this Forum does nothing with a modern Chrome Browser. Yay!