GridMath2
GridMath2 is superceded by GridMath3. Consider using GridMath3 instead. GridMath2 has been retained for backward compatibility.
GridMath2 performs grid-to-grid and grid-to-constant math operations. It creates a new grid file that transforms the Z values of a single grid file or combines Z values from multiple grid files. The output grid file is based on a mathematical function of the form f (A ,B, ...), where A, B, ... are input grid files. Returns a Boolean. Returns 'True', if the new grid file is successfully created, otherwise, returns 'False'.
The GridMath2 command should be used instead of GridMath command when more than two grids need to be combined or when the Z value of NoData grid nodes need to be changed.
Before calling the GridMath2 command, the input grids must be included in a NewGridMathInput array.
Syntax
object. GridMath2( Function, InGrids, OutGrid, OutFmt )
Parameter |
Type |
Required/ Optional |
Default |
Description |
Function |
String |
Required |
|
This specifies the function equation. |
InGrids |
Array |
Required |
|
This provides the path, file name, and any options for the input grid files. This is defined with the NewGridMathInput. |
OutGrid |
String |
Optional |
"" |
This provides the path and file name of the output grid file. |
OutFmt |
Optional |
srfGridFmtS7 |
This provides the output grid file format. |
Example 1
This example demonstrates how to add three grids together. Sample1a.grd is gridded using the first, second and third columns (X, Y and Z1) of Sample1.dat while Sample1b.grd is gridded using the first, second and fourth columns (X, Y and Z2). Sample1c.grd is gridded using the first, second, and fifth columns (X, Y, Z3). The output grid file, GridCombine.grd, represents the difference in Z values between Sample1a.grd and Sample1b.grd and added to Sample1c.grd. A contour map is then created from GridCombine.grd.
'Create the first grid
SurferApp.GridData(DataFile:=SurferApp.Path+"\Samples\demogrid.dat", xCol:=1, _
yCol:=2, zCol:=3, Algorithm:=srfKriging, ShowReport:=False, _
OutGrid:="c:\temp\demogrida.grd", OutFmt:=srfGridFmtS7)
'Create the second grid
SurferApp.GridData(DataFile:=SurferApp.Path+"\Samples\demogrid.dat", xCol:=1, _
yCol:=2, zCol:=3, Algorithm:=srfKriging, ShowReport:=False, _
OutGrid:="c:\temp\demogridb.grd", OutFmt:=srfGridFmtS7)
'Create the third grid
SurferApp.GridData(DataFile:=SurferApp.Path+"\Samples\demogrid.dat", xCol:=1, _
yCol:=2, zCol:=3, Algorithm:=srfKriging, ShowReport:=False, _
SearchEnable:=False, SearchRad1:=5, SearchRad2:=5, _
OutGrid:="c:\temp\demogridc.grd", OutFmt:=srfGridFmtS7)
'Create the InGrids() array with 3 grid files
Dim InGrids (1 To 3) As IGridMathInput
'The first input grid will use Variable="A", second Variable = "B", third Variable="blanked"
'The first and second grids will use NoData values.
'The third grid will remap NoData nodes To 1000.
Set InGrids(1) = SurferApp.NewGridMathInput(GridFileName:= _
"c:\temp\demogrida.grd", VariableName:="A")
Set InGrids(2) = SurferApp.NewGridMathInput(GridFileName:= _
"c:\temp\demogridb.grd", VariableName:="B")
Set InGrids(3) = SurferApp.NewGridMathInput(GridFileName:= _
"c:\temp\demogridc.grd", VariableName:="blanked", _
BlankHandling:=srfGMBlankRemap, RemapValue:=1000)
'Use the GridMath2 with the function A-B+blanked
SurferApp.GridMath2(Function:="A-B+blanked", InputGrids:=InGrids, _
OutGrid:="c:\temp\GridCombine.grd", OutFmt:=srfGridFmtS7)
'Create a contour map from the output grid
Plot.Shapes.AddContourMap("c:\temp\GridCombine.grd")
Example 2
This script demonstrates how to assign Z values to the NoData values in a single grid.
'Create the grid with NoData values
SurferApp.GridData(DataFile:=SurferApp.Path+"\Samples\demogrid.dat", xCol:=1, _
yCol:=2, zCol:=3, Algorithm:=srfKriging, ShowReport:=False, _
SearchEnable:=True, SearchRad1:=5, SearchRad2:=5, _
OutGrid:="c:\temp\demogridc.grd", OutFmt:=srfGridFmtS7)
'Create a contour map from the grid and move it to the left of the page
Set ContourMap1 = Plot.Shapes.AddContourMap("c:\temp\demogridc.grd")
ContourMap1.Left = -6
'Create the InGrids() array with 1 grid files
Dim InGrids (1 To 1) As IGridMathInput
'The first input grid will use variable="blanked"
Set InGrids(1) = SurferApp.NewGridMathInput(GridFileName:="c:\temp\demogridc.grd", _
VariableName:="blanked", BlankHandling:=srfGMBlankRemap, RemapValue:=1000)
'Use the GridMath2 with the function "blanked"
SurferApp.GridMath2(Function:="blanked", InputGrids:=InGrids, _
OutGrid:="c:\temp\ChangeBlank.grd", OutFmt:=srfGridFmtS7)
'Create a contour map from the output grid
Plot.Shapes.AddContourMap("c:\temp\ChangeBlank.grd")
Example 3
This script displays all the methods in the Application object.
Used by: Application object