English

How To: Add direction arrows to arcs using Avenue

Summary

The script in this article shows how to add directional arrow symbols to selected features of a polyline theme.

Procedure

This example requires a view, selected features of a polyline theme, Fnode and Tnode fields in the attribute table of the Polyline theme.

  1. Open a new script window.

    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.


  2. Copy the following code into the new window:

    Code:
    '-- Name: AVArrows.ave
    '
    '-- This script creates a line theme of arrows showing arc
    '-- direction of another line theme.
    '-- This script facilitates editing of shapefiles and
    '-- attributes when line direction is important, such as
    '-- editing the address ranges of a street file for geocoding.
    '
    '-- Before running it, make a polyline theme active,
    '-- select some of the lines (with a selection tool).
    '
    '-- Self: N/A
    '-- Returns: N/A
    '-- Topics: shape, direction, arcarrows
    '-- Search Keys: shape, direction, arcarrows
    '-- Requires: companion script MakeArrow.ave

    '-- Create the output object
    out_name = FileDialog.Put( "*.shp".asfilename, "*.shp", "Output Shapefile")

    if (out_name = nil) then
    exit
    end

    arrowIDfld = Field.Make("Arrow_ID",#FIELD_SHORT,6,0)
    fields = list.Make
    Fields.Add(arrowIDfld)
    tblrecno=0

    '-- Create the new Ftab
    tbl = Ftab.MakeNew( out_name, Polyline )
    tbl.AddFields( fields )

    v = av.GetActiveDoc
    t = v.GetThemes.Get(0)
    d = v.GetDisplay

    tFTab = t.GetFTab

    '-- Find a good length for the arrow lines
    l = (d.ReturnExtent.GetWidth)/80

    tShape = tFTab.FindField("Shape")

    tGraphicSet = t.GetGraphics
    vGraphics = v.GetGraphics

    theNumSelected = tFTab.GetSelection.Count
    theCounter = 0
    av.ShowMsg("Working...")

    for each r in tFTab.GetSelection
    theCounter = theCounter + 1
    av.SetStatus((theCounter/theNumSelected) * 100)

    pntListList = (tFTab.ReturnValue(tShape,r)).AsList

    for each pntList in pntListList

    numPoints = pntList.Count

    for each i in 1..(numPoints-1)

    Fpnt = pntList.Get((i-1))
    Tpnt = pntList.Get(i)

    arrowShape = av.run("MakeArrow.ave",{Fpnt,Tpnt,(20.0).AsRadians,l})

    outputRecNum = tbl.AddRecord
    tbl.SetValue(tbl.FindField("Shape"), outputRecNum, arrowShape)
    tbl.SetValue(arrowIDfld, outputRecNum, outputRecNum)

    end
    end
    end

    av.ClearStatus
    av.ClearMsg
    theFTheme = FTheme.Make(tbl)
    v.AddTheme(theFTheme)
    theFTheme.SetVisible(true)
    MsgBox.Info("Created Arrow Theme","Done")

  3. Select Properties from the Script menu.
  4. Type AVArrows.ave for the name of the script.
  5. Click OK.
  6. Select Compile from the Script menu or click the
    [O-Image] Script compile button
    button.
  7. Open another new script window.
  8. Copy the following code into the new window:

    Code:
    '-- Name: MakeArrow.ave
    '
    '-- This script builds an arrow polyline (2 points) for displaying
    '-- the orientation of a line. It is required by AVArrows.ave.
    '
    '-- Self: {FromPoint,ToPoint,Angle,Length}
    '-- Returns: aPolyline
    '-- Topics: shape, direction, arcarrows
    '-- Search Keys: shape, direction, arcarrows
    '-- Requires: N/A

    fp = self.Get(0) '-- from point
    tp = self.Get(1) '-- to point
    theta = self.Get(2) '-- angle
    length = self.Get(3) '-- length

    x1 = tp.GetX
    y1 = tp.GetY
    x2 = fp.GetX
    y2 = fp.GetY

    xshift = length * (theta.cos)
    yshift = length * (theta.sin)
    totLength = (((y1-y2)^2)+((x1-x2)^2)).Sqrt

    '-- Point along the line
    p1 = ((1.0 - (xshift/totLength)) * x1) + ((xshift/totLength) *x2)
    p2 = ((1.0 - (xshift/totLength)) * y1) + ((xshift/totLength) *y2)

    pi = Number.GetPI

    if (x2<>x1) then
    slope = (y2-y1)/(x2-x1)
    slant = (slope/(((slope^2)+1).Sqrt)).ASin
    else
    slant = pi/2.0
    end

    a1 = p1 - (yshift * (slant.sin))
    a2 = p2 + (yshift * (slant.cos))

    b1 = p1 + (yshift * (slant.sin))
    b2 = p2 - (yshift * (slant.cos))

    lpnt = Point.Make(a1,a2)
    rpnt = Point.Make(b1,b2)

    aPolyLine = PolyLine.Make({{lpnt,tp},{tp,rpnt}})

    return(aPolyline)

  9. Select Properties from the Script menu.
  10. Type MakeArrow.ave as the name of the script.
  11. Click OK.
  12. Compile the script.
  13. Attach the AVArrows.ave script to a button on the View GUI.

    A. Compile the script.
    B. Switch to the Project window.
    C. Select Customize from the Project menu.
    D. On the Customize dialog box, click the Type dropdown arrow and click View.
    E. Select Buttons under Category.
    F. Click the New button.
    G. Double-click the Click property in the Customize dialog box.
    H. Type the name of the script in the Script Manager and click Select.
    I. Close the Customize dialog box.

    For more information, see "Customize dialog box" in ArcView Help.

  14. Click the new button.