I need to create lines from an airport to numerous destination locations. The destinations change often, so drawing them manually becomes tedious. I want to create a script that will draw them automatically. Does anyone know how to do this?

I've written a number of scripts for ArcGIS 10 using arcpy, but nothing for 9.3. If you could point me in the right direction that would be great.

  • 1
    so the airport is in one feature class, and the destination in another feature class? You wish to join all airports to all destinations?
    – gotchula
    Commented Jan 20, 2011 at 5:04

2 Answers 2


In Arc, they call these "Desire Lines" or "Spider Diagrams". There are a number of ArcGIS Toolbox tools that have already been created to to just this task:

Take a look at the ArcGIS Resource center for Geoprocessing under Model and Script Tool Gallery:

Or ArcScripts:

Or if you have the Business Analyst Extension:

Or SoCalGIS python script:

Outside of the Arc platform, you can also:

  • Thanks for the wonderful answer! This is exactly what I needed.
    – Tanner
    Commented Oct 18, 2011 at 23:48
  • 1
    @Tanner- Great! For future readers sake, which option did you find met your needs the best, and why? Commented Oct 19, 2011 at 14:28

It's not python but how is this? Select a point layer in the table of contents (TOC) then on that layer select the origin point feature. The script will draw a lines on another (Target) feature class from the selected point to all other points in the same feature class.

Public Sub Distances

    Dim i As Long

    Dim pFeature As IFeature
    Dim pNewFeature As IFeature
    Dim pMxDoc As IMxDocument
    Dim pPoint As IPoint
    Dim pFeatureClass As IFeatureClass
    Dim pLayer As ILayer
    Dim pFeatureLayer As IFeatureLayer
    Dim pFeatureCursor As IFeatureCursor
    Dim pFeatureSelection As IFeatureSelection
    Dim pMap As IMap
    Dim pEnumFeature As IEnumFeature
    Dim pEnumFeatureSetup As IEnumFeatureSetup
    Dim OriginFeature As IFeature
    Dim OriginPoint As IPoint
    Dim pPolyline As IPolyline5
    Dim pSelectionSet As ISelectionSet
    Dim pSp As ISpatialReference

    Dim x As Integer, d As Long

    Set pMxDoc = ThisDocument

    Set pLayer = pMxDoc.SelectedLayer
    If pLayer Is Nothing Then
        MsgBox "Select a layer in the TOC!": exit sub
    End If

    Set pFeatureLayer = pLayer
    Set pFeatureClass = pFeatureLayer.FeatureClass

    If pFeatureLayer.FeatureClass.ShapeType <> esriGeometryPoint Then
        MsgBox "Target layer must be a point geometry feature class."
        GoTo ep
    End If

    Set pMap = pMxDoc.FocusMap
    If pMap.SelectionCount = 0 Then
        MsgBox "You must select a point feature for origin."
        GoTo ep
    End If

    If pMap.SelectionCount > 1 Then
        MsgBox "Select only one feature for origin" & Chr(13) & "Currently " & pMap.SelectionCount & " feature(s) are selected."
        GoTo ep
    End If

    Set pEnumFeature = pMap.FeatureSelection
    Set pEnumFeatureSetup = pEnumFeature 
    pEnumFeatureSetup.AllFields = True

    Set OriginFeature = pEnumFeature.Next

    If OriginFeature.Shape.GeometryType <> esriGeometryPoint Then
        MsgBox "Selected origin must be a point geomtry feature."
        GoTo ep
    End If

    Set OriginPoint = OriginFeature.ShapeCopy 

    Dim originCS As String, targetCS As String

    originCS = Trim$(OriginFeature.Shape.SpatialReference.Name)

    GetSpatialReference pFeatureLayer, pSp   
    targetCS = Trim$(pSp.Name)

    If originCS <> targetCS Then
        MsgBox "Origin must have the same coordinate system as target." & Chr(13) & _
            "Origin CS: " & originCS & Chr(13) & "Target CS: " & targetCS, vbInformation
        GoTo ep
    End If

    If Trim$(Mid(targetCS, 1, 12)) <> "NAD_1983_UTM" Then
        If MsgBox("The coordinate system is not NAD 83 UTM!" & Chr(13) & _
            "Distances may not be accurate. Continue Anyway?", vbQuestion + vbYesNo) = vbNo Then
            GoTo ep
        End If
    End If

    x = pFeatureClass.FindField("DISTANCE")
    If x = -1 Then
        MsgBox "DISTANCE field does not exist!": exit sub
    End If

    Set pFeatureSelection = pFeatureLayer

    Set pSelectionSet = pFeatureSelection.SelectionSet
    d = pSelectionSet.count
    'retreive selection into a cursor
    If d > 0 Then
        pSelectionSet.Search Nothing, False, pFeatureCursor  
        d = pFeatureLayer.FeatureClass.FeatureCount(Nothing)
        Set pFeatureCursor = pFeatureClass.Update(Nothing, False) 
    End If

    Set pFeature = pFeatureCursor.NextFeature

    Do While Not pFeature Is Nothing

        Application.StatusBar.message(0) = Str(i) & " of " & Str(d) & " completed"
        i = i + 1
        Set pPoint = pFeature.Shape
        Set pPolyline = New Polyline
        pPolyline.FromPoint = OriginPoint
        pPolyline.ToPoint = pPoint

        If x <> -1 Then pFeature.Value(x) = pPolyline.Length

        If d > 0 Then
            pFeatureCursor.UpdateFeature pFeature 
        End If

        Set pFeature = pFeatureCursor.NextFeature

    MsgBox "Done!"

End Sub

Private Sub GetSpatialReference(pFeatureLayer As IFeatureLayer, pSR As ISpatialReference)

       Dim pGeoLayer As IGeoDataset

       Set pGeoLayer = pFeatureLayer
       Set pSR = pGeoLayer.SpatialReference

End Sub
  • Thanks for the very detailed answer! Although it's not python, it should suit my needs. I have a question though. How do I run this in 9.3? I tried pasting the code into the command line window but every line of the code gives me "ERROR 000604: Method <value> not found." The description of the error is "The tool or environment used was not found in the list of available tools or environments". I've never ran any scripts in 9.3, or VBscript in general. Thanks again.
    – Tanner
    Commented Sep 12, 2010 at 21:46
  • 1
    This is a VBA procedure. Create a UI button control and drag it to a toolbar. While still in "Customize" mode, right click on the new button control and select "View Source". Once VBA editor opens paste the code there. Then you just need to click the button to run the script. Commented Sep 13, 2010 at 1:30
  • I created a UI button and pasted the code into it after going to "View Source". It gets caught up at GoTo ep right after MsgBox "Target layer must be a point geometry feature class." It says "Compile Error: Label not defined." Is a window supposed to pop up if there's an error? Also, I'm unsure whether I'm using the command correctly. Am I supposed to just select a point feature class in the TOC, and then select a point on that feature class, then hit the button? Thanks
    – Tanner
    Commented Sep 14, 2010 at 1:28
  • replace "goto ep" with "exit sub" (Do not include quotes) ep is my own exiting procedure that i have at the end of each function and procedure. I must have forgotten to remove all references to it. Under the debug menu, run "Compile" to make sure all is good. Commented Sep 14, 2010 at 3:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.