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.

About me...

First of all great thanks to my best friend Moovida who helped me to open this blog... and being honest... to choose the funny name of it.
Just a few details on who I actually am.

I grew up in a very small village (maximum 100 people) in the northern part of Italy, near the Garda Lake, a beautiful place to grow up, not so much to find something interesting for work. Since I was a child I had a passion for Africa... passion handed to me from my uncle that lives and work in Africa as a religious. I have ever thought that I could do something for helping people in the developing countries and so I decided to become and engineer. Maybe not the easiest way to do that! :-)

In 2004 I was gone to Kinshasa for more than one month. The things there are very different from how a person could imagine. At a first moment I wanted to stay there to help those people growing up and surviving, but after a billion of thoughts and conversations, I realized that for help those people I have to start from the others in the so called “first world”.
So I decided to come back to Italy and start to make something that could change the world... and met a person (my best friend) who agreed with me about the possibility to show the people that there could be a different way to live, work and manage a company taking in account of the OTHERS.
Now I am an engineer and the administrator of a small company situated in Bolzano (Italy) that calls HydroloGIS.

HydroloGIS is not simply a company, it is a different way to live and to work, it is doing something with particular regard to quality of the work, safety, environmental processes, environmental protection and at first to the person.
In the vision of collaboration and sharing of information, thinking at how we could help people in the developing countries, we decided to develop and use only open source software and to put our experience and our knowledge to make some projects in Africa.

Since 2005 I worked in that direction, maybe sometimes I lost the right way due to the very high level of efforts that a small company with an ethic and with respect to the people and to the world have to make to survive. As I wrote before, maybe this wasn't the easiest way to change the world, but in these last two months I realized that this is the right way... :-)
And that I will tell you in an other post, when I will have more informations... Hope so!

Hydrologic lady starts here!

Welcome to the blog of the Hydrologic Lady, feel free to comment all you find in this small place of thoughts about the mixture of water and IT sciences.

Cheers!