Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
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 Jan 20 '11 at 5:04
add comment

2 Answers 2

up vote 5 down vote accepted

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:

Outside of the Arc platform, you can also:

share|improve this answer
    
Thanks for the wonderful answer! This is exactly what I needed. –  Tanner Oct 18 '11 at 23:48
1  
@Tanner- Great! For future readers sake, which option did you find met your needs the best, and why? –  RyanDalton Oct 19 '11 at 14:28
add comment

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  
    Else
        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

        'UPDATE FEATURE
        If d > 0 Then
            pFeature.Store 
        Else
            pFeatureCursor.UpdateFeature pFeature 
        End If

        Set pFeature = pFeatureCursor.NextFeature
    Loop

    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
share|improve this answer
    
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 Sep 12 '10 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. –  Jakub Sep 13 '10 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 Sep 14 '10 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. –  Jakub Sep 14 '10 at 3:03
add comment

protected by Community May 31 '12 at 7:50

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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