Assign NoData using a polygon boundary via Surfer automation

Automation now allows users to point to polygons drawn in a base layer to be used to assign NoData instead of requiring them to export those polygons as BLNs. See below for specifications on how to use the new objects and methods in automation: 


GridAssignNoData (renamed from GridBlank2 and extended to add the following three parameters):

Parameter Type Required/Optional Default Description
Layer VectorBaseLayer Object Optional Empty The vector base layer whose polygons can be used as the polygon boundary for assigning NoData
SelectedPolysOnly Boolean Optional False If True, only selected polygons from the 'Layer' parameter will be used for the polygon boundary. If False, all polygons from the 'Layer' parameter will be used for the polygon boundary
Side SrfNoDataPolygonSide enum Optional srfNoDataPolyMixed The side of each polygon (inside or outside) in the polygon boundary to be used for assigning NoData

 

Remarks:

The 'BlankFile' parameter has been renamed to 'NoDataFile' and is now optional (with a default value of ""). If both the 'Layer' and 'NoDataFile' parameters are provided, the GridAssignNoData() method will use the value provided to 'Layer' for the polygon boundary. If neither of these parameters are provided, an error will be raised.

The 'SelectedPolysOnly' and 'Side' parameters only apply to GridAssignNoData() if the 'Layer' parameter is provided. If the user provides the 'NoDataFile' parameter instead, the two aforementioned parameters will be ignored.

The 'Layer' parameter must be defined using 'Dim [LayerObject] as Object' before passing [LayerObject] in for the 'Layer' parameter, in order for the GridAssignNoData() method to work correctly. If this 'Dim [LayerObject] as Object' line is not added to the script before passing [LayerObject] in for the 'Layer' parameter, the GridAssignNoData() method will not recognize the value passed in for the 'Layer' parameter as a valid VectorBaseLayer object.

If any other type of object (other than a VectorBaseLayer) is passed in for the 'Layer' parameter, an error is raised.


 

SrfNoDataPolygonSide Values

Enumeration Value Description
srfNoDataPolyOutside 0 Assign NoData to the grid nodes outside of the polygons in the polygon boundary
srfNoDataPolyInside 1 Assign NoData to the grid nodes inside of the polygons in the polygon boundary
srfNoDataPolyMixed 2 Assign NoData to the grid nodes inside or outside of the polygons in the polygon boundary on a polygon by polygon basis

Example: (the path on line 5 will need to be updated; I have also attached the 'SelectedPgon.srf' file)

 Sub Main
    Dim Surfer As Object
    Set Surfer = GetObject(,"Surfer.Application")
    Surfer.Visible = True
    Set dirPath = "C:\Users\David\Downloads"

    Dim BaseLayer As Object 'This line is required
    Set Plot = Surfer.Documents.Open(dirPath + "\SelectedPgon.srf")

    Set BaseLayer = Plot.Shapes.Item(1).Overlays.Item(2)
    BaseLayer.Shapes.StartEditing()
    BaseLayer.Shapes.Item("Donut").Select

    'assigns NoData to Conifer.grd for all nodes in base layer (represented by 'BaseLayer') outside of the selected polygons (just the polygon called 'Donut' in this case)
    Surfer.GridAssignNoData(Surfer.Path + "\Samples\Conifer.grd", Layer:=BaseLayer, SelectedPolysOnly:=True, Side:=srfNoDataPolyOutside, OutGrid:=dirPath + "\outLayer.grd")
Set MapFrame1 = Plot.Shapes.AddColorReliefMap(GridFileName:=dirPath + "\outLayer.grd")

    'assigns NoData using the 'NoDataFile' parameter (equivalent to how GridBlank used to work) - 'Side' and 'SelectedPolysOnly' parameters would not apply if provided in this case
    Surfer.GridAssignNoData(Surfer.Path + "\Samples\Demogrid.grd", NoDataFile:=Surfer.Path + "\Samples\Demorect.bln", OutGrid:=dirPath + "\outFile.grd")
Set MapFrame2 = Plot.Shapes.AddColorReliefMap(GridFileName:=dirPath + "\outFile.grd")

End Sub

 

Updated January 2021

 

Was this article helpful?
3 out of 3 found this helpful

Comments

0 comments

Please sign in to leave a comment.