Follow

How can I combine multiple overlapping/touching areas into a single area using MapViewer Scripter?

This article contains a sample script for creating a map and combining areas into a new “union” of the combined areas.

To run this script:

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

*********

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Union_of_Areas.BAS
' Copyright (C) Golden Software Inc. 1992-2015
'
' This sample demonstrates how to select two areas and use the Union Of Areas command to combine them
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub Main

   Set mvApp = CreateObject("MapViewer.Application")
   mvApp.Visible = True
   Dim Plot, area As Object
   Set Plot = mvApp.Documents.Add(DocType:=mvDocPlot)
   InPath$ = mvApp.ApplicationFolder + "samples\"

   'Creates a base map
   Plot.CreateBaseMap("CA2010.gsb")

   'Selects two areas (by PID) from the base map layer
   Plot.Layers(1).Shapes.SelectByPID("06093")
   Plot.Layers(1).Shapes.SelectByPID("06049")

   'Uses the Union Of Areas command to combine the areas
   Plot.Layers(1).Selection.UnionOfAreas(KeepOriginalAreas:=False, KeepInnerareas:=True)

   'Renames the new area, 'area'
   Set area = Plot.Layers(1).Selection.Item(1)

   'Fills the area with a green crosshatch fill pattern
   area.Fill.Pattern = "Crosshatch"
   area.Fill.ForeColor = mvColorGreen

   'Gives the area a PID of 'Zone 1'
   area.PIDName="Zone 1"

End Sub

 

Updated November 2, 2016

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

0 Comments

Please sign in to leave a comment.