Friday, March 28, 2008

How to set console environment in JGrass (Update1)

Following JGrass development some of you asked to me to update the post regarding the GRASS settings of the console environment in JGrass.
So from the last post in this field the options are less and the preferences are summarized in the following panel, as shown in the picture below.



Just fill in the blank of the main options if they are not set by default:
  1. MAPSET: the path of the mapset on which to work
  2. GRASS: the path to the GISBASE
All the other preferences are optional.

NOTE: The GISBASE is the folder in which there is the GRASS installation and it is different from the operating system and the installation type the user has done. To better simplify the things this is the folder in which there are the two main GRASS installation folders bin and lib.
This is valid in case of the user has a valid GRASS installation, and mainly for linux and mac users. For windows users there is the included GRASS executable in the JGrass plugins. By default the field of GRASS options in the preferences panel is completed with the right path, if not here the user has to write the path of the folder, in the plugins, containing the grass installation. In general it is: ... pathtoJGrassinstallationfolder\plugins\eu.hydrologis.jgrass.grass_1.0.0\windows\grass\grass\.

In addition at the windows preferences for the console the user has to set also the runtime Console preferences. The menu, shown below, is visible just right clicking on the console window and for GRASS commands the only important field is the MAPSET definition.


At this time the console environment is ready to use for GRASS commands. For example typing
  • grass r.info adige_pit
  • grass r.in.gdal --help
  • and so on...
Some nice hints to use the console editor:
  1. to run all the commands written in the console editor just right click and run
  2. to run only a selection of the written text, simply select the whole command to run and the right click and run
  3. it is possible to have some hinst form JGrass for writing the command, just wait a second after typing the "." in the commands names and after the "--" in the options.



Hope this helps the users in GRASS settings and command executing.

Hope also the develpers will not change this preferences again... :-) it will be not so exiting writing thousand post on the same topic... :-)

Thursday, March 20, 2008

GIS for sustainable development

Finally I moved and my home internet connection is working again... so from now I will be active again in this blog. :-)
In one of my breaks of internet surfing I found this website: http://www.esri.com/industries/sustainable_dev/index.html

So... reading from the website people understand that esri is helping developing countries and in their processes and projects. I don't really want to put the attention on the helping or on the projects... but I would like to read somewhere that an open source software (GIS maybe) is used for projects in developing countries.
Maybe this is still true but do open source projects have websites dedicated on developing countries? In my opinion open source and free softwares have to be used for projects in developing countries... and hopefully used by people there... but this will be the next step.

Wednesday, February 27, 2008

My first script...

Here is a script, written together with Moovida, in which I used three JGrass command in sequence to create 2 shapefiles, one withe the subbasins and the other with the numbered stream network.

In the new JGrass console editor it is possible to:
  1. declare variables
  2. use variables in the scripts
  3. put the result of a command in a variable
  4. use string like in Java
  5. ... much more that I don't know jet!! :-)
To declare variables just put the name and all the information needed and at the end of the statement put a ";". An example is below:

The string that identifies the name of the main basin:
basemap = "chiese";

The output folder for the shapefiles I will create:

outputfolder = "/home/moovida/TMP/tmp/";

The name of the input shapefile:
inputmonitoringpoints = "/home/moovida/data/hydrocareworkspace/featuredata/utm/pti_monitoraggio.shp";

To read some maps which are already saved in the location just type the name of these maps, in this case the strings are a little complicated but managing them is very easy in this way:

drain = basemap + "_drain";
net = basemap + "_net_chnum";
pit = "bacino_" + basemap + "_pit";
netflow = basemap + "_net_flow";
nethackstream = basemap + "_net_hstr";


The output variables are initialized with the string name, everything could be added here...

netnumber = basemap + "_netnumber";
basin = basemap + "_basin";
basinoutput = outputfolder + "bacino_" + basemap + ".shp";
netoutput = outputfolder + "rete_" + basemap + ".shp";

