Hello,
JFYI: i have added a new option "selection" to r.neighbors.
The user can optionally specify a selection map, to compute new values
only where the raster cells of the selection map are not NULL. In case
of NULL cells, the values from the input map are copied into the
output map. This may useful to smooth only parts of an elevation map
(pits, peaks, ...).
Example how to use a selection map with method=average:
input map:
1 1 1 1 1
1 1 1 1 1
1 1 10 1 1
1 1 1 1 1
1 1 1 1 1
selection map, NULL values are marked as *:
* * * * *
* * 1 * *
* 1 1 1 *
* * 1 * *
* * * * *
The output map:
1 1 1 1 1
1 1 2 1 1
1 2 2 2 1
1 1 2 1 1
1 1 1 1 1
Without using the selection map, the output map would look like this:
1 1 1 1 1
1 2 2 2 1
1 2 2 2 1
1 2 2 2 1
1 1 1 1 1
Have fun
Soeren
Soeren Gebbert wrote:
JFYI: i have added a new option "selection" to r.neighbors.
A few points about the change:
1. Human-readable strings (option descriptions, messages) should be
localised with _(...).
2. There's no need to read the map using its native type
(CELL/FCELL/DCELL); reading as DCELL will suffice, and requires less
code. Better still, as you only care whether or not cells are null,
you can use Rast_get_null_value_row().
3. It reads the input a second time (at its native type, then converts
to DCELL) when the input row will already be in ncb.buf[ncb.dist] (as
DCELL).
4. There are a couple of deviations from the GRASS formatting
conventions (see tools/grass_indent.sh), specifically space between
"if" and "(" and "else" on a separate line to a preceding closing
brace.
Please check r40541.
--
Glynn Clements <glynn@gclements.plus.com>
Hi Glynn,
2010/1/19 Glynn Clements <glynn@gclements.plus.com>:
Soeren Gebbert wrote:
JFYI: i have added a new option "selection" to r.neighbors.
A few points about the change:
1. Human-readable strings (option descriptions, messages) should be
localised with _(...).
Sorry, i will check other modules, which i modified, to make sure i did
not forget the localization.
2. There's no need to read the map using its native type
(CELL/FCELL/DCELL); reading as DCELL will suffice, and requires less
Ok.
code. Better still, as you only care whether or not cells are null,
you can use Rast_get_null_value_row().
I see, i never used Rast_get_null_value_row() before, thanks for your advise.
3. It reads the input a second time (at its native type, then converts
to DCELL) when the input row will already be in ncb.buf[ncb.dist] (as
DCELL).
4. There are a couple of deviations from the GRASS formatting
conventions (see tools/grass_indent.sh), specifically space between
"if" and "(" and "else" on a separate line to a preceding closing
brace.
I german we call the coding which i have done "verschlimmbessern",
translated into english this means "Trying to improve things but
actually make them worse."
Please check r40541.
Code looks much better now, thanks.
Soeren
--
Glynn Clements <glynn@gclements.plus.com>
Soeren Gebbert wrote:
> 4. There are a couple of deviations from the GRASS formatting
> conventions (see tools/grass_indent.sh), specifically space between
> "if" and "(" and "else" on a separate line to a preceding closing
> brace.
I german we call the coding which i have done "verschlimmbessern",
translated into english this means "Trying to improve things but
actually make them worse."
It's probably a useful feature; it could also be done with a
combination of the unmodified r.neighbors and r.mapcalc, but that's
inefficient if the neighbourhood is large and the selection map is
sparse.
The issues were relatively minor, given how much really horrible code
lurks within GRASS (some of it seems to exist primarily as evidence of
the saying "you can write Fortran code in any language").
--
Glynn Clements <glynn@gclements.plus.com>