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


How to create a Conditional Function raster dataset (ArcObjects .NET 10.4 SDK)

How to create a Conditional Function raster dataset


Creating a Conditional Function raster dataset

Do the following steps to create a Conditional Function raster dataset:
  1. Create the Conditional Function object.
  2. Create the Conditional Function arguments object.
  3. Set the properties for the conditional function arguments.
    1. Specify the operation.
    2. Specify the input conditional raster.
    3. Specify the true raster and false raster.
      • These can be a Raster or Scalar object.
  4. Create a Raster function object.
  5. Create a Function raster dataset object.
  6. Initialize the new function raster dataset with the raster function and its arguments.
The following code example shows how to create a Conditional Function raster dataset by querying a raster for some values (using a greater than Math Function) to create the conditional raster, then use the Con operation to assign new output values based on another raster if the condition is True, and a scalar value, if the condition is false.
[C#]
////Executes the "GreaterThan" operation to create a conditional raster. 
//Create a Raster Function and Function Argument object.
IRasterFunction rasterFunction1=new MathFunction();
IMathFunctionArguments mathFunctionArguments=new MathFunctionArguments()as
    IMathFunctionArguments;

//Open a raster dataset and create a Scalar object for the "GreaterThan" operation.
.mathFunctionArguments.Operation =
    esriGeoAnalysisFunctionEnum.esriGeoAnalysisFunctionGreaterThan;
mathFunctionArguments.Raster=inRasterDataset01;
IScalar inScalar01=new Scalar();
inScalar01.Value=2000;
mathFunctionArguments.Raster2=inScalar01;

//Create and initialize the Function raster dataset.
IFunctionRasterDataset greaterThanRasterDataset;
greaterThanRasterDataset=new FunctionRasterDataset();
greaterThanRasterDataset.Init(rasterFunction1, mathFunctionArguments);

////Executes the "Con" operation.
//Create the Raster Function object and the Function Argument object.
IRasterFunction rasterFunction2=new ConditionalFunction();
IConditionalFunctionArguments conditionalFunctionArguments=new
    ConditionalFunctionArguments()as IConditionalFunctionArguments;

//Open the raster dataset and create a Scalar object for the input true and false raster for the input true raster for the Con operation.
//Use the Function raster dataset from the "GreaterThan" operation as the input conditional raster.
conditionalFunctionArguments.Operation =
    esriGeoAnalysisFunctionEnum.esriGeoAnalysisFunctionCon;
conditionalFunctionArguments.ConditionalRaster=greaterThanRasterDataset;
conditionalFunctionArguments.TrueRaster=inRasterDataset02;
IScalar inScalar02=new Scalar();
inScalar02.Value= - 999;
conditionalFunctionArguments.FalseRaster=inScalar02;

//Create and initialize a Function raster dataset.
IFunctionRasterDataset functionRasterDataset;
functionRasterDataset=new FunctionRasterDataset();
functionRasterDataset.Init(rasterFunction2, conditionalFunctionArguments);
[VB.NET]
''''Executes the "GreaterThan" operation to create a conditional raster.
'Create a Raster Function and Function Argument object.
Dim rasterFunction1 As IRasterFunction
rasterFunction1=New MathFunction()
Dim mathFunctionArguments As IMathFunctionArguments
mathFunctionArguments=New MathFunctionArguments()
mathFunctionArguments.Operation=esriGeoAnalysisFunctionEnum.esriGeoAnalysisFunctionGreaterThan

'Open a raster dataset and create a Scalar object for the "GreaterThan" operation.
Dim inScalar01 As IScalar
inScalar01=New Scalar()
inScalar01.Value=2000
mathFunctionArguments.Raster=inRasterDataset01
mathFunctionArguments.Raster2=inScalar01

'Create and initialize the Function raster dataset.
Dim greaterThanRasterDataset As IFunctionRasterDataset
greaterThanRasterDataset=New FunctionRasterDataset()
greaterThanRasterDataset.Init(rasterFunction1, mathFunctionArguments)

''''Executes the "Con" operation.
'Create the Raster Function object and the Function Argument object.
Dim rasterFunction As IRasterFunction
rasterFunction=New ConditionalFunction()
Dim conditionalFunctionArguments As IConditionalFunctionArguments
conditionalFunctionArguments=New ConditionalFunctionArguments()

'Open the raster dataset and create a Scalar object for the input true and false raster for the input true raster for the Con operation.
'Use the Function raster dataset from the "GreaterThan" operation as the input conditional raster.
conditionalFunctionArguments.Operation=esriGeoAnalysisFunctionEnum.esriGeoAnalysisFunctionCon
conditionalFunctionArguments.ConditionalRaster=greaterThanRasterDataset
conditionalFunctionArguments.TrueRaster=inRasterDataset02
Dim inScalar02 As IScalar
inScalar02=New Scalar()
inScalar02.Value=-999
conditionalFunctionArguments.FalseRaster=inScalar02

'Create and initialize a Function raster dataset.
Dim functionRasterDataset As IFunctionRasterDataset
functionRasterDataset=New FunctionRasterDataset()
functionRasterDataset.Init(rasterFunction, conditionalFunctionArguments)


See Also:

How to create a Math Function raster dataset
How to create a Local Function raster dataset
How to save a Function raster dataset into a raster dataset
How to access a raster dataset
Samples:




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: Spatial Analyst ArcGIS for Desktop Advanced: Spatial Analyst
ArcGIS for Desktop Standard: Spatial Analyst ArcGIS for Desktop Standard: Spatial Analyst
ArcGIS for Desktop Basic: Spatial Analyst ArcGIS for Desktop Basic: Spatial Analyst