Now it is possible to read raster data from ASCII grid files, TIFFs and JPEGs and access the individual samples:
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:read ASC '/tmp/dem.asc' to mydem;
show dem[10, 10];
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.show dem at(ST_X(mypoint), ST_Y(mypoint))
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:
In the previous constructionresult = rexp dem do (h) {
if (h > 100) {
return h;
} else {
return null;
}
};
- "rexp dem" means "I want to process raster stored in 'dem' variable".
- "do (h)" says "let 'h' be any sample of the input raster".
- 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:
It is possible to involve more rasters, georreference them, etc.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])
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/