I am using the Python API and attempting to query an AGOL hosted polygon feature layer to return back the centroids of the polygons. I set return_centroid=True in the query, but I do not see the centroid information returned in the data when I load to a dataframe or view the returned json. Below is my query:
q = site_data_layer.query(where="1=1",return_centroid=True)
When I run this same query on the layer via the REST API, I do get centroids back.
Is this a bug or am I not structuring the query the proper way or not handling the returned data properly?
Thank you in advance,
It is a bug in the ArcGIS API for Python. I used Fiddler to watch the traffic between my client and server, and the correct URL is passed to the server, the correct results are returned, but the results are processed incompletely. From what I can gather, the error is in the arcgis.features.Feature class:
>>> import arcgis >>> import inspect >>> print(inspect.getsource(arcgis.features.Feature.from_dict)) @classmethod def from_dict(cls, feature): """returns a feature from a dict""" geom = feature['geometry'] if 'geometry' in feature else None attribs = feature['attributes'] if 'attributes' in feature else None return cls(geom, attribs) >>>
The from_dict class method is missing an option for "centroid" that is returned alongside "geometry" and "attributes".
Is the polygon layer stored up in AGOL or does the polygon layer reside on your org's servers and passed as a feature layer to AGOL?
Polygon layer is stored/hosted in AGOL.
Interesting and thank you for digging in so thoroughly on this. I'll use another method to get my centroids for now.
Appreciate the feedback and glad to know I am not going crazy.