[GRASS5] region growing - r.mapcalc bug?

On Wed, Mar 02, 2005 at 10:06:47AM +0000, Paul Kelly wrote:

On Wed, 2 Mar 2005, Jachym Cepicky wrote:

>sorry, I need
>if(seed[-1,-1] && (raster[-1,-1]> raster[1,1]),seed[-1,-1]+1,\
> if(seed[-1,0] && (raster[-1,0] > raster[1,0]),seed[-1,-1]+1,\
> if(seed[-1,1] && (raster[-1,1] > raster[1,-1]),seed[-1,1]+1,\
> if(seed[0,-1] && (raster[0,-1] > raster[0,1]),seed[0,-1]+1,\
> if(seed[0,1] && (raster[0,1] > raster[0,-1]),seed[0,1]+1,\
> if(seed[1,-1] && (raster[1,-1] > raster[-1,1]),seed[1,-1]+1,\
> if(seed[1,0] && (raster[1,0] > raster[-1,0]),seed[1,0]+1,\
> if(seed[1,1] && (raster[1,1] >
> raster[-1,-1]),seed[1,1]+1,null()))))))))

Have you tried the isnull() function in r.mapcalc? That old tutorial you
linked to was written for GRASS 4 where there was no null cell concept.

Paul

Dou you mean something like
rg = \
     if(!isnull(seed[-1,-1]) && (raster[-1,-1]> raster[1,1]),1,\
     if(!isnull(seed[-1,0] ) && (raster[-1,0] > raster[1,0]),1,\
     if(!isnull(seed[-1,1] ) && (raster[-1,1] > raster[1,-1]),1,\
     if(!isnull(seed[0,-1] ) && (raster[0,-1] > raster[0,1]),1,\
     if(!isnull(seed[0,1] ) && (raster[0,1] > raster[0,-1]),1,\
     if(!isnull(seed[1,-1] ) && (raster[1,-1] > raster[-1,1]),1,\
     if(!isnull(seed[1,0] ) && (raster[1,0] > raster[-1,0]),1,\
     if(!isnull(seed[1,1] ) && (raster[1,1] > raster[-1,-1]),1,null()))))))))

??

But I need to detect neighbourhood of the central point, if it is
"notnull()"...

OOh, I have it:
    if(x) = TRUE if x != 0, but
    if(x) = TRUE if isnull(x)

(I hope, you can understand).

Now I run
    rg = \
     if(seed, 1, \
     if(seed[-1,-1] && (raster[-1,-1]> raster[1,1]),1,\
     if(seed[-1,0] && (raster[-1,0] > raster[1,0]),1,\
     if(seed[-1,1] && (raster[-1,1] > raster[1,-1]),1,\
     if(seed[0,-1] && (raster[0,-1] > raster[0,1]),1,\
     if(seed[0,1] && (raster[0,1] > raster[0,-1]),1,\
     if(seed[1,-1] && (raster[1,-1] > raster[-1,1]),1,\
     if(seed[1,0] && (raster[1,0] > raster[-1,0]),1,\
     if(seed[1,1] && (raster[1,1] > raster[-1,-1]),1,\
     0)))))))))

where seed is map containing 1 and 0 but NOT null values. Now it works fine.

it is in xif.c file:
/********************************************************************
if(a) 1,0,1 1 if a is non zero, 0 otherwise
if(a,b) b,0,b b if a is non zero, 0 otherwise
if(a,b,c) b,c,b b if a is non zero, c otherwise
if(a,b,c,d) d,c,b b if a is positive, c if a is zero, d if a is negative
********************************************************************/

should be

/********************************************************************
if(a) 1,0|null,1 1 if a is non zero AND not null, null otherwise
...

But I don't know, how to corect it...

Jachym
--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://www.fle.czu.cz/~jachym/gnupg_public_key/

Jachym Cepicky wrote:

But I need to detect neighbourhood of the central point, if it is
"notnull()"...

OOh, I have it:
    if(x) = TRUE if x != 0, but
    if(x) = TRUE if isnull(x)

No. if(x) is NULL if x is NULL.

For the one argument form:

  if(x) = NULL if x is NULL
  if(x) = 0 if x = 0
  if(x) = 1 otherwise (i.e. x is neither NULL nor 0).

For the two argument form:

  if(x,a) = NULL if x is NULL
  if(x,a) = 0 if x = 0
  if(x,a) = a otherwise (i.e. x is neither NULL nor 0).

For the three argument form:

  if(x,a,b) = NULL if x is NULL
  if(x,a,b) = b if x = 0
  if(x,a,b) = a otherwise (i.e. x is neither NULL nor 0).

For the four argument form:

  if(x,a,b,c) = NULL if x is NULL
  if(x,a,b,c) = a if x > 0
  if(x,a,b,c) = b if x = 0
  if(x,a,b,c) = c if x < 0

More generally, all operators and most functions return NULL if *any*
of their arguments are NULL.

if(), isnull() and eval() are exceptions.

isnull() returns 1 if its argument is NULL and 0 otherwise. If you
want the opposite, use the ! operator, e.g. "!isnull(x)".

All forms of if() return NULL if the first argument is NULL. The 2, 3
and 4 argument forms of if() return NULL if the "selected" argument is
NULL, e.g.:

  if(0,a,b) = b regardless of whether a is NULL
  if(1,a,b) = a regardless of whether b is NULL

eval() always returns its last argument, so it only returns NULL if
the last argument is NULL.

Note that you cannot test for NULL using the == operator, as that
returns NULL if either or both arguments are NULL, i.e. if x and y are
both NULL, then "x == y" and "x != y" are both NULL rather than 1 and
0 respectively.

The behaviour makes sense if you consider NULL as representing an
unknown quantity. E.g. if x and y are both unknown, then the values of
"x == y" and "x != y" are also unknown; if they both have unknown
values, you don't know whether or not they both have the same value.

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