How to apply a server side raster function on an image service layer


Summary
Image service clients can define raster functions that are processed on the server side. A raster function defines on-the-fly processing, such as hillshade, Normalized Difference Vegetation Index (NDVI), stretch, and so on. This topic shows how to programmatically apply server side raster functions on an image service layer.
Note: ArcGIS for Desktop is a powerful client that supports the client side raster function, which can be easily achieved through the Image Analysis Window or the functions tab on an image service layer.

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:
  1. Open the image service layer.
  2. Define a raster function.
  3. Define a rendering rule and apply it on the image service layer.
  4. Save the image service layer.

    See the following code example:
[C#]
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 layer




To 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