Showing posts with label raster. Show all posts
Showing posts with label raster. Show all posts

Thursday, November 17, 2011

Raster processing

It's been a long time since we last wrote a post. I've been involved in other projects and I've had no time to work on GGL2. Now we're preparing the workshop at the gvSIG conference and we have made a great breakthrough by adding raster capabilities to the language.

Now it is possible to read raster data from ASCII grid files, TIFFs and JPEGs and access the individual samples:
read ASC '/tmp/dem.asc' to mydem;
show dem[10, 10];
The value at a specific world point can be accessed easily as well. Say "mypoint" is the geometry containing the point we're interested in, the following code woulf give the raster value for that point:
show dem at(ST_X(mypoint), ST_Y(mypoint))
But the hardest part have been the "rexp" expressions. Rexp stands for Raster EXPressions and as it may be taken for "regular expression", we are tempted to change it to "rop" for Raster OPeration. Anyway, it's called Rexp during this post.

Rexps lets the user filter the samples of a raster. For example, say we just want to have the samples in our dem that are higher than 100 meters:
result = rexp dem do (h) {
if (h > 100) {
return h;
} else {
return null;
}
};
In the previous construction
  1. "rexp dem" means "I want to process raster stored in 'dem' variable".
  2. "do (h)" says "let 'h' be any sample of the input raster".
  3. The code between curly brackets return the value of the sample for the output raster.

When the sample expression is simple enough it is possible to use the more concise "eval" syntax. For example, the following code produces the shadow of the dem in the north direction:
result = rexp dem eval (h| h[-1, -1] + 2*h[0, -1] 
+ h[1, -1]
+ h - h[-1, 1] - 2*h[0, 1] - h[1, 1])
It is possible to involve more rasters, georreference them, etc.

If you think rexp is cool, please note that it's not my idea but I copied it from Jiffle, a raster specific language from the super jaitools project[1].

There is a lot of work ahead: supporting more raster formats, optimizing the execution, etc. But ah! when I think how much did it took to do all these operations in GGL1 I get so happy...

More on this at the gvSIG International Conference.


[1] http://jaitools.org/