And now just use the varibles in the JGrass command lines:

jgrass {
h.netnumbering --mode 2 --igrass-flow $drain --igrass-net $net --ishapefile-pointshape $inputmonitoringpoints
--ograss-netnumber $netnumber --ograss-basin $basin
}



jgrass {
h.basinShape --igrass-pit $pit --igrass-basins $basin --oshapefile-basinshape $basinoutput
}



jgrass {
h.pfafstetter --mode 0 --igrass-flow $netflow --igrass-hacks $nethackstream --igrass-pit $pit --igrass-netnumber $netnumber --oshapefile-netshapeout $netoutput
}



Run the script with the specific RUN option in the right mouse button menu. In the console window you can see some messages to check the progress of the operations.

If someone has other interestig scripts it would be nice to put them here together.





Monday, February 25, 2008

Some JGrass commands

Before using JGrass commands you have to set the active region that is the portion of the world in which JGrass makes raster elaborations. Note that visualization is more or less independent from active region, calculations are stricktly related to it.

To kown ho to set the active region in JGrass have a lood at the moovidas blog.

Here some JGrass commands to write in the console environment. Thanks to Erica and Andreas that gave them to me. I didn't test all of them but pretty sure they runs well.

h.netnumbering

This command allows you to enumerate the stream network channels and to extract the related basins. The network will be divided in subpieces which start and end at the confluences. To dived the network also in some other interesting points you have to add a shapefile of node point.

  1. first option is the command in the basic mode: Usage mode 0: h.netnumbering --mode 0 --igrass-flow flow --igrass-net net --ograss-netnumber netnumber --ograss-basin basin
  2. second option is dividing the network in subpieces which have an area less than the threshold fixed on the tca: Usage mode 1: h.netnumbering --mode 1 --thtca value --igrass-flow flow --igrass-net net --igrass-tca tca --ograss-netnumber netnumber--ograss-basin basin
  3. third option is dividing the network in some interesting points taken from a shapefile: Usage mode 2: h.netnumbering --mode 2 --igrass-flow flow --igrass-net net --ishapefile-pointshape "filepath" -ograss-netnumber netnumber--ograss-basin basin
  4. fourth method: mixed method between second and third (tca threshold and point shapefile): Usage mode 3: h.netnumbering --mode 3 --thtca value --igrass-flow flow --igrass-net net --igrass-tca tca ishapefile-pointshape "filepath" --ograss-netnumber netnumber--ograss-basin basin

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...

Friday, February 22, 2008

GRASS natives commands under JGrass

As a first attempt to use GRASS commands in the new JGrass console environment in windows, I tried to use the basical GRASS commands like g.region or something to import and create a new location (since at present JGrass hasn't the new location creation tools).

GRASS commands in JGrass console environment can be used by writing the "grass" word before the string of the GRASS command. The string of the GRASS command has to be the same as in GRASS console.

Before using GRASS commands I had to set the runtime preferences. From the right mouse button on the console window, select Set Runtime Preferences and then choose the position of the location and the name of the mapset to use.

My first step was to download from the province website the dtm (lidar dtm at a 2.5 resolution), available free at http://www.provinzia.bz.it/urbanistica/cartografia/cartografia.asp, previous registration.
So used with success the commands:
1. grass r.in.gdal input=D:\path_to_the_ascii_file.ascii output=dtm location=alto_adige
2. grass g.region -p
3. grass r.info dtm

Thursday, February 21, 2008

Why HydrologicLady?

As I already written I am an environmental engineer specialized in hydrology and GIS analysis. I will use this blog not just to put my thoughts about the world but first to write some hints about the use of GIS application in professional world.

I think I tried to use more or less all the major GIS software, since I decided to use the Open Source software, the blog will contain interesting observation about these GIS.

I will write something to help people solving problems in GIS, beginning from the three software I use much frequently: JGrass, GRASS and uDig.