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.
To run this script:
- Copy the script below, or download the attached BAS file: ContourMap_DualUnitColorscale.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.
- In the Variables section, update the custom parameters to match your map:
- MtoF = the conversion factor to convert from your current to your desired units
- zMinM = the minimum contour of the map
- zMaxM = the maximum contour of the map
- zIntM = the contour interval of the map
- Click Script | Run to run the script.
Sub Main Debug.Clear '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 '=============================== 'Variables '=============================== 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.LoadPreset("Rainbow3") ContourLayer.FillForegroundColorMap.SetDataLimits (DataMin:=zMinM, DataMax:=zMaxM) ContourLayer.ShowMajorLabels = False ContourLayer.ShowMinorLabels = False 'Add color scale and edit properties ContourLayer.ShowColorScale=True 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.LoadPreset("Rainbow3") ContourLayer2.FillForegroundColorMap.SetDataLimits (DataMin:=zMinF, DataMax:=zMaxF) 'Add a color scale to the new layer and edit properties ContourLayer2.ShowColorScale=True 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
Comments
0 comments
Please sign in to leave a comment.