How can I change the projection for my MapViewer map via automation?

This article contains a sample script for changing the projection type.

To run this script:

  1. Copy the script below, or click here to download the BAS file: projection.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.


' Projection.BAS
' '
' This sample demonstrates how to change projection type.

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

   'Makes the application main window visible
   MapViewerApp.Visible = True

   'Assigns the location of the samples folder to the variable "InPath"
   InPath$ = MapViewerApp.ModuleFolder + "samples\"

   'Creates a map document object, and assigns it to the variable named "doc"
   Set doc = MapViewerApp.Documents.Add(DocType:=mvDocPlot)

   'Creates a base map
   doc.CreateBaseMap(InPath$ + "us50ll.gsb")

   'Creates a copy of the projection object, and assigns the projection object copy
   'to the variable named "Projection"
   Set Projection = doc.CopyDocProjection

   'Changes the projection type and parameters of the projection object copy
   Projection.ProjectionType = mvProjAlbersEqualAreaConic
   Projection.CentralLon = -95
   Projection.CentralLat = 21
   Projection.LatOf1stPt = 29
   Projection.LatOf2ndPt = 45

   'Assigns the modified projection object copy to the document.
   'Now the document has the new projection type.

   'Must delete the projection copy after it's done.

End Sub


Updated February 14, 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.