5

I have a raster map in GRASS that looks like this:

Raster map with binary values

The red cells have a value of 1, the yellow cells have a value of 0.

I am trying to use the r.grow command to 'fill in' the gaps in the red lines, but it seems that whatever options I give the command, the output is either exactly the same as the input, or entirely 1, or entirely 0.

The way to run the command that seems most sensible is:

r.grow input=extracted@PERMANENT output=gr8 radius=3.01

which, as far as I can tell, should grow all positive cells by 3 cells. However, it doesn't seem to do anything at all - the output map is exactly the same as the input map. Changing the old and new values doesn't seem to change it either.

Am I doing something wrong here? I have read through the manual page for the r.grow command many times, but can't see what I'm missing.

4
  • 1
    Do you mean that the yellow has a value of zero or that it is null? The manual page says that the non-null cells are expanded only into the null cells (which, by default, apparently are encoded with the value -1, not zero).
    – whuber
    Commented Nov 23, 2012 at 21:19
  • 2
    Ah yes, that seems to solve it. I didn't notice that it was talking about NULL pixels, rather than 0 pixels (or maybe I was just used to grow functions working with {0,1} rasters rather than {NULL,1} rasters. If you add this as an answer then I'll accept it. Thanks!
    – robintw
    Commented Nov 25, 2012 at 18:12
  • 2
    Furthermore, you can use the r.null command to set zero values to NULL: r.null <rast_map> setnull=0
    – Micha
    Commented Nov 25, 2012 at 19:53
  • (+1 for the question.) I have converted the comment into a formal answer. Glad it helped!
    – whuber
    Commented Feb 24, 2013 at 20:19

1 Answer 1

2

The manual page says that the non-null cells are expanded only into the null cells (which, by default, apparently are encoded with the value -1, not zero).

In a comment, @Micha states you can use r.null to convert the zero values to nulls, as in

 r.null <rast_map> setnull=0

After you make such a change, r.grow should produce the expected output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.