Opened 15 years ago
Last modified 6 years ago
#857 new enhancement
add simple neighborhood functions to r.mapcalc
Reported by: | dickeya | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | 7.6.2 |
Component: | Raster | Version: | svn-trunk |
Keywords: | r.mapcalc | Cc: | |
CPU: | All | Platform: | All |
Description
I find myself using a lot of neighbor functions in r.mapcalc, but find the syntax to be tedious. Anything larger than a 3x3 neighborhood and writing out "raster[-1,-1] + raster[-1,0] + raster[-1,-1] + ..." is quite a task. It's especially hard to do an average when nodata cells are present.
It would be great to have some built in neighborhood functions that would handle the math, taking into account nodata cells, and working on a rectangular or circular area. Something like:
neighborhood(raster, width, height, shape, function)
Change History (10)
comment:1 by , 15 years ago
comment:2 by , 12 years ago
Milestone: | 6.4.0 → 7.0.0 |
---|---|
Version: | unspecified → svn-trunk |
Perhaps the new Python interface in GRASS 7 is a useful start here.
comment:3 by , 9 years ago
Milestone: | 7.0.0 → 7.0.5 |
---|
comment:4 by , 8 years ago
Milestone: | 7.0.5 → 7.3.0 |
---|
comment:7 by , 7 years ago
Milestone: | 7.4.1 → 7.4.2 |
---|
comment:8 by , 6 years ago
Milestone: | 7.4.2 → 7.6.0 |
---|
All enhancement tickets should be assigned to 7.6 milestone.
Replying to dickeya:
For a sum, use
r.mfilter[.fp]
orr.neighbors ... weight=...
Convert nulls first in a separate pass.
There area a couple of issues with this:
If neighborhood() was a normal function, the above call would result in its first argument being the current row of the specified raster, which is no good for a neighborhood operation (and all of its other arguments would also be row-sized arrays of CELL/FCELL/DCELL values; a numeric literal is passed as a row-sized array filled with that value).
I suspect that it might be more fruitful to add new aggregates to r.neighbors.
That still leaves a gap between what can be implemented with a combination of r.mapcalc + r.neighbors + r.mapcalc and what could be implemented with a more general language. E.g. there isn't any combination which will allow you to calculate:
for any <op> except multiplication.
Implementing that specific case in r.mapcalc (or r.neighbors) would be a lot of work, but not entirely out of the question. My main concern is that it would be the thin end of the wedge; either we draw a line in the sand, or we end up with Perl.
IMHO, if you can't do what you want with r.mapcalc + r.neighbors, you'll need a system with enough (virtual) memory to use Matlab/Octave/NumPy.