[GRASS5] Newbies Q: dealing with nulls in raster maps

Hi all.

I'm writing my first C app (after hello world :wink: - a GRASS module.
I managed to load raster into 2d array and do all stuff what I need,
except when dealing with null values.

Q's:
1. How can I check is raster cell value null? foo[y]==NULL?
2. How can I save resulting raster map with null instead of "0"?

Those Q's may sound lame, but, as I have only read "teach yourself C
in 24 hours" style tutorial, I cannot understand GRASS null magic
looking only on source.

tnx for reading,
Maris Nartiss.

Hi Maris,

1. How can I check is raster cell value null? foo[y]==NULL?
2. How can I save resulting raster map with null instead of "0"?

Those Q's may sound lame, but, as I have only read "teach yourself C
in 24 hours" style tutorial, I cannot understand GRASS null magic
looking only on source.

I think the best thing would be to look into a simple module like for example
r.sum and read the developers manual. It supplies all the functions you need.
For example some lines of r.sum

// for every row of the region defined in "w"
  for (row = 0; row < w.rows; row++) {

// this reads the row number "row" from the cellfile into the buffer tf
      G_get_f_raster_row(cellfile, tf, row);

// for every column of the region defined in "w"
      for(col=0; col < w.cols; col++){

// if the value in tf is null
    if (G_is_f_null_value (tf)) *tf = 0.0;

// move pointer one position
    tf++;
// and so on...

Functions like G_is_f_null_value, G_get_f_raster_row are all well described in
the developer's manual, which is a bible if you want to write a module.

Cheers,
Andrea

tnx for reading,
Maris Nartiss.

_______________________________________________
grass5 mailing list
grass5@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass5

--
____________________________________________________________________________
HydroloGIS - Environmental Open Source Solutions
www.hydrologis.com

Andrea Antonello
Environmental Engineer
mobile: +393288497722

"Let it be as much a great honour to take as to give learning,
if you want to be called wise."
Skuggsja' - The King's mirror - 1240 Reykjavik
____________________________________________________________________________

Mris Nartis wrote:

I'm writing my first C app (after hello world :wink: - a GRASS module.
I managed to load raster into 2d array and do all stuff what I need,
except when dealing with null values.

Q's:
1. How can I check is raster cell value null? foo[y]==NULL?

  int G_is_c_null_value(const CELL *cellVal);
  int G_is_f_null_value(const FCELL *fcellVal);
  int G_is_d_null_value(const DCELL *dcellVal);
  int G_is_null_value(const void *rast, RASTER_MAP_TYPE data_type);

2. How can I save resulting raster map with null instead of "0"?

  void G_set_c_null_value(CELL *cellVals, int numVals);
  void G_set_f_null_value(FCELL *fcellVals, int numVals);
  void G_set_d_null_value(DCELL *dcellVals, int numVals);
  void G_set_null_value(void *buf, int numVals, RASTER_MAP_TYPE data_type);

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