How can I sort a list of selected features based on a field value (i.e. the field name is "cityname")?
My code is this:
...
FeatureQueryResult queryResult = await featureTable.QueryFeaturesAsync(queryParams, QueryFeatureFields.LoadAll);
var features = queryResult.ToList();
// ... here I need to sort the features list
Many thanks
Massimo
Solved! Go to Solution.
You can use LINQ to perform any form of sorting:
var sortedResults = queryResult.OrderBy(f=>f.Attributes["FieldName"])
However you might be better off sorting up front in the query:
var parameters = new Data.QueryParameters();
parameters.OrderByFields.Add(new Data.OrderBy("FieldName", Data.SortOrder.Ascending);
Hi Massimo,
You may user features.Sort() method by defining the Comparer, for your case it would be "cityname".
You may take a look at this site: List(T).Sort Method (System.Collections.Generic)
Hope that helps,
Nagma
Thanks for the help. It is correct, but the solution proposed by Morten Nielsen is simpler and more suitable for my needs.
Best regards
Massimo
You can use LINQ to perform any form of sorting:
var sortedResults = queryResult.OrderBy(f=>f.Attributes["FieldName"])
However you might be better off sorting up front in the query:
var parameters = new Data.QueryParameters();
parameters.OrderByFields.Add(new Data.OrderBy("FieldName", Data.SortOrder.Ascending);
The LINQ solution
var sortedResults = queryResult.OrderBy(f=>f.Attributes["FieldName"])
is perfetct for me.
Many thanks
Massimo