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()
Solved! Go to Solution.
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.
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!
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.
Excellent, thanks!
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!
Thank you for posting the solution that worked for you - that's a big help!