Calculate max value on feature layer

979
4
Jump to solution
05-15-2021 04:12 AM
Jose_FranciscoSánchez_Díaz1
New Contributor III

Hello!

I'm tryng to get the max value on a feature layer using argis python api.

 

I need to check the max record on a numeric field.
I was able to get it loading the feature layer to a spatial dataframe, but it is slow and will become slower once the feature layer grow (I spect to reach near a million records).

I think it is possible with the fearurelayer metho, but I don know how to do it.

My actual code:

sdf = pd.DataFrame.spatial.from_layer(feature_layer_hosted_on_arcgis)
id = sdf["id"]
max_value = id.max()

0 Kudos
3 Solutions

Accepted Solutions
DavidPike
MVP Frequent Contributor

If you go to the FeatureLayer heading arcgis.features module — arcgis 1.8.5 documentation there is a query() method with an out_statistics parameter (min,max etc.).  This may be faster.

View solution in original post

MingHome
New Contributor III

Have you triedfeaturelayer.query with "out_statistics"?

 

Ming

View solution in original post

Jose_FranciscoSánchez_Díaz1
New Contributor III

Hello!
I was able to do it with out_statistics:

max_value = feature_layer.query(out_fields='id', out_statistics=[{"statisticType":"max", "onStatisticField": "id", "outStatisticFieldName": "maxid"}])
for record in max_value:
print(record.get_value("maxid"))

Wasn't sure how to do it beacause I'm still learning how to deal with the api, but It's done and it is faster than creating a spatialdataframe.
Thanks for your help!

View solution in original post

0 Kudos
4 Replies
DavidPike
MVP Frequent Contributor

If you go to the FeatureLayer heading arcgis.features module — arcgis 1.8.5 documentation there is a query() method with an out_statistics parameter (min,max etc.).  This may be faster.

View solution in original post

MinbinJiang
Esri Contributor

Excellent, thanks!

0 Kudos
MingHome
New Contributor III

Have you triedfeaturelayer.query with "out_statistics"?

 

Ming

View solution in original post

Jose_FranciscoSánchez_Díaz1
New Contributor III

Hello!
I was able to do it with out_statistics:

max_value = feature_layer.query(out_fields='id', out_statistics=[{"statisticType":"max", "onStatisticField": "id", "outStatisticFieldName": "maxid"}])
for record in max_value:
print(record.get_value("maxid"))

Wasn't sure how to do it beacause I'm still learning how to deal with the api, but It's done and it is faster than creating a spatialdataframe.
Thanks for your help!

View solution in original post

0 Kudos