ArcMap .CAL Script: Service Area Count From Intersecting Polygons

Written by Bert Granberg,

BACKGROUND

A service area polygon is a polygon in which a particular service or service level is the same and whose external boundaries demarcates a change from one service situation to another.

This script was written for work with cell phone towers and sectors. A sector is the area served by a particular cell phone antenna and is defined by the tower location, height on antenna and the left and right directional azimuth of antenna. The goal was to calculate the level of service for all locations served by an array of cell phone
antennae in a given area.

To accomplish this, sector polygons were created and then these sector polygons were planarized (all overlaps were removed) to form service areas for the cell phone network. The goal of the script is to count the number of cell phone sectors that overlap a particular service area.

  • Note: To create the planar service area polygons you'll need before running the script, you'll need an ArcGIS ArcEditor or ArcINFO level license. I like to do this in arccatalog by putting the sector polygons into a geodatabase feature dataset and right clicking in the feature database and selecting New --> Polygon Feature Class from Lines.

This .cal script is for calculating the number of "customer" polygons (in our case these are the cell phone antenna sectors) in a given service area polygon. It produces a numeric count for the number of customer features in the specified customer layer that intersect the midpoint of the given polygon (see example depiction below).

 

TO USE: 

  • open the attribute for the planar service area polygons, select the SHAPE field
  • then hit CTRL + SHIFT + F to open the field calculator.
  • In the field calculator, check the Advanced Option and paste this script in the Pre-Logic VBS Scipt Code text box.
  • Make Sure that the layer index number for the customer feature class is set. This item can be found by searching the code below for 'SET THIS.
  • Type the word Count into the bottom text box and hit OK.

'.CAL CODE

'** Declare variable to store population sum in
Dim count As Long

'** Get pointer variables to current arcmap project
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap

'** Get pointer variable to the polygon layer for which you wish
'** to count the # of intersects from
Dim pCountLayer As IFeatureLayer

'SET THIS...At the moment the "CountLayer"
'must be FIRST in ArcMap TOC

Set pCountLayer = pMap.Layer(0)

'** Set up a spatial filter and feature cursor to select
'** all polygons that interest the current layer's midpoint
'** and iterate through results to produce a count

Dim pSpatialFilter As ISpatialFilter
Dim pFCursor As IFeatureCursor
Dim pFeature As IFeature
Dim pPolygon As IPolygon
Dim pMidPoint as IPoint
Dim pArea as IArea
Set pArea = [Shape]
Set pMidPoint = pArea.labelpoint

Set pSpatialFilter = New SpatialFilter
Set pSpatialFilter.Geometry = pmidpoint
pSpatialFilter.SpatialRel = esriSpatialRelIntersects

Set pFCursor = pCountLayer.Search(pSpatialFilter, True)
Set pFeature = pFCursor.NextFeature

'** iterate through selected polygons to count for each
'** polygon to be analyzed
Count = 0
Do Until pFeature Is Nothing
  Count = Count + 1
  Set pFeature = pFCursor.NextFeature
Loop


Users' Comments  
 

No comment posted

Add your comment

19, Jan. 2009
Last Updated ( 02, Jul. 2009 )