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.
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
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?
Thanks Josh, cleaner code (updated above), but it didn't solve the issue.
Thanks!
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?
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