Monday, January 5, 2009

v.addattributes or... have you ever seen the rain?

As some of you might know, we are working on large hydrologic model that is going to be put into JGrass following the openmi standards.

One of the issues we found is that to have a good feeling of the spatial distribution of data over the studied basin. With raster data that has never been an issue (in fact the issue is the space taken by the rasters :)), but how to be quick when you have resulting values placed in the baricenter of a basin?

Usually you get a nice matricx of values that you then have to somehow push into the attributes table of a shapefile in order to have some visual result of your calculus. But what if the values are temporal???

Copy and paste the result of every timestep into a shapefile? Hmmm.... no way!

We now have a module in JGrass that is called v.addattributes and I'm gonna show you an example of it.

Assume I have a file that contains a line for every timestep of my model and that line is formatted like the following: 

idbasin1, value11, value12, idbasin2, value21, value22,... idbasinN, valueN1, valueN2

The values could be any numeric thing, we could have 1, 2, ...n values.

In my example I have a file with interpolated rainvalues in the baricenters of these basins:




The file looks like:

1739.0 0.0 1535.0 0.0 1655.0 0.0 2157.0 0.0 1930.0 0.0 1801.0 0.0 1460.0 0.0 632.0 3.684153909618608 906.0 ...
1739.0 0.4793081233266918 1535.0 0.048572411261128046 1655.0 0.6070006443236106 2157.0 0.44196721516998566   ...
1739.0 0.0532564581474102 1535.0 0.0 1655.0 0.042013300835839144 2157.0 0.04910746835222063 1930.0 0.0909374550600321   ...
1739.0 0.5304998409078074 1535.0 1.0377122085218624 1655.0 0.7508780110017237 2157.0 0.6222435955068898 1930.0   ...


i.e. idbasin1, rainvalue1, idbasin2, rainvalue2... and so on

With the following script I am now able to merge the two informations, based on the basin ids. 






jgrass {
v.addattributes
--iflayer-infeatures "bacini_bz_idlikedb0"
--itscalar-attributes "C:\\zcontainer\\TMP\\THEBIGTEST\\rain-allbasin.csv"
--oshapefile-outfeatures "C:\\zcontainer\\TMP\\THEBIGTEST\\testoutput\\test"
--joinfield "NETNUM"
}

The field used to join the informations has to be defined as a parameter, in this case NETNUM.


The result is a shapefile for every time step that the model runs for. The shapefile will have a new field (by deafult called new_0, new_1...) containing the information. In this case it is just one field containing the rain values, but could be as well more fields as forexample the temperature in different elevation bands for every basin.

The result is quite nice, can you see the strom moving in the following three screenshots?



Timestep 1:


Timestep 2:


Timestep 3:











2 comments:

silli said...

Great!!!
Nice idea to show the evolution of a storm... :)

markusN said...

Very nice indeed! Do we want the same thing in upstream GRASS as well?