Monday, February 25, 2008

How to set Console Environment in JGrass

To satisfy Moovidas requirements... :-)
here are some screenshots, and much more, about the JGrass commands in the JGrass Console environment.

Console preferences for JGrass are in the Window - Preferences menu. The tag to select is Console, the first pannel to set is about the general preferences the one below:



The second step is to set the compiler settings that should be already pre-compiled in the installation activity.



The rt folder is the folder in which JGrass looks for the commands, if the user wants to use other commands in other folders, just specify the name of the new folder or add the new commands to the files in the rt folder.

The third panel is about the preferences for the GRASS natives commands. For unix like systems (linux and mac) the preferences are setted in this way:
1. GRASS location, mapset and database specification
2. GRASS environment and library folder (to have the GISBASE name just enter GRASS and type which r.sun
3. user information



Last panel is to set the syntax colouring, not so useful for now.

To accept the changes just press Apply and then OK to close the Preferences window.

After setting the Console preferences you have to open the console editor by clicking the correspondet icon in the tools bar.

The new JGrass editor looks like in the picture below.



Here first click with the right mouse button and set the runtime preferences with the name of the location and mapset you want to use for elaborations.



Select the options and then close the window to accept the changes.



In the JGrass console editor the commands are mainly divided in two groups:
1. JGrass commands (written in Java and directly in JGrass)
2. GRASS natives commands (written in C for GRASS and executed from JGrass)

To execute a JGrass command use the word jgrass before the command, for GRASS use the grass word before the linestring of the GRASS command.

Every JGrass command has an help string to show the main targets. This string can be visualized by writing the --help string after the command, just like in GRASS environment. For GRASS commands the syntax and the options are the same as in GRASS.

To run a script or a part of it, select from the right mouse button the option "run name_of_the_console_editor_file". If you want to execute all the script just select the run option, if you want to run only a part of the script, before running, select the string you need to execute and the run with the right mouse button.

For example to know how you can use the h.pitfiller command:

jgrass h.pitfiller --help

The result is written in the console window below the console editor window as shown in picture.



There is not at present a good command line execution and so you can not see the complete list of the JGrass and GRASS commands. To see them you can have a look at the files in the rt folder of the console plugin in the JGrass installation folder.

The usage sentence contains:
  1. the name of the command
  2. the inputs of the commands that can be
    • igrass: input in the GRASS - JGrass standard format
    • igrassascii: input in the grassascii format in the related folder of the JGrass location
    • iesrigrid: input in the esri grid format in the related folder of the JGrass location
    • ifluidturtle: input in the fluidturtle format in the related folder of the JGrass location
    • ishapefile: vector input shapefile
  3. the outputs of the commands that can be
    • ograss: output in the GRASS - JGrass standard format
    • ograssascii: output in the grassascii format in the related folder of the JGrass location
    • oesrigrid: output in the esri grid format in the related folder of the JGrass location
    • ofluidturtle: output in the fluidturtle format in the related folder of the JGrass location
    • oshapefile: vector output shapefile
    • otable: writes an output file containing a table, used in commands like r.cb
    • ocolor: writes the color table file of the related raster map
    • ocats: writes the category file of the related raster map

For every input and output of the JGrass command it is possible to set the proper format. Standard format (JGrass-GRASS location) is the i/ograss format for raster maps and i/oshapefile for vector ones.

When a command has more than one input (or output) the syntax requires to define what type of input (r output) it is. So in command like r.netnumbering you can obtain:

jgrass h.netnumbering --help

**********************************************************************************************

untitled.jgrass - 1 model/s compiled, total compilation time: 26 ms

-------------------------------------------------------------------------------
Beanshell, Version 2.0b4, Copyright (C) Pat Niemeyer
------------------------------ Running model... -------------------------------
Usage:
h.netnumbering --igrass-flow flow --igrass-net net --ograss-netnumber netnumber --ograss-basin basin

Total run time: 51 ms


**********************************************************************************************

Where the --igrass-flow means that the input is a flow map in the grass format, and so on...

No comments: