KB no longer maintained - MapViewer is a Legacy Product. Legacy Products are still supported, but no longer receive new features or updates. Many of MapViewer's features have been moved to Surfer. Please contact support@goldensoftware.com with any questions. |
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:
- Copy the script below, or click here to download the BAS file: percent_of_area_inside_buffer.BAS.
- In a Windows Explorer window, navigate to C:\Program Files\Golden Software\MapViewer 8\Scripter.
- Double click on Scripter.exe to launch Scripter.
- Press Ctrl+A to select all of the existing lines then press Delete.
- 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.
- Click Script | Run to run the script.
*********
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'percent_of_area_inside_buffer.bas ' 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 February 14, 2017
Comments
0 comments
Please sign in to leave a comment.