AnsweredAssumed Answered

How do I query records based on actual location using the Python API?

Question asked by JMak_NC on Aug 18, 2020
Latest reply on Aug 20, 2020 by rvburton


I've been using the Python API to batch-update records for hosted feature service layers on ArcGIS Online.

To do this, I query the layer according to the API Syntax.

One such example would be like this:


search_item = gis.content.get('<ITEM ID AS A STRING>')  # change this for every layer you run this on

item_layers = search_item.layers

item_layers[0].query(where="<ATTRIBUTE> = '<Example Data>' ")


However, I'm dealing with a layer that has hundreds of thousands of points, and now I want to narrow the results by querying all of the points that are in a certain area. There is no other attribute field that universally describes the points in this area besides their location. There are latitude/longitude fields, but those fields happen to be empty in my case.


How do I query points by location in the Python API syntax, using the point's actual location/the hidden 'Shape'/geometry field?

A non-working example of what I want would be something like filtering out all points below a certain latitude, like 34.1°N, (assuming WGS 1984):

item_layers[0].query(where="geometry.y > 34.1")


I could also run Calculate Geometry on the point layer and then query by those fields, but running Calculate Geometry on all of the points would take as long as returning everything with a raw .query()--that is, not querying at all. I'm trying to avoid operating on all of the points, if possible.