When analyzing data, there are times when only values above or below a certain threshhold are relevant. For example, when evaluating an area for building sites with acceptable inclines and obstructions. One way to make this process easier is to remove data that doesn't meet your criteria. In the script below, this is done by prompting the user for a cutoff value and direction and then assigning NoData to grid file as directed.
To run this script:
- Copy the text below, or download the attached BAS file: BlankByLevel.bas.
- In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
- Double click on Scripter.exe to launch Scripter.
- Press Ctrl+A to select all of the existing lines then press Delete.
- If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
- Click Script | Run to run the script.
*********
'BlankByLevel blanks a grid above or below a given Z value, 'and saves the blanked grid to a new grid file. Sub Main Debug.Clear Dim SurferApp As Object Set SurferApp = CreateObject("Surfer.Application") SurferApp.Visible = True Set Plot = SurferApp.Documents.Add(srfDocPlot) Set Shapes = Plot.Shapes Set Grid = SurferApp.NewGrid 'Choose a grid file gridfilepath = GetFilePath( , "grd",SurferApp.Path+"\samples\","Open Grid File",0) Set Grid2 = Grid.LoadFile(gridfilepath,False) Debug.Print "Grid Min =";Grid.zMin Debug.Print "Grid Max =";Grid.zMax ' Set level cutoff and flag above or below Dim level As Double Dim below As Boolean Begin Dialog UserDialog 270,112 ' %GRID:10,7,1,1 Text 10,7,90,14,"Z Level value:",.Text0 TextBox 10,28,180,21,.LevlVal OptionGroup .Group1 OptionButton 20,77,130,14,"Blank Below",.below OptionButton 20,56,130,14,"Blank Above",.above OKButton 170,70,80,21 End Dialog Dim entervalue As UserDialog Dialog entervalue level = Val(entervalue.LevlVal$) Debug.Print "Z Level Value = ";entervalue.LevlVal$ If entervalue.Group1 = 0 Then below = True If entervalue.Group1 = 1 Then below = False Debug.Print "Processing GridRow:" For row=1 To Grid.NumRows() For col=1 To Grid.NumCols() If below = True Then If Grid.GetNode(row,col) < level And Grid.IsBlanked(row,col) = False Then Grid.BlankNode(row,col) ElseIf below = False Then If Grid.GetNode(row,col) > level And Grid.IsBlanked(row,col) = False Then Grid.BlankNode(row,col) End If Next col Debug.Print row; If row Mod 20 = 0 Then Debug.Print Next row 'Saves the grid to a new name gridfilepath = Left(gridfilepath,InStrRev(gridfilepath,".")-1) + "_Blanked.grd Grid.SaveFile(gridfilepath, srfGridFmtS7) Debug.Print "" 'newline Debug.Print "" 'newline Debug.Print "File saved as ";gridfilepath 'Creates a contour map of new grid Shapes.AddContourMap(gridfilepath) End Sub
Updated November 2021
Comments
Where do I set the Z value which will blank the values above or below it? This algorithm seems like the normal blanking.
Hi Felipe,
Thank you for posting your question! It appears the wrong script was included this article, but the attachment was correct. My apologies for the confusion. I have updated the article so you can copy/paste the correct script should you prefer that to downloading it.
You will now see where to set the Z level on line 39. Please let me know if you have any other questions.
Thank you,
Brittany Bodane
Technical Support
I am trying to print Grid Statistics for Z, specifically the 99 percentile. Does anyone know how I can accomplish this?
My code currently displays the zMin & zMax (snip from above) but when I use Debug.Print Grid.Statistics.Percentile99 it returns the 99Percentile of X and I'm not sure how to specify Z.
Alternatively, I would be okay with the entire grid statistics running / opening & saving. Then I could scroll for the specific stats I need and open the statistics document at a later date if required, but I cant seem to find out a code for this either.
I am also confused as to why Debug.Print row; is used at the end, as I get hundreds of numbers printing due to this and it doesn't seem to stop..
Any advice would be greatly appreciated! :)
Hi Michael,
Thank you for posting your question. Percentile99 pertains to the Z value by default, so you should be seeing this data for the Z value. You can verify this number by looking at the Grid Report for your grid. If you are still not seeing this in relation to your Z values, please email your script and a data file you are seeing this behavior with to support@goldensoftware.com.
If you would like to have the Grid Report open and save via automation, this can be done during the gridding process. We have a sample script for this you may be interested in: https://support.goldensoftware.com/hc/en-us/articles/227873488-How-can-I-save-a-grid-report-when-using-Surfer-Scripter-.
Regarding your last question about Debug.Print row being used at the end of the this sample script, I believe this is included so you can see the script is working, and which row it is on. However, it is not necessary for the function of the script and you can delete these lines if you choose.
Thanks,
Brittany
Technical Support
Golden Software
Please sign in to leave a comment.