How can I create and edit a flow map in MapViewer via automation?

This article contains a sample script for creating a flow map and editing the methods and properties of the flow map.

To run this script:

  1. Copy the script below, or click here to download the BAS file: Create FlowMap.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_Flow_Map.BAS
' Copyright (C) Golden Software Inc. 1992-2015
' This sample demonstrates how to create a flow map and change many of the properties

Sub Main
	'Declare the variable that will reference the application
	Dim mvapp As Object

	'Creates an instance of the MapViewer Application object
	' and assigns it to the variable named "mvapp"
	Set mvapp = CreateObject("MapViewer.Application")

	'Make MapViewer visible
	mvapp.Visible = True

	'Declare Plot and FlowMap as Object
	Dim Plot, FlowMap As Object

	'Creates a new plot window
	Set Plot = mvapp.Documents.Add(mvDocPlot)

	'Create a flow map using connect centroid method
	Set FlowMap = Plot.CreateFlowMap(BoundaryFileName:=mvapp.ApplicationFolder & _
		"\Samples\us50alb.gsb", DataFileName:=mvapp.ApplicationFolder & _ 
		"\Samples\flow.dat", FlowMethod:=mvFlowConnectEnds, PIDCol:=1, _
		EPIDCol:=2, VarCol:=3 )

	'Returns the arrow scale
	Debug.Print "The arrow scale size is ";FlowMap.ArrowScale

	'Change the arrow scale
	FlowMap.ArrowScale = 3

	'Returns the bulge value
	Debug.Print "The bulge value for the curve is"; FlowMap.Bulge

	'Change the bulge value
	FlowMap.Bulge = 0.6

	'Return the arrow style for the line
	Debug.Print "The ending arrow head is ";FlowMap.EndArrow
	Debug.Print "       1 = No arrow, 2 = Simple, 3 = Filled, 4 = Triangle, 5 = 2 Stick"

	'Change the end arrow style
	FlowMap.EndArrow = mvASTriangle

	'Return the end offset value
	Debug.Print "The end offset for the flow lines is ";FlowMap.EndOffset

	'Change the end offset value
	FlowMap.EndOffset = 0.05

	'Return the column used for the PID
	Debug.Print "The PID column for the end of the line is column ";FlowMap.EndPIDCol

	'Change the column used for the end of line PID
	FlowMap.EndPIDCol = 2

	'Return the method used To create the flow lines
	Debug.Print "The method used to create the flow lines is: ";FlowMap.FlowMethod
	Debug.Print "    1 = Overlay Curves, 2 = Connect Centroids"

	'Change the method used to create the flow lines
'	FlowMap.FlowMethod = mvFlowOverlayCurve

	'Return the flow shape
	Debug.Print "The flow shape is: ";FlowMap.FlowShape
	Debug.Print "     1 = Straight, 2 = Bent, 3 =S shaped"

	'change the flow shape
	FlowMap.FlowShape = mvFlowShapeStraight
	Wait 2
	FlowMap.FlowShape = mvFlowShapeBent
	Wait 2
	FlowMap.FlowShape = mvFlowShapeSFlow
	Wait 2

	'Return whether global data are used
	Debug.Print "Global data are used "; FlowMap.GlobalData

	'Set data limits to use globabl data
	FlowMap.GlobalData = True

	'Change the line properties for the flow lines
	With FlowMap.Line
		.Color = mvColorRed
		.Style = "Dash Dot"
	End With

	'Return the maximum flow line width
	Debug.Print "The maximum flow line width is ";FlowMap.MaxWidth

	'Change the maximum flow width
	FlowMap.MaxWidth = 0.14

	'Return the minimum flow line width
	Debug.Print "The minimum flow line width is ";FlowMap.MinWidth

	'Change the minimum flow width
	FlowMap.MinWidth = 0.02

	'Return the column for the starting PID
	Debug.Print "The PID is located in column ";FlowMap.PIDCol

	'Change the PID column
	FlowMap.PIDCol = 1

	'Return the arrow style for the beginning of the flow line
	Debug.Print "The starting arrow head is ";FlowMap.StartArrow
	Debug.Print "       1 = No arrow, 2 = Simple, 3 = Filled, 4 = Triangle, 5 = 2 Stick"

	'Change the arrow type for the beginning of the flow line
	FlowMap.StartArrow = mvASSimple

	'Return whether the absolute value is used
	Debug.Print "The absolute value is used for flow lines "; FlowMap.UseAbsoluteValue

	'Use the absolute value of negative numbers
	FlowMap.UseAbsoluteValue = True

	'Set the user defined limits
	FlowMap.SetUserLimits (True, 0, 50)

	'Return the user defined values for the min/max flow values
	Debug.Print "User defined values are used for FlowMaps ";FlowMap.UserLimits

	'Return the user defined maximum value
	Debug.Print "The maximum value is ";FlowMap.UserLimitMaxVal

	'Return the user defined minimim value
	Debug.Print "The minimum value is ";FlowMap.UserLimitMinVal

	'Return the column that the variable is located
	Debug.Print "The variable is in column ";FlowMap.VarCol

	'Change the column that the variable is located
	FlowMap.VarCol = 3

End Sub


Updated September 24, 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.