GridMath3

GridMath3 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 GridMath3 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 GridMath3 command, the input grids must be included in a NewGridMathInput array.

Syntax

object.GridMath3( Function, InGrids, OutGrid, OutFmt, OutGridOptions )

Parameter

Type

Required/

Optional

Default

Description

Function

String

Required

 

This specifies the function equation.

InputGrids

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

SrfGridFormat

Optional

srfGridFmtS7

This provides the output grid file format.

OutGridOptions

String

Optional

""

This provides the output option string for the grid 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 GridMath3 with the function A-B+blanked

SurferApp.GridMath3(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 example 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 GridMath3 with the function "blanked"

SurferApp.GridMath3(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 example demonstrates how to apply function "A*2" to Diablo.grd, save the file as Math.grd and save the spatial references as a MapInfo TAB file.

Dim InGrids(1 To 1) As IGridMathInput

Set InGrids(1) = Surfer.NewGridMathInput(GridFileName:= InGridPath+"Diablo.grd", VariableName:="A")

Surfer.GridMath3(Function:="A * 2", InputGrids:=InGrids, OutGrid:=OutGridPath + "Math.grd", OutFmt:=srfGridFmtS7, OutGridOptions:="UseDefaults=1, ForgetOptions=1, SaveRefInfoAsTAB=1")

Example 4

This script displays all the methods in the Application object.

Used by: Application object