Fill contours via Surfer automation

One of the most common processes completed by Surfer users is to create a contour map and apply a colormap.  This sample script demonstrates how to:

  • create a contour map
  • fill the contour intervals using a preset colormap
  • fill a single contour interval with a specific color
  • fill the contour intervals with a custom gradational colormap

To run this script:

  1. Copy the script below, or download the attached BAS file: contourfill.BAS
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer\Scripter.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. 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.
  6. Click Script | Run to run the script.
     

*********

'==========================================================================
'CONTOURFILL.BAS
'
'This script demonstrates the following:
'
'	How to create a contour map
'	How to fill the contour intervals with CLR file
'	How to fill a single contour interval with a specific color
'	How to apply a custom gradational colormap to a contour map
'==========================================================================

Sub Main
	Dim SurferApp As Object
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True
	
	Path = SurferApp.Path + "\samples\"
	
	Dim Plot As Object
	Set Plot = SurferApp.Documents.Add
	Set MapFrame = Plot.Shapes.AddContourMap(GridFileName:=Path+"demogrid.grd")
	Set ContourLayer = MapFrame.Overlays(1)
	ContourLayer.FillContours = True

'Fills the contours with colors from a preset CLR file
	ContourLayer.FillForegroundColorMap.LoadPreset("Rainbow")
	ContourLayer.ApplyFillToLevels(1, 1, 0)

'Change a specific contour interval to Magenta
	Set Levels = ContourLayer.Levels
	Levels(8).Fill.ForeColorRGBA.Color = srfColorMagenta
	
'Move first map to lower left
	MapFrame.Selected = True
	Plot.Selection.Left = 1.0
	Plot.Selection.Top = 4.0
		
'Deselect All
	Plot.Selection.DeselectAll
	
'Create a second contour map and fill contours
	Set MapFrame2 = Plot.Shapes.AddContourMap(GridFileName:=Path+"demogrid.grd")
	Set ContourLayer2 = MapFrame2.Overlays(1)
	ContourLayer2.FillContours = True
	
'Set the colors to be gradational from blue to white
	Set Levels2 = ContourLayer2.Levels
	m = Levels2.Count
	ColorInc2 = 255.0 / (m-1)
	For j=1 To m
		ColorInc2 = 255.0 * (j-1) / (m-1)
		Levels2(j).Fill.ForeColorRGBA.Color = RGB(ColorInc2,ColorInc2,255)
	Next j
	
	'Move second map to upper right
	MapFrame2.Selected = True
	Plot.Selection.Left = 4.5
	Plot.Selection.Top = 10.0
	
	'Turn on screen updating to view maps
	Plot.Windows(1).Zoom(srfGridZoomFitToWindow)
End Sub

 

Updated October 2021

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

Comments

0 comments

Please sign in to leave a comment.