[GRASS-user] Calling external programs

Glynn Clements glynn at gclements.plus.com
Sat Feb 9 15:58:39 EST 2008


Hufkens Koen wrote:

> I was wondering if it is possible to feed raster maps as input into an
> external model and let the input be imported or be importable by GRASS
> as a result. The model is able to accept data of several biophysical
> parameters but for the moment only in 1D. Extending this to 2D with the
> use of rasterized data from GRASS would be a nice bonus. Or I will
> rephrase my question: Is there a standard command that can pipe raster
> data per pixel location into external code for evaluation and accept the
> output of this program? I know that there is shell access from within
> GRASS, but I don't know how it deals with the output of programs run in
> the shell from within GRASS.

Usually this is done by exporting the data, processing it, then
importing the processed data. The various export and import modules
for raster data are named r.out.* and r.in.* respectively.

The r.{in,out}.gdal modules can import/export data in a wide range of
formats (the exact set depends up which formats your version of GDAL
supports).

If you're writing the import/export code for the processing component
yourself, you can get raster data in a raw format using either
r.{in,out}.ascii (text format) or r.{in,out}.bin (binary format).

Note that export modules (r.out.*) will re-scale raster data according
to the current region settings, while import modules (r.in.*) will
read it cell-for-cell. If the format supports georeferencing, the
imported map will be positioned correctly, otherwise the lower-left
corner will be at 0,0 and the dimensions of the map will correspond to
the dimensions of the raster data in cells (pixels). In the latter
case, you can correct the bounds of the imported map with r.region.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list