Select to view content in your preferred language

How to get returnCentroid to work when querying Feature Service layer

3977
11
Jump to solution
04-19-2021 01:07 PM
KarenRobine1
New Contributor III

According to the documentation here: 

https://developers.arcgis.com/rest/services-reference/query-feature-service-layer-.htm 

There's a parameter, returnCentroid. According to the documentation Notes:

Note:

The layer metadata returns supportsReturningGeometryCentroid in the advancedQueryCapabilities metadata object. The absence of the supportsReturningGeometryCentroid property means that the server does not support the returnCentroid parameter. Line and point data will return supportReturningGeometryCentroid as false.

Question: I'm trying to figure out how to make the server support the returnCentroid parameter, because in our case, the supportsReturningGeometryCentroid property does not exist. FYI: We're on 10.8 so I know this is supposed to be supported in our version.

0 Kudos
11 Replies
jcarlson
MVP Esteemed Contributor

There is still a way to get the centroids, if you don't mind doing some Python.

Once you query the layer out to a spatially enabled dataframe, you can call the centroid property on a GeoSeries Accessor of the dataframe's SHAPE column.

sdf = lines_service.layers[0].query(as_df=True)

gsa = arcgis.features.GeoSeriesAccessor(sdf['SHAPE'])

gsa.centroid

 

Which returns:

0     (986305.7876933983, 1833079.8610554787)
1     (960080.7627723165, 1827236.9255665324)
2     (943782.9728523004, 1822116.2102860417)
3      (920423.2422279464, 1823134.951778373)
4     (991925.4577918178, 1758800.7325564628)
5     (916942.1624821002, 1776554.3496633286)
6     (927332.5836300697, 1748540.1104202385)
7     (952494.8496332371, 1765384.4943458117)
...

And just to confirm, the layer I'm running it on has the return centroid property set to False. The difference here is that I'm asking the dataframe for the centroid, not the REST endpoint.

I don't know if that's applicable to what you're trying to do with the data, but wanted to make sure you knew about it.

- Josh Carlson
Kendall County GIS
0 Kudos
KarenRobine1
New Contributor III

Thanks Josh. I'm actually doing this using the JavaScript API. I could possibly do a request using the geometry service to get the center for each geometry passed in, but trying to keep this thing fast as I may have to do it for tens of thousands of lines at a time on a public-facing app, so speed is key. Thanks again for your help.  

Karen

0 Kudos