Creating a Math Function raster dataset
Do the following steps to create a Math Function raster dataset:
- Create the Math Function object.
- Create the Math Function Arguments object.
- Set the properties for the Math Function arguments.
- Specify the operation.
- Specify the operands for the operation.
- If only one operand is needed, only specify the Raster property; otherwise, specify both Raster and Raster2 respectively.
- The operands can be a Raster or Scalar (at least one must be a Raster) object.
- Create a Raster Function object.
- Create a Function Raster dataset object.
- Initialize the new Function Raster dataset with the raster function and its arguments.
The following code example shows how to create a Math function raster dataset, combining multiple operations together into a complex equation:
- outFunctionRaster=(raster01 + raster02) / raster03
'Create the Raster Function object and Function Arguments object for the first operation.
Dim rasterFunction1 As IRasterFunction
rasterFunction1=New MathFunction()
Dim mathFunctionArguments1 As IMathFunctionArguments
mathFunctionArguments1=New MathFunctionArguments()
'Open raster datasets and specify as inputs for the "Plus" operation.
mathFunctionArguments1.Operation=esriGeoAnalysisFunctionEnum.esriGeoAnalysisFunctionPlus
mathFunctionArguments1.Raster=inRasterDataset01
mathFunctionArguments1.Raster2=inRasterDataset02
'Create and initialize first function raster dataset with the Raster Function object and its arguments object.
Dim functionRasterDataset1 As IFunctionRasterDataset
functionRasterDataset1=New FunctionRasterDataset()
functionRasterDataset1.Init(rasterFunction1, mathFunctionArguments1)
'Create the Raster Function and the Function Arguments object for the second operation.
Dim rasterFunction2 As IRasterFunction
rasterFunction2=New MathFunction()
Dim mathFunctionArguments2 As IMathFunctionArguments
mathFunctionArguments2=New MathFunctionArguments()
'Specify input rasters for the "Divide" operation.
'Use the output function raster dataset from the 1st operation as one of the input.
mathFunctionArguments2.Operation=esriGeoAnalysisFunctionEnum.esriGeoAnalysisFunctionDivide
mathFunctionArguments2.Raster=functionRasterDataset1
mathFunctionArguments2.Raster2=inRasterDataset03
'Create and initialize the second function raster dataset.
Dim functionRasterDataset2 As IFunctionRasterDataset
functionRasterDataset2=New FunctionRasterDataset()
functionRasterDataset2.Init(rasterFunction2, mathFunctionArguments2)
[C#] //Create the Raster Function object and Function Arguments object for the first operation.
IRasterFunction rasterFunction1=new MathFunction();
IMathFunctionArguments mathFunctionArguments1=new MathFunctionArguments()as
IMathFunctionArguments;
//Open raster datasets and specify as inputs for the "Plus" operation.
mathFunctionArguments1.Operation =
esriGeoAnalysisFunctionEnum.esriGeoAnalysisFunctionPlus;
mathFunctionArguments1.Raster=inRasterDataset01;
mathFunctionArguments1.Raster2=inRasterDataset02;
//Create and initialize first function raster dataset with the Raster Function object and its arguments object.
IFunctionRasterDataset functionRasterDataset1;
functionRasterDataset1=new FunctionRasterDataset();
functionRasterDataset1.Init(rasterFunction1, mathFunctionArguments1);
//Create the Raster Function and the Function Arguments object for the second operation.
IRasterFunction rasterFunction2=new MathFunction();
IMathFunctionArguments mathFunctionArguments2=new MathFunctionArguments()as
IMathFunctionArguments;
//Specify input rasters for the "Divide" operation.
//Use the output function raster dataset from the first operation as one of the input.
mathFunctionArguments2.Operation =
esriGeoAnalysisFunctionEnum.esriGeoAnalysisFunctionDivide;
mathFunctionArguments2.Raster=functionRasterDataset1;
mathFunctionArguments2.Raster2=inRasterDataset03;
//Create and initialize the second function raster dataset.
IFunctionRasterDataset functionRasterDataset2;
functionRasterDataset2=new FunctionRasterDataset();
functionRasterDataset2.Init(rasterFunction2, mathFunctionArguments2);
See Also:
How to create a Local Function raster datasetHow to create a Conditional 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 Basic: Spatial Analyst | ArcGIS for Desktop Basic: Spatial Analyst |
ArcGIS for Desktop Standard: Spatial Analyst | ArcGIS for Desktop Standard: Spatial Analyst |