How can I create and edit a choropleth (hatch) map in MapViewer via automation?

This article contains a sample script for creating a choropleth (hatch) map and editing the methods and properties of the hatch map.

To run this script:

  1. Copy the script below, or click here to download the BAS file: Create_Hatch_Map.bas.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\MapViewer 8\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.


' Create_Hatch_Map.BAS
' Copyright (C) Golden Software Inc. 1992-2015
' This sample demonstrates how to create a hatch map and change the properties

Sub Main

'Initializes and opens MapViewer
Set mvApp = CreateObject("MapViewer.Application")
mvApp.Visible = True
InPath$ = mvApp.ApplicationFolder + "samples\"
Set Plot = mvApp.Documents.Add(DocType:=mvDocPlot)

'Creates a hatch map object and assigns it to the variable named "HatchMap"
Set HatchMap = Plot.CreateHatchMap(BoundaryFileName:=InPath$ + "co2010.gsb", _
	DataFileName:=InPath$ + "co2010.dat", PIDCol:=1, VarCol:=7, NumClasses:=4)

'Loads a color spectrum for the background color

'Set the diameter of the square

'Changes the fill properties for class 1 in the hatch map
HatchMap.ClassFill(iClass:=1).ForeColor = mvColorBlue
HatchMap.ClassFill(iClass:=1).BackColor = mvColorYellow
HatchMap.ClassFill(iClass:=1).Pattern = "Diagonal Cross"
HatchMap.ClassFill(iClass:=1).Transparent = False

'Sets the data classification method to Equal Number.

'Returns the index number of the All Others class
Debug.Print "ClassIndexOfAllOthers = "+HatchMap.ClassIndexOfAllOthers

'Returns the index number of the No Data class
Debug.Print "ClassIndexOfNoData = "+HatchMap.ClassIndexOfNoData

'Returns the maximum value of class 1
Debug.Print "Class 2 MinVal = "+HatchMap.ClassMaxVal(iClass:=2)

'Returns the minimum value of class 1
Debug.Print "Class 1 MinVal = "+HatchMap.ClassMinVal(iClass:=1)

'Sets the draw type of the hatch map to be a square
HatchMap.DrawType = mvHatchDrawSquare

'Loads a color spectrum for the foreground color

'Set the Pattern and Mode for all classes
HatchMap.FillPatAndMode.Pattern = "Gravel"
HatchMap.FillPatAndMode.Transparent = True

'Set the data limits to use Global Data
HatchMap.GlobalData = True

'Returns the PID column of the worksheet.
Debug.Print "PIDCol = "+HatchMap.PIDCol

'Sets the PID column of the worksheet to Column B.
'HatchMap.PIDCol = 2

'Returns the state of the User Limits checkbox
Debug.Print "UserLimits = "+HatchMap.UserLimits

'Returns the User Limits max value
Debug.Print "UserLimitMaxVal = "+HatchMap.UserLimitMaxVal

'Returns the User Limits min value
Debug.Print "UserLimitMinVal = "+HatchMap.UserLimitMinVal

'Sets the variable coloumn of the worksheet to Column H
HatchMap.VarCol= 6

'Interpolate all class fills between first and last color

'Adds a class color to the color spectrum and then interpolate all class fills
HatchMap.ClassFill(iClass:=2).ForeColor = mvColorBlue

'Set the min and max values for class 1

'Set the User Limits state and specify the Min/Max values

'Creates a legend for the map
Set Legend = HatchMap.CreateLegend(-2,6)

'Adds HatchMap information in Layer #1 to legend
HatchMap.AddLayerToLegend("Layer #1")

End Sub


Updated November 2, 2016

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Please sign in to leave a comment.