Follow

How can I perform radius analysis in MapViewer via automation?

This article contains a sample script for determining the total value of a variable that is within a buffer zone.

To run this script:

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

*********

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' radiusanalysis.bas
' Copyright (C) Golden Software Inc. 1992-2015
'
' This sample demonstrates how to determine the total variable value that falls within a buffer
' Change the path and file names in lines 20-23 and the units, point location, and buffer width in lines 29-41
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub Main
	'Initializes and opens MapViewer
	 Dim mvapp, Plot, HatchMap, wks, WksRange As Object
	 Dim shapename As String
	 Dim datavalue, varvalue As Double
	 Set mvapp = CreateObject("MapViewer.Application")
	 mvapp.Visible = True
	 Set Plot = mvapp.Documents.Add(mvDocPlot)

	 'Sets the file path
	 InPath$=mvapp.ApplicationFolder

	'Creates the hatch map
	 Set HatchMap = Plot.CreateHatchMap(InPath$ + "\Samples\co2010.gsb",InPath$ + "\Samples\co2010.dat",1,7)

	'Sets the linked data to the variable wks
	 Set wks = Plot.Layers(1).LinkedWorksheetDoc

	'Add the point to the map (position is in X,Y in page units)
	 Set Point = Plot.Layers.ActiveLayer.Shapes.AddPoint(5.625, 5.625)

	'Change the surface distance units to miles
	 Plot.DistanceUnits = mvDistUnitMiles

	'Change the surface area units to square miles
	 Plot.AreaUnits = mvAreaUnitMiles

	'Select the point
	 Point.Select

	'Create 30 mile buffer around point
	 Plot.Layers.ActiveLayer.Shapes.AutoBufferZone(BufferWidth:=30, AroundArea:=False, AroundPoint:=True, AroundCurve:=False)

	'Deselect the point
	 Point.Deselect

	 varvalue=0
	 Set numberofareas=Plot.Layers.ActiveLayer.Shapes.Count

	 'Save the buffer area to use later (last area created)
     Set Buffer = Plot.Layers.ActiveLayer.Shapes.Item(numberofareas)

	 For i =1 To numberofareas-3 'item 1 will be the buffer zone and item 2 will be the point the buffer was created from
ProcessBoundary:
        'Select the buffer and the boundary to determine if they intersect
        Plot.Layers.ActiveLayer.Selection.DeselectAll
        Buffer.Select
        Set AreaOfInterest = Plot.Layers.ActiveLayer.Shapes.Item(i)
        AreaOfInterest.Select

        'Get the current count of objects
        Set objCount = Plot.Layers.ActiveLayer.Shapes.Count

         'Intersect the areas
         Plot.Layers.ActiveLayer.Selection.InterSectAreas(KeepOriginalAreas:=True)

         'If a new area was created for the intersection, process the area of interest, otherwise get the next boundary
        If Plot.Layers.ActiveLayer.Shapes.Count <> objCount + 1 Then
            i=i+1
            GoTo ProcessBoundary
        End If

        Debug.Print "-----Processing Area " + AreaOfInterest.PIDName + "-----"

		'Get area for county
		 CountyArea = Plot.Layers.ActiveLayer.Shapes.Item(i).Area

		'Get the area of the intersection with the buffer (new/last object created)
         CountyAreaInBuffer = Plot.Layers.ActiveLayer.Shapes.Item(Plot.Layers.ActiveLayer.Shapes.Count).Area
         Debug.Print "County Area Inside Buffer = " + Str(Round(CountyAreaInBuffer,3)) + " mi^2"

		'Get percentage
		Percent = CountyAreaInBuffer/CountyArea
         Debug.Print "Percent of county area inside buffer area = "+Str(Round((CountyAreaInBuffer/CountyArea)*100,3))+"%"

		'Gets the PID of the current area
		 shapename = Plot.Layers.ActiveLayer.Shapes.Item(i).PIDName

		 'Finds shapename in col A
		 Set WksRange = wks.Columns(Col1:=1, Col2:=1)
		 Set Selection = WksRange.Find(TargetStr:=shapename, After:=Nothing, Method:=wksFindPhrase, MatchCase:=True)

		 'Gets data value for shapename from col G
		  datavalue=wks.Cells(Row:=Selection.Row,Col:=HatchMap.VarCol)

		 'Multiplies the percentage by the value of that area's data variable and then saves to be added to the others later
		 varvalue=varvalue+(Percent*datavalue)

	Next i
	Debug.Print "Total variable value of the buffer zone = "+Str(varvalue)
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.