How can I create a choropleth (hatch) map and sort the objects by data value in MapViewer via automation?

This article contains a sample script for creating a choropleth (hatch) map and sorting the objects in the object manager by their linked data values.

To run this script:

  1. Copy the script below, or click here to download the BAS file: Create_Hatch_Map_and_Sort.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_and_Sort.bas
' Copyright (C) Golden Software Inc. 1992-2015
' This script creates a hatch map and then sorts the objects
' by their linked data values.
' This script requires MapViewer 6 or later.

Sub Main
  Dim mvApp, plot, hatch As Object
  Dim path As String

  ' Start MapViewer and create a pointer to the application object
  Set mvApp = CreateObject("MapViewer.Application")
  ' Make the application visible
  mvApp.Visible = True
  ' Create a plot document
  Set plot = mvApp.Documents.Add(DocType:=mvDocPlot)

  ' Set the path variable to point to the MapViewer samples folder
  path = mvApp.ApplicationFolder + "samples\"

  ' Create a hatch map of the population in Alabama
  ' Col A contains the PID
  ' Col G contains the population
  Set hatch = plot.CreateHatchMap( BoundaryFileName := path + "al2010.gsb", _
  	DataFileName := path + "al2010.dat", PIDCol := 1, VarCol := 7 )

  ' Sort by population
  plot.ActiveLayer.SortObjects( Type := mvSortByLinkedData, Ascending := True, _
    IgnoreCase := True, DataCol := 7, LabelInFirstRow := True )

End Sub


Updated August 20, 2018

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


Please sign in to leave a comment.