[GRASS-user] GRASS64 - r.mapcalc - replacement of specifics value by a mean of nearest neigbour

Dear Grass users,

I'm working with rasters maps of large area and I want to calculate surface related to specific colours. Before this, I have to replace the surfaces of the rivers by the surrounding value (or the mean of the surrounding value).

I looked at the manual of r.mapcalc but I didn't found how to do this...

For instance, I want to replace all value between 4 and 7 by the mean of the value of the 4 nearest pixels.

Is there any way of doing this?

Which command shall I use then for calculating the surface for each color? r.stats? or is there a command that directly computes the surface?

Best regards

Lucien

One way to do this would be to replace all values between 4 and 7 by NULL (e.g., r.null map=yourRaster setnull=4-7). Then use r.neighbors to calculate the mean of the nearest neighbors (e.g., r.neighbors input=yourRaster output=intermediateResult size=3. Have a look at the help file of r.neighbors and the part about the size of the neighborhood and option to use a circular neighborhood). Last step, patch the two layers together (e.g, r.patch input=yourRaster,intermediateResult output=yourOutput).

As for your second question, r.stats is indeed what you are looking for I think, it calculates the surface for each categories of the input raster layer.

Rgds

Paulo

ยทยทยท

On 05/04/2013 08:17 PM, BLANDENIER Lucien wrote:

Dear Grass users,

I'm working with rasters maps of large area and I want to calculate surface related to specific colours. Before this, I have to replace the surfaces of the rivers by the surrounding value (or the mean of the surrounding value).

I looked at the manual of r.mapcalc but I didn't found how to do this...

For instance, I want to replace all value between 4 and 7 by the mean of the value of the 4 nearest pixels.

Is there any way of doing this?

Which command shall I use then for calculating the surface for each color? r.stats? or is there a command that directly computes the surface?

Best regards

Lucien
_______________________________________________
grass-user mailing list
[grass-user@lists.osgeo.org](mailto:grass-user@lists.osgeo.org)
[http://lists.osgeo.org/mailman/listinfo/grass-user](http://lists.osgeo.org/mailman/listinfo/grass-user)

On 04/05/13 20:17, BLANDENIER Lucien wrote:

Dear Grass users,

I'm working with rasters maps of large area and I want to calculate surface related to specific colours. Before this, I have to replace the surfaces of the rivers by the surrounding value (or the mean of the surrounding value).

I looked at the manual of r.mapcalc but I didn't found how to do this...

For instance, I want to replace all value between 4 and 7 by the mean of the value of the 4 nearest pixels.

Is there any way of doing this?

Something like this:

newMap =if(oldMap >= 4 && oldMap <=7, (oldMap[-1,0]+oldMap[0,-1]+oldMap[0,1]+oldMap[1,0])/4, oldMap)

Which command shall I use then for calculating the surface for each color?

When you say color, I suppose you mean cell values.

r.stats? or is there a command that directly computes the surface?

r.stats -a _does_ directly compute the surface.

Moritz

BLANDENIER Lucien wrote:

Dear Grass users,

I'm working with rasters maps of large area and I want to calculate surface
related to specific colours. Before this, I have to replace the surfaces of
the rivers by the surrounding value (or the mean of the surrounding value).

I looked at the manual of r.mapcalc but I didn't found how to do this...

For instance, I want to replace all value between 4 and 7 by the mean of the
value of the 4 nearest pixels.

Is there any way of doing this?

Which command shall I use then for calculating the surface for each color?
r.stats? or is there a command that directly computes the surface?

Dear Lucien,

did you get past this problem?

I think a combination of r.neighbours (to get the average values from
surrounding cells) and r.recode (for re-categorising values in your input
raster maps so as to get the desired output) + r.stats could do it.

Didn't try anything, of course -- not time.

Thanks, Nikos