Applying a server side raster function on an image service layer
Do the following steps to apply a server side function on an image service layer:
- Open the image service layer.
- Define a raster function.
- Define a rendering rule and apply it on the image service layer.
- Save the image service layer.
See the following code example:
public static void ApplyServerRasterFunctionOnISLayer(string layerPath)
{
//Open the layer.
ILayerFile islayerFile=new LayerFileClass();
islayerFile.Open(layerPath);
IImageServerLayer3 isLayer=islayerFile.Layer as IImageServerLayer3;
//Define a stretch function (assuming service is 3 band).
IRasterFunction stretchFunction=new StretchFunctionClass();
IStretchFunctionArguments2 args=new StretchFunctionArgumentsClass();
args.ComputeGamma=false;
args.StretchType=esriRasterStretchType.esriRasterStretchPercentMinimumMaximum;
args.MinPercent=2.5;
args.MaxPercent=2.5;
args.DRA=true;
//Define a rendering rule and apply to the layer.
IRenderingRule renderRule=new RenderingRuleClass();
renderRule.Function=stretchFunction;
renderRule.Arguments=(IRasterFunctionArguments)args;
renderRule.VariableName="Raster";
isLayer.RenderingRule=renderRule;
//Save the layer.
islayerFile.Save();
}
[VB.NET] Public Shared Sub ApplyServerRasterFunctionOnISLayer(layerPath As String)
'Open the layer.
Dim islayerFile As ILayerFile=New LayerFileClass()
islayerFile.Open(layerPath)
Dim isLayer As IImageServerLayer3=TryCast(islayerFile.Layer, IImageServerLayer3)
'Define a stretch function (assuming service is 3 band).
Dim stretchFunction As IRasterFunction=New StretchFunctionClass()
Dim args As IStretchFunctionArguments2=New StretchFunctionArgumentsClass()
args.ComputeGamma=False
args.StretchType=esriRasterStretchType.esriRasterStretchPercentMinimumMaximum
args.MinPercent=2.5
args.MaxPercent=2.5
args.DRA=True
'Define a rendering rule and apply to the layer.
Dim renderRule As IRenderingRule=New RenderingRuleClass()
renderRule.Function=stretchFunction
renderRule.Arguments=DirectCast(args, IRasterFunctionArguments)
renderRule.VariableName="Raster"
isLayer.RenderingRule=renderRule
'Save the layer.
islayerFile.Save()
End Sub
See Also:
How to change mosaic properties on an image service layerTo use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing | Deployment licensing |
---|---|
ArcGIS for Desktop Advanced | ArcGIS for Desktop Advanced |
ArcGIS for Desktop Standard | ArcGIS for Desktop Standard |
ArcGIS for Desktop Basic | ArcGIS for Desktop Basic |
Engine Developer Kit | Engine |