English

How To: Measure the distance of a polyline in three dimensions

Summary

The measure tool only measures polylines on a plane. You can measure a polyline in three dimensions with the script provided in this document. You must have the Spatial or 3D Analyst extension loaded in order for this operation to work properly.

Procedure

The following script only measures distances and computes elevation rise and fall for each vertex along the polyline. It is assumed that the change in elevation between vertices is a straight line. The more detailed you are in drawing the polyline, the more accurate your real-world distance will be. Use the interactive pan (right-mouse click) so that you can zoom in close and still be able to move across the theme while drawing the polyline.

  1. Open a new script window.

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

  2. Copy the code into the new script window.

    Code:
    '-- This script uses an active grid theme and a polyline graphic in your view.
    '-- It calculates the 3-dimensional distance of that polyline using the values of
    '-- the grid cells as a base.

    theView = av.getactivedoc
    if (theView.Is(View).Not)
    then
    MsgBox.Info
    ("The active window must be the View",
    "Please try again")
    exit
    end
    theDisplay = theView.GetDisplay
    theDistUnits = theDisplay.GetDistanceUnits
    theMapUnits = theDisplay.GetUnits
    if (theDistUnits <> theMapUnits)
    then
    MsgBox.Info
    ("The View's Distance Units and Map Units"+NL+
    "must be the same. Go to View Properties"+NL+
    "and check it out.","Please try again")
    exit
    end
    theGTheme = theView.GetActiveThemes.Get(0)
    if (theGTheme.Is(GTheme).Not)
    then
    MsgBox.Info
    ("The active theme must be a GRID theme",
    "Please try again")
    exit
    end
    theSelGraphicList = theView.GetGraphics.GetSelected
    theNumSelGraphics = theSelGraphicList.Count
    if (theNumSelGraphics < 1)
    then
    MsgBox.Info
    ("You must first have a graphic selected.",
    "Please try again")
    exit
    end
    if (theNumSelGraphics > 1)
    then
    MsgBox.Info
    ("You must have only ONE graphic selected.",
    "Please try again")
    exit
    end
    thePolyline = theSelGraphicList.Get(0).GetShape
    if (thePolyline.Is(Polyline).Not)
    then
    MsgBox.Info
    ("The graphic must be a single Polyline.",
    "Please try again")
    exit
    end
    thePointList = thePolyline.AsList.get(0)

    '-- Initialize the counters

    measureCount = (thePointList.Count) - 2
    trailLength = 0
    birdLength = 0
    startMark = 0
    endMark = 1

    '-- Calculate the distances

    theGrid = theGTheme.GetGrid
    for each i in 0..measureCount
    av.ShowMsg("Calculating Trail Distance...")
    av.SetStatus((i/measureCount) * 100)
    p1 = thePointList.Get(startMark)
    p2 = thePointList.Get(endMark)
    v1 = theGrid.CellValue(p1,(Prj.MakeNull))
    v2 = theGrid.CellValue(p2,(Prj.MakeNull))
    len = p1.distance(p2)
    rise = (v1 - v2).Abs
    hypo = ((len^2) + (rise^2)).sqrt
    trailLength = trailLength + hypo
    birdLength = birdLength + len
    startMark = startMark + 1
    endMark = endMark + 1
    end

    '-- Display the results

    birdLength = birdLength.SetFormat("d.d").AsString
    trailLength = trailLength.SetFormat("d.d").AsString
    av.ClearMsg
    av.ClearStatus
    if (theDistUnits = #UNITS_LINEAR_FEET)
    then theUnits = " feet."
    elseif (theDistUnits = #UNITS_LINEAR_METERS)
    then theUnits = " meters."
    else theUnits = " map units."
    end
    MsgBox.Info("This is the distance of your trail:"
    +NL++NL+"2-dim distance:"++birdLength+theUnits+NL+
    "3-dim distance:"++trailLength+theUnits,
    "As the crow flies vs. As the person walks")

  3. Compile the script by clicking the compile button.
    [O-Image] Script compile button
  4. Ensure that the View's Map Units and Distance Units are correct and the same.
  5. Make the grid theme the only active theme in the View.
  6. Create and only select one polyline graphic at a time.
  7. Make the script window active.
  8. Run the script by clicking the run button.
    [O-Image] Run compiled script button