Follow

How can I calculate the percentage of a buffer that's inside of a selected boundary using MapViewer automation?

This article contains a sample script for creating an auto buffer zone and calculating the area of the buffer inside a selected base map boundary.

To run this script:

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

*********

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'percent_of_area_inside_buffer.bas
' Copyright (C) Golden Software Inc. 1992-2015
'
' This sample demonstrates how to determine the percent of an area that falls within a buffer
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub Main
	'Initializes and opens MapViewer
	 Dim mvapp, Plot, BaseMap As Object
	 Set mvapp = CreateObject("MapViewer.Application")
	 mvapp.Visible = True
	 Set Plot = mvapp.Documents.Add(mvDocPlot)

	'Creates the base map
	 Set BaseMap = Plot.CreateBaseMap(mvapp.ApplicationFolder + "\Samples\co2010.gsb")

	'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

	'The buffer is already selected, so select the area by PID (FIPS code in this example)
	 Plot.Layers.ActiveLayer.Shapes.SelectByPID(PIDName:= "08013",Deselect:=False, Accumulative:= True)

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

	'Get area for county
	 CountyArea = Plot.Layers.ActiveLayer.Shapes.Item("08013").Area
	 Debug.Print "County Area = "+Str(CountyArea)+" mi^2"

	'Get area for buffer
	 BufferArea = Plot.Layers.ActiveLayer.Shapes.Item(Plot.Layers.ActiveLayer.Shapes.Count).Area
	 Debug.Print "Buffer Area ="+Str(BufferArea)+" mi^2"

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

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.