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


How to create a Constant function dataset (ArcObjects .NET 10.5 SDK)

How to create a Constant function dataset


Creating a Constant function dataset

To create a Constant function dataset, follow these steps:
  1. Create an Identity function using the input dataset.  
  2. Create the Function Arguments object.
  3. Specify the constant value to use to fill the pixels of the raster.
  4. Specify the Raster Info for the constant raster to be created. Use the info extracted from the Identity function created in Step 1.
  5. Create a Raster Function object.
  6. Create a Function Raster Dataset object.
  7. Create a name object for the function raster dataset.
  8. Specify the output file name for the new dataset.
  9. Initialize the new function raster dataset with the raster function and its arguments.
The following code example shows how to create a Constant function raster dataset by applying the constant raster function to an image:
[C#]
// Create an Identity function from the input dataset.
// The Identity function is then used to extract info from the input data.
IRasterFunction identFunction=(IRasterFunction)new IdentityFunction();
// The input data can be of type IRasterDataset, IRasterBand, or IRaster.
identFunction.Bind(inputData);

// Create the Function Arguments object.
IConstantFunctionArguments rasterFunctionArguments=(IConstantFunctionArguments)new
    ConstantFunctionArguments();
// Set the value to fill the pixels of the raster.
rasterFunctionArguments.Constant=128;
// Use the info from the Identity function.
rasterFunctionArguments.RasterInfo=identFunction.RasterInfo;

// Create the Raster Function object.
IRasterFunction rasterFunction=new ConstantFunction();
// Create the Function Raster Dataset object.
IFunctionRasterDataset functionRasterDataset=new FunctionRasterDataset();
// Create a name object for the Function Raster Dataset.
IFunctionRasterDatasetName functionRasterDatasetName=(IFunctionRasterDatasetName)
    new FunctionRasterDatasetName();
// Specify the output file name for the new dataset (including the .afr extension at the end).
functionRasterDatasetName.FullName=@"c:\temp\Constant.afr";
functionRasterDataset.FullName=(IName)functionRasterDatasetName;
// Initialize the new Function Raster Dataset with the Raster Function and its arguments.
functionRasterDataset.Init(rasterFunction, rasterFunctionArguments);
[VB.NET]
' Create an Identity function from the input dataset.
' The Identity function is then used to extract info from the input data.
Dim identFunction As IRasterFunction
identFunction=New IdentityFunction()
' The input data can be of type IRasterDataset, IRasterBand, or IRaster.
identFunction.Bind(inputData)

' Create the Function Arguments object.
Dim rasterFunctionArguments As IConstantFunctionArguments
rasterFunctionArguments=New ConstantFunctionArguments()
' Set the value to fill the pixels of the raster.
rasterFunctionArguments.Constant=128
' Use the info from the Identity function.
rasterFunctionArguments.RasterInfo=identFunction.RasterInfo

' Create the Raster Function object.
Dim rasterFunction As IRasterFunction
rasterFunction=New ConstantFunction()
' Create the Function Raster Dataset object.
Dim functionRasterDataset As IFunctionRasterDataset
functionRasterDataset=New FunctionRasterDataset()
' Create a name object for the Function Raster Dataset.
Dim functionRasterDatasetName As IFunctionRasterDatasetName
functionRasterDatasetName=New FunctionRasterDatasetName()
' Specify the output file name for the new dataset (including the .afr extension at the end).
functionRasterDatasetName.FullName="c:\temp\ArithmaticFunction.afr"
functionRasterDataset.FullName=functionRasterDatasetName
' Initialize the new Function Raster Dataset with the Raster Function and its arguments.
functionRasterDataset.Init(rasterFunction, rasterFunctionArguments)






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