[GRASS-dev] How to: if undefined, set to NULL?

Markus Neteler neteler at osgeo.org
Sat Aug 27 06:37:35 PDT 2016


On Sat, Aug 27, 2016 at 3:26 PM, Nikos Alexandris
<nik at nikosalexandris.net> wrote:
> While modifying i.rgb.his,
>
>    if (chroma == 0.0) {
>
>        saturation = 0.0;
>
>        /* undefined -- (how to) set to NULL? */
>        hue = 0.0;
>
>        rowbuffer[0][sample] = (FCELL)hue;
>        rowbuffer[1][sample] = (FCELL)intensity;
>        rowbuffer[2][sample] = (FCELL)saturation;
>    }
>
>
> I'd like to set hue to NULL, whenever the condition is met. How do I do
> that?
>
>    hue = NULL;
>
> does not work.

No, it is done withRast_set_null_value()

Something like:

    for (row = 0; row < nrows; row++) {
        G_percent(row, nrows, 5);
        for (col = 0; col < ncols; col++) {
            cell_buf[col] = bas[SEG_INDEX(ba_seg, row, col)];
            if (cell_buf[col] == 0)
                Rast_set_null_value(&cell_buf[col], 1, CELL_TYPE);
        }
        Rast_put_row(basin_fd, cell_buf, CELL_TYPE);
    }

(random example, taken from r.water.outlet/main.c)

HTH,
Markus


More information about the grass-dev mailing list