For those needing to showcase data in both metric and standard units, having a dual-labeled color scale can be a game-changer! Surfer's color scale doesn't natively support dual units, but this script offers a clever solution. By generating two contour maps—one in meters and another in feet—it adds aligned color scale bars for each and strategically hides the extra elements. The result? A seamless single map with a color scale displaying both meters and feet, offering clear, professional, dual-unit visuals. While it currently converts meters to feet, the script can be easily customized for other unit conversions.
To run this script:
- In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
- Double click on Scripter.exe to launch Scripter.
- Copy and paste the script below into Scripter's code window (be sure to delete any existing lines first), or simply download the attached BAS file and open it in Scripter.
- Update the values in the USER-DEFINED VARIABLES section near the top of the script as needed. If you skip this step, the script will still run using the current values for these variables.
- Click Script | Run to run the script.
Sub Main 'Clear any output in the Imediate window Debug.Clear 'Initialize Surfer Dim SurferApp As Object Set SurferApp = CreateObject("Surfer.Application") SurferApp.Visible = True '====================================================== 'USER-DEFINED VARIABLES '====================================================== path2inputGrid = SurferApp.Path + "\samples\demogrid.grd" meters2feet = 3.28084 'conversion factor to convert meters to feet zMinMeters = 25 'the minimum contour value in meters zMaxMeters = 100 'the maximum contour value in meters zIntMeters = 4 'the contour interval in meters zMinFeet = zMinMeters * meters2feet zMaxFeet = zMaxMeters * meters2feet zIntFeet = zIntMeters * meters2feet '====================================================== 'Create a new plot document Dim Plot As Object Set Plot = SurferApp.Documents.Add Plot.PageSetup.Orientation = srfLandscape 'Create a contour map from original grid file (meters) Dim MapFrame As Object, ContourLayer As Object Set MapFrame = Plot.Shapes.AddContourMap(GridFileName:=path2inputGrid) MapFrame.Name = "Map (m)" Set ContourLayer = MapFrame.Overlays(1) 'Edit the contour layer properties With ContourLayer .LevelMethod = SrfConLevelMethodSimple .SetSimpleLevels(Min:=zMinMeters, Max:=zMaxMeters, Interval:=zIntMeters) .FillContours = True .FillForegroundColorMap.LoadPreset("Rainbow3") .FillForegroundColorMap.SetDataLimits(DataMin:=zMinMeters, DataMax:=zMaxMeters) .ShowMajorLabels = False .ShowMinorLabels = False End With 'Add color scale and edit properties Dim ColorScale As Object ContourLayer.ShowColorScale=True Set ColorScale = ContourLayer.ColorScale With ColorScale .Name = "Color Scale (m)" .Title = "Elevation" .TitlePosition = srfColorScaleTitlePositionTop .TitleAngle = 0 .TitleOffsetHorizontal = -0.2 .LabelFormat.Postfix = " m" .Left = 9 End With 'Convert grid file to feet Dim inGrid(1 To 1) As IGridMathInput Set inGrid(1) = SurferApp.NewGridMathInput(SurferApp.Path + "\Samples\demogrid.grd", "A") SurferApp.GridMath3("A*" + Str(meters2feet), inGrid, "C:\temp\demogrid_feet.grd") 'Create a new contour map Dim MapFrame2 As Object, ContourLayer2 As Object Set MapFrame2 = Plot.Shapes.AddContourMap(GridFileName:= "C:\temp\demogrid_feet.grd") MapFrame2.Name = "Map (ft)" Set ContourLayer2 = MapFrame2.Overlays(1) 'Edit contour layer to have the same layer properties as for the other layer With ContourLayer2 .LevelMethod = SrfConLevelMethodSimple .SetSimpleLevels(Min:=zMinFeet, Max:=zMaxFeet, Interval:=zIntFeet) .FillForegroundColorMap.LoadPreset("Rainbow3") .FillForegroundColorMap.SetDataLimits (DataMin:=zMinFeet, DataMax:=zMaxFeet) .ShowMajorLabels = False .ShowMinorLabels = False End With 'Add a color scale to the new layer and edit properties Dim ColorScale2 As Object ContourLayer2.ShowColorScale = True Set ColorScale2 = ContourLayer2.ColorScale With ColorScale2 .Name = "Color Scale (ft)" .Title = "" .LabelFormat.Type = srfLabFixed .LabelFormat.NumDigits = 1 .LabelFormat.Postfix = " ft" .Left = 8.4 End With 'Hide the second contour map and the second color scale bar's lines MapFrame2.Visible = False ContourLayer2.MajorLine.Style = "Invisible" ContourLayer2.MinorLine.Style = "Invisible" ColorScale2.FrameLine.Style = "Invisible" End Sub
Related Articles and Help Pages:
- GridMath3 method
- NewGridMathInput method
- Set the data limits and scaling for a colormap via Surfer automation
- Change the contour map fill color via Surfer automation
Updated October 2024
Comments
Please sign in to leave a comment.