Add a colorscale with feet and meters to a contour map via Surfer automation

The use of metric and standard units of measurement is not always consistent so it can be useful to display both (meters and feet for example) on a map.  Surfer's colorscale does not support the display of two label sets but it is possible to use a script to achieve this result.  The script below will add a second set of labels to a colorscale with different units.  It is currently written to convert meters to feet so some adjustments are needed if your units are different.

Create a contour map with a color scale in two units in Surfer!

To run this script:

  1. Copy the script below, or download the attached BAS file: ContourMap_DualUnitColorscale.BAS.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
  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. In the Variables section, update the custom parameters to match your map:
    1. MtoF = the conversion factor to convert from your current to your desired units
    2. zMinM = the minimum contour of the map
    3. zMaxM = the maximum contour of the map
    4. zIntM = the contour interval of the map
  7. Click Script | Run to run the script.



Sub Main

'Initializes Surfer
	Dim SurferApp, Plot, MapFrame, ContourLayer, MapFrame2, ContourLayer2, ColorScale, ColorScale2 As Object
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True
	Set Plot = SurferApp.Documents.Add
	Plot.PageSetup.Orientation = srfLandscape

MtoF = 3.28084
zMinM = 25
zMaxM = 100
zIntM = 4
zMinF = zMinM * 3.28084
zMaxF = zMaxM * 3.28084
zIntF = zIntM * 3.28084

'Creates contour map from original grid file (meters)
	Set MapFrame = Plot.Shapes.AddContourMap(GridFileName:=SurferApp.Path + "\samples\demogrid.grd")
	Set ContourLayer = MapFrame.Overlays(1)

'Edit the contour layer
	ContourLayer.LevelMethod = SrfConLevelMethodSimple
        ContourLayer.SetSimpleLevels(Min:=zMinM, Max:=zMaxM, Interval:=zIntM)
	ContourLayer.FillContours = True
	ContourLayer.FillForegroundColorMap.SetDataLimits (DataMin:=zMinM, DataMax:=zMaxM)
	ContourLayer.ShowMajorLabels = False
	ContourLayer.ShowMinorLabels = False

'Add color scale and edit properties
	Set ColorScale = ContourLayer.ColorScale
	ColorScale.Title = "Elevation"
	ColorScale.TitlePosition = srfColorScaleTitlePositionTop
	ColorScale.TitleAngle = 0
	ColorScale.TitleOffsetHorizontal = -0.2
	ColorScale.LabelFormat.Postfix = " m"
	ColorScale.Left = 9

'Convert grid file to feet
  	Dim inGrid(1 To 1) As IGridMathInput
   	Set inGrid(1) = SurferApp.NewGridMathInput(SurferApp.Path+"\Samples\demogrid.grd", "A")
	SurferApp.GridMath2("A* 3.28084" , inGrid, "C:\temp\demogrid_feet.grd")

'Create new contour map
	Set MapFrame2 = Plot.Shapes.AddContourMap(GridFileName:= "C:\temp\demogrid_feet.grd")
	Set ContourLayer2 = MapFrame2.Overlays(1)

'Edit contour layer to have the same layer properties as for the other layer
	ContourLayer2.LevelMethod = SrfConLevelMethodSimple
    ContourLayer2.SetSimpleLevels(Min:=zMinF, Max:=zMaxF, Interval:=zIntF)
	'ContourLayer2.FillContours = True
	ContourLayer2.FillForegroundColorMap.SetDataLimits (DataMin:=zMinF, DataMax:=zMaxF)

'Add a color scale to the new layer and edit properties
	Set ColorScale2 = ContourLayer2.ColorScale
	ColorScale2.Title = ""
	ColorScale2.LabelFormat.Type = srfLabFixed
	ColorScale2.LabelFormat.NumDigits = 1
	ColorScale2.LabelFormat.Postfix = " ft"
	ColorScale2.Left = 8.4

'Turn off what you don't want to see
	MapFrame2.Visible = False
	ContourLayer2.MajorLine.Style = "Invisible"
	ContourLayer2.MinorLine.Style = "Invisible"
	ColorScale2.FrameLine.Style = "Invisible"
End Sub


Was this article helpful?
8 out of 10 found this helpful



Please sign in to leave a comment.