English

How To: Make a tool return UTM coordinates on decimal degree data

Summary

The script script in this article can be attached to a tool. When you use that tool and click in a decimal degree view, the script will calculate the UTM Zone for the point you clicked, and it will return the UTM coordinates for that point.

Procedure

  1. Open a new script window.

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

  2. Copy and paste the following code into the new window:

    Code:
    '-- DD2UTM.AVE

    theView = av.Getactivedoc
    theDisplay = theView.GetDisplay
    myRect = Rect.MakeXY( -180, -90, 180, 90 )
    myUTM = Trnmerc.Make(myRect)

    p = theDisplay.ReturnUserPoint

    if (((p.GetX > 180) or (p.GetX < -180)) or
    ((p.GetY > 90) or (p.GetY < -90))) then
    MsgBox.Info("You are not on this planet","")
    return nil
    end

    '-- Determine the UTM zone base meridian that the
    '-- user clicked point falls into.
    '
    '-- The following code is not very efficient, but it tries
    '-- to be self-explanatory.
    px = p.GetX
    pxDividedBy6 = px / 6
    trimOffDecimal = pxDividedBy6.AsString.AsTokens(".").Get(0).AsNumber
    longitudeOfLeftSideOfZone = trimOffDecimal * 6
    if (px >= 0) then
    baseMeridianForUTMzone = longitudeOfLeftSideOfZone + 3
    else
    baseMeridianForUTMzone = longitudeOfLeftSideOfZone - 3
    end
    b = baseMeridianForUTMZone

    '-- Setup UTM zone projection parameters
    myUTM.SetCentralMeridian(b.setformat("d"))
    myUTM.SetFalseEasting(500000)
    myUTM.SetFalseNorthing(0)
    myUTM.SetReferenceLatitude(0)
    myUTM.SetScale(0.9996)

    myUTM.ProjectPt(p)

    '** To put he result into a modal MsgBox, uncomment this section.
    'MsgBox.Info("X is:"++p.GetX.SetFormat("d.dd").AsString+NL+
    ' "Y is:"++p.GetY.SetFormat("d.dd").AsString,
    ' "Your click converted to UTM Zone"++
    ' ((b+183)/6).AsString)
    '
    '** To simply show the results into a modeless 'av.ShowMsg'
    av.ShowMsg("X is:"++p.GetX.SetFormat("d.dd").AsString++
    " Y is:"++p.GetY.SetFormat("d.dd").AsString++
    " UTM Zone:"++((b+183)/6).AsString)

  3. Click the Compile button.
    [O-Image] Script compile button
  4. Make the Project window active.
  5. Select Customize from the Project menu.
  6. Set the Type dropdown to View on the Customize dialog box.
  7. Set the Category dropdown to Tools.
  8. Click the Tool button.
  9. Double-click the Apply property at the bottom of the Customize dialog box.
  10. Type the name of the script in the Script Manager and click Select.
  11. Close the Customize dialog box.
  12. Click the tool.
  13. Click any point in your view to return the UTM coordinates.

    Note:
    UTM is only really supported between 84 North Latitude and 80
    South Latitude.