Skip to content

Using the console

Zoltan Siki edited this page Jul 1, 2020 · 16 revisions

The new Tcl console in version 3.1 enables users to make calculations using the functions of GeoEasy. The documentation of tcl procs can be found here: http://www.digikom.hu/tcldoc

Open a console window from the Window menu of the main window. Input your Tcl command into the entry widget at the top of the console window. In the main part of the console the previous commands are visible. The command have to be finished by Enter key. The result of your command is visible in the calculation results window.

Let's start with basic calculation. Input in the top line of the console window:

expr 4 + 5
expr 100 * sin(5.0 / 200000.0)

In the Calculation results window you should get

9
0.0024999999997395834

The functions defined in the GeoEasy source code can be used. The documentation of the functions are here. Input in the top line of the console window to change angle from radian to DMS:

DMS 0.13245

The result is:

7-35-20

Or decimal degrees to DMS:

DMS [D2Rad 43.675]

43-40-30

To calculate the intersection of two lines given by a point and a bearing.

Intersec 10 20 50 17 [DMS2Rad 45-10-22] [DMS2Rad 321-45-32]

The intersection point will be in the calculation results window:

31.10400420201746 40.977106498665322 43-40-30 You can even load a tcl script using the File/Load tcl file from the menu of the console window to execute a pre-written scripts or you can specify one or more tcl scripts in the command line to execute after initialization of GeoEasy.

If you would like to use more commands in the same context (e.g. using global variables) enter your commands separated by semicolon. For example to list the loaded geo datasets in the Calculation results window:

global geoLoaded; GeoLog1 $geoLoaded

You can extend the functionality of GeoEasy writing and loading tcl functions (proc) which are executed when you call them. Let's try to write a script to swap horizontal coordinates in a loaded dataset. As the script will be longer, it will be stored in file swapxy.tcl.

#
# GeoEasy utility to swap horizontal coordinates
proc SwapXY {dataset} {
    global geoChanged
    upvar #0 ${dataset}_coo coo

    if {! [info exists coo]} {
        GeoLog "Dataset not loaded $dataset"
        return
    }
    foreach pn [array names coo] {
        upvar #0 ${dataset}_coo($pn) coo_rec
        set prelim 0
        set east [GetVal 38 $coo_rec]
        set north [GetVal 37 $coo_rec]
        if {$east == ""} {
            # try preliminary coords
            set east [GetVal 138 $coo_rec]
            set north [GetVal 137 $coo_rec]
            set prelim 1
        }
        if {$east != "" && $north != ""} {
            set coo_rec [DelVal {38 138} $coo_rec]
            set coo_rec [DelVal {37 137} $coo_rec]
            lappend coo_rec [list [expr {$prelim * 100 + 38}] $north]
            lappend coo_rec [list [expr {$prelim * 100 + 37}] $east]
            set geoChanged($dataset) 1
        }
    }
}

After saving the script above into swapxy.tcl, please load test1 data set from demodata folder. Open the console window, load the script (File/Load tclscript from the menu) and enter the following command:

SwapXY test1

You have to open or refresh coordinate window to see the effect of the script.

Sample scripts will be available in the procs directory on GitHub.