How to get field unique values of a ArcGIS Server dynamic map service layer field.

2580
3
Jump to solution
02-24-2012 12:13 PM
SuiHuang
Occasional Contributor II
Hi Everybody:

    I am making a Silverlight application using a ArcGIS Server Dynamic map service. One of the feature I want to implement is to let the application get all the unique values of a field provided by a layer of the map service.

Inputs from user:
1. the field name
2. the layer id
Output: the list of unique values of the specified field

This feature is for some layer with millions of records but only few possible values.

The performance will be poor if I use QueryTask class to get all the records and aggregate the result in the client side C# code (big data transimission through network and non-trivial computation in client side). Is there anyway to provide this feature with better performance? such as setup the map service in a certain way to allow the aggregation happen on server side?

Thank you.
0 Kudos
1 Solution

Accepted Solutions
wangzhifang
Occasional Contributor
If you have relative few records, you may want to retrieve them once and using LINQ to get the unique value on one field.
If you have millions of records and want to get its unique value, it's better to do this job on server side rather than get all of them to the client side.
On server side, you could using a GP services or a SOE operation to easily achieve your goal.

View solution in original post

0 Kudos
3 Replies
SanajyJadhav
Occasional Contributor II
To fix this issue, we used WCF code.In that code, it was simple DISTINCT query that returned unique values of the concerned field to the Silverlight client.These values can then be bound to the Silverlight control.

Hope this helps.
0 Kudos
wangzhifang
Occasional Contributor
If you have relative few records, you may want to retrieve them once and using LINQ to get the unique value on one field.
If you have millions of records and want to get its unique value, it's better to do this job on server side rather than get all of them to the client side.
On server side, you could using a GP services or a SOE operation to easily achieve your goal.
0 Kudos
MarkCederholm
Occasional Contributor III
As of 3.0, you can use GenerateRendererTask to get a list of unique field values.

List<string> FieldList = new List<string>() { sFieldName };
ColorRamp colorRamp = new ColorRamp();
colorRamp.Algorithm = Algorithm.CIELabAlgorithm;
colorRamp.From = Colors.Black;
colorRamp.To = Colors.White;
ObservableCollection<ColorRamp> ColorRamps = new ObservableCollection<ColorRamp>() { colorRamp };
UniqueValueDefinition uvDef = new UniqueValueDefinition();
uvDef.Fields = FieldList;
uvDef.ColorRamps = ColorRamps;
GenerateRendererParameters grParam = new GenerateRendererParameters();
grParam.ClassificationDefinition = uvDef;
if (sWhereClause != null)
 grParam.Where = sWhereClause;
GenerateRendererTask grt = new GenerateRendererTask(sUrl);
grt.ExecuteCompleted += new EventHandler<GenerateRendererResultEventArgs>(grt_ExecuteCompleted);
grt.Failed += new EventHandler<TaskFailedEventArgs>(grt_Failed);
grt.ExecuteAsync(grParam, userToken);

[snip]
GenerateRendererResult grResult = e.GenerateRendererResult;
UniqueValueRenderer uvRenderer = (UniqueValueRenderer)grResult.Renderer;
List<string> UniqueValues = new List<string>();
foreach (UniqueValueInfo uvInfo in uvRenderer.Infos)
{
 if (uvInfo.Value == null)
  continue;
 UniqueValues.Add(uvInfo.Value.ToString());
}
0 Kudos