This document is archived and information here might be outdated.  Recommended version.


How to apply a raster function to an image service (ArcObjects .NET 10.5 SDK)

How to apply a raster function to an image service


Summary
When a client sends a raster function with a GetImage or ExportImage request to the server, the server returns an image with the raster function applied. This topic shows how to apply a raster function to an image service.

Applying a raster function to an image service

To apply a raster function to an image service and export the image, follow these steps:
  1. Define the raster function.
  2. Attach the function to a rendering rule.
  3. Define the image service.
  4. Define the return image type.
  5. Export the image.
The following code example shows how to apply a hillshade function to an elevation service and export the image rendered by the hillshade function:
[C#]
public static string ApplyHillshadeFunction(IImageServer imageServer)
{
    //Define a hillshade function.
    IRasterFunction hillshadeFunction=new HillshadeFunctionClass();
    IRasterFunctionArguments functionArgument=new HillshadeFunctionArgumentsClass()
        ;
    functionArgument.PutValue("Altitude", 45);
    functionArgument.PutValue("Azimuth", 315);
    functionArgument.PutValue("ZFactor", 1.0);

    //Attach the function to a rendering rule.
    IRenderingRule renderRule=new RenderingRuleClass();
    renderRule.Function=hillshadeFunction;
    renderRule.Arguments=functionArgument;
    renderRule.VariableName="DEM";

    //Define the image description.
    IGeoImageDescription geoImageDesc=new GeoImageDescriptionClass();
    geoImageDesc.Compression="LZ77";
    geoImageDesc.Extent=imageServer.ServiceInfo.Extent;
    geoImageDesc.Width=800;
    geoImageDesc.Height=600;
    geoImageDesc.Interpolation=rstResamplingTypes.RSP_BilinearInterpolation;
    IGeoImageDescription2 geoImageDesc2=(IGeoImageDescription2)geoImageDesc;
    geoImageDesc2.RenderingRule=renderRule;

    //Define the return image type.
    IImageType imgType=new ImageTypeClass();
    imgType.Format=esriImageFormat.esriImagePNG;
    imgType.ReturnType=esriImageReturnType.esriImageReturnURL;

    //Export the image.
    IImageResult imgResult=imageServer.ExportImage(geoImageDesc2, imgType);
    return imgResult.URL;
}
[VB.NET]
Public Shared Function ApplyHillshadeFunction(ByVal imageServer As IImageServer) As String
'Define a hillshade function.
Dim hillshadeFunction As IRasterFunction=New HillshadeFunctionClass()
Dim functionArgument As IRasterFunctionArguments=New HillshadeFunctionArgumentsClass()
functionArgument.PutValue("Altitude", 45)
functionArgument.PutValue("Azimuth", 315)
functionArgument.PutValue("ZFactor", 1)

'Attach the function to a rendering rule.
Dim renderRule As IRenderingRule=New RenderingRuleClass()
renderRule.[Function]=hillshadeFunction
renderRule.Arguments=functionArgument
renderRule.VariableName="DEM"

'Define the image description.
Dim geoImageDesc As IGeoImageDescription=New GeoImageDescriptionClass()
geoImageDesc.Compression="LZ77"
geoImageDesc.Extent=imageServer.ServiceInfo.Extent
geoImageDesc.Width=800
geoImageDesc.Height=600
geoImageDesc.Interpolation=rstResamplingTypes.RSP_BilinearInterpolation
Dim geoImageDesc2 As IGeoImageDescription2=DirectCast(geoImageDesc, IGeoImageDescription2)
geoImageDesc2.RenderingRule=renderRule

'Define the return image type.
Dim imgType As IImageType=New ImageTypeClass()
imgType.Format=esriImageFormat.esriImagePNG
imgType.ReturnType=esriImageReturnType.esriImageReturnURL

'Export the image.
Dim imgResult As IImageResult=imageServer.ExportImage(geoImageDesc2, imgType)
Return imgResult.URL
End Function






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 Desktop Advanced ArcGIS Desktop Advanced
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Basic ArcGIS Desktop Basic
Engine Developer Kit Engine