Map service GenerateDataClasses method

Returns the class breaks or unique values for the specified layer or table.

GenerateDataClasses(string MapName, MapTableDescription MapTableDescription, DataClassificationDef DataClassificationDef)

Parameter

Description

MapName

The name of the data frame in the map service.

MapTableDescription

Used to define a layer or a standalone table.

DataClassificationDef

Used to define what type of renderer will be returned and whether symbols will be omitted.

Return Value

The type of renderer that is returned by this function depends on the DataClassificationDef parameter. For example, if an object of type ClassBreaksDef is passed in, the result will be a ClassBreaksRenderer. If UniqueValuesDef is passed in you will get back a UniqueValueRenderer object.

Remarks

GenerateDataClasses is a helper function that allows clients to generate classes based on a classification method or get distinct values from single or multiple fields. This eliminates the need to download an entire dataset on the client side to compute class breaks or find out distinct values from a field. Since the result is a FeatureRenderer, the result is primarily used to change the renderer of a layer without needing to access fine grained ArcObjects or restarting a map service by simply making coarse grained MapServer function calls. For more information, see ExportMapImage.

When this function is called with a standalone table as an input parameter, it does not return a symbol for each class in the returned FeatureRenderer, unless DataClassificationDef::BaseSymbol is specified.

You can control the symbols returned in the result by specifying BaseSymbol and/or ColorRamp. If these are not specified, the function returns symbols with default values (in case the input is a layer). The default ColorRamp is "Green to Blue". The color of the returned symbol is always RgbColor.

This function honors the definition expression set on the queried layer or table. To maximize map service performance, you should always run this on a base layer or table instead of joined layer or table.

NoteNote:

In order to compute breaks for a class break renderer, MapServer needs to read all records from a layer/table. As a result, processing time may take longer depending on the number of records in the layer/table. You can control the number of records processed by using the MaxSampleSize property in the map service configuration.

Examples

C#

//Sample code to generate 5 different classes based on LANDVAL field using EqualInterval classification method

HsvColor pColorStart = new HsvColor();
pColorStart.Hue = 60;
pColorStart.Saturation = 50;
pColorStart.Value = 100;

HsvColor pColorMiddle = new HsvColor();
pColorMiddle.Hue = 37;
pColorMiddle.Saturation = 81;
pColorMiddle.Value = 95;

HsvColor pColorEnd = new HsvColor();
pColorEnd.Hue = 0;
pColorEnd.Saturation = 100;
pColorEnd.Value = 42;

AlgorithmicColorRamp pAlgorithmicColorRamp1 = new AlgorithmicColorRamp();
pAlgorithmicColorRamp1.FromColor = pColorStart;
pAlgorithmicColorRamp1.ToColor = pColorMiddle;

AlgorithmicColorRamp pAlgorithmicColorRamp2 = new AlgorithmicColorRamp();
pAlgorithmicColorRamp2.FromColor = pColorMiddle;
pAlgorithmicColorRamp2.ToColor = pColorEnd;

MultiPartColorRamp pMultiPartColorRamp = new MultiPartColorRamp()
{
	ColorRamps = new ColorRamp[2] 
		{   
			pAlgorithmicColorRamp1, 
			pAlgorithmicColorRamp2
		},
	NumColorRamps = 2,
	NumColorRampsSpecified = true
};

RgbColor pColor = new RgbColor() 
{ 
	Red = 255 
};
SimpleFillSymbol pBaseFillSymbol = new SimpleFillSymbol()
{
	Color = pColor,
	Style = esriSimpleFillStyle.esriSFSSolid,
	Outline = null
};

ClassBreaksDef pCBDef = new ClassBreaksDef()
{
	ClassificationField = "LANDVAL",
	ClassificationMethod = esriClassifyMethod.esriClassifyEqualInterval,
	BreakCount = 5,
	BreakCountSpecified = true,
	ColorRamp = pMultiPartColorRamp,
	BaseSymbol = pBaseFillSymbol
};

FeatureRenderer pFeatureRenderer = pMapServer.GenerateDataClasses(pMapServer.GetDefaultMapName(), pLayerDescription, pCBDef);

2/28/2020