Select to view content in your preferred language

API Fails to get Sublayers to a Feature Layer (the second time in a loop)

1378
4
02-18-2022 01:17 PM
DirkVandervoort
Frequent Contributor

Hello and greetings:

Executing the code below will explain everything (I hope).

When the API consumes a Feature Layer with multiple sublayers, it fails to execute a query on the second thru nth sublayer. The API complains that there it cannot perform the operation because I'm using invalid query parameters.

DirkVandervoort_0-1645292775751.png

 

More importantly, I just want to perform a query on a sublayer and to be able to specify the which sublayer to query. Any thoughts?

 

 

 

 

def main():
    target_item_string = "_USE_AN_ITEM_ID_TO_GET_A_FEATURE_LAYER_"
    gis = GIS("https://YOUR_DOMAIN.maps.arcgis.com", "superuser", "T0p5Ecr3T")
    result = gis.content.get(target_item_string)
    for layer in result.layers:
        query_result = layer.query()
        # do something with the query_result

 

 

 

 

TIA

Tags (1)
0 Kudos
4 Replies
jcarlson
MVP Esteemed Contributor

Why not use gis.content.get('itemidforyourfeaturelayer')? You'll be assured that the response is the single Item you want, where searching is not always 100% reliable.

Have you tried supplying other parameters to the query?

Edit to add: I tested this and don't see the same behavior. What version of the API are you using? And is this AGOL, or Portal? And if Portal, what version?

- Josh Carlson
Kendall County GIS
0 Kudos
DirkVandervoort
Frequent Contributor

Thanks Josh, cleaner code (updated above), but it didn't solve the issue.

  • Yes, I've tried providing parameters, including 1=1
  • This is on AGOL. I haven't tried it on a Portal instance

Thanks!

0 Kudos
jcarlson
MVP Esteemed Contributor
lyr = gis.content.get('87acff1ba86c40098b59472292de3d11')

[l.query(return_all_records=False, result_record_count=5, return_ids_only=True) for l in lyr.layers]

Returns

[{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 5]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 5]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 5]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 5]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 5]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 5]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 5]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 5]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 5]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 5]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 4, 5, 6, 7]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 5]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 5]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 5]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 5]},
{'objectIdFieldName': 'OBJECTID', 'objectIds': [1, 2, 3, 4, 6]}]

Run on AGOL, too. Perhaps it's specific to the layer(s) you're trying to query? Any chance it's public for someone else to test?

- Josh Carlson
Kendall County GIS
0 Kudos
DirkVandervoort
Frequent Contributor

change 

 

l.query(return_all_records=False, result_record_count=5, return_ids_only=True)

 

to

 

l.query(return_all_records=True, return_ids_only=False)

 

and it does not work

0 Kudos