[GRASS-user] Re: r.mapcalc and nested if
Thank you all for yours answers! I'll explain my problem: I have got a raster map with a lot of small area like this one: 112 112 112 122 112 112 112 1 1 122 122 1 1 1 122 112 122 122 112 112 The boundary is made cells with values from 100 to 200 instead the inner ones have got 1 as value. I need to fill the inner cells with the mode of a 3x3 window. Using a loop until there are no more cell with 1 as value, I started with this approach: map=if(map == 1,mode(map[-1,-1],map[-1,0],map[-1,1],map[0,1],map[1,1],map[1,0],map[1,-1],map[0,-1]),0) I added the map == 1 condition due the null cells outside the boundary, which set the mode to null and slowly eat all my areas :) Using that syntax the loop goes smooth but after a certain point the cells=1 remain the same because the mode is always 1. I discarded r.neighbors because it changes also the values on the boundary which should remain the same. Any hint? Thank you very much. Luca -- View this message in context: http://n2.nabble.com/r-mapcalc-and-nested-if-tp4901916p4913028.html Sent from the Grass - Users mailing list archive at Nabble.com. ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Re: r.mapcalc and nested if
thedok78 wrote: I have got a raster map with a lot of small area like this one: 112 112 112 122 112 112 112 1 1 122 122 1 1 1 122 112 122 122 112 112 The boundary is made cells with values from 100 to 200 instead the inner ones have got 1 as value. I need to fill the inner cells with the mode of a 3x3 window. Using a loop until there are no more cell with 1 as value, I started with this approach: map=if(map == 1,mode(map[-1,-1],map[-1,0],map[-1,1],map[0,1],map[1,1],map[1,0],map[1,-1],map[0,-1]),0) I added the map == 1 condition due the null cells outside the boundary, which set the mode to null and slowly eat all my areas :) Using that syntax the loop goes smooth but after a certain point the cells=1 remain the same because the mode is always 1. I discarded r.neighbors because it changes also the values on the boundary which should remain the same. r.mapcalc 'map.tmp = if(map == 1, null(), map)' r.neighbors in=map.tmp out=map.mode method=mode size=3 r.mapcalc 'map.filled = if(map == 1, map.mode, map)' Replacing the ones with nulls in the first step will cause r.neighbors to ignore those cells when calculating the mode. -- Glynn Clements gl...@gclements.plus.com ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
[GRASS-user] Re: r.mapcalc and nested if
Sorry, this is the expression: r.mapcalc 'map2=if(map ==1 ,if(mode(map[-1,-1],map[-1,0],map[-1,1],map[0,1],map[1,1],map[1,0],map[1,-1],map[0,-1])==1,0,mode(map[-1,-1],map[-1,0],map[-1,1],map[0,1],map[1,1],map[1,0],map[1,-1],map[0,-1]),map))' Thanks Luca -- View this message in context: http://n2.nabble.com/r-mapcalc-and-nested-if-tp4901916p4901925.html Sent from the Grass - Users mailing list archive at Nabble.com. ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Re: r.mapcalc and nested if
thedok78 pisze: Sorry, this is the expression: r.mapcalc 'map2=if(map ==1 ,if(mode(map[-1,-1],map[-1,0],map[-1,1],map[0,1],map[1,1],map[1,0],map[1,-1],map[0,-1])==1,0,mode(map[-1,-1],map[-1,0],map[-1,1],map[0,1],map[1,1],map[1,0],map[1,-1],map[0,-1]),map))' Thanks Luca seem that much easier will be: r.neighbors input=your_map method=mode size=3 output=mode_output r.mapcalc 'first_map=if(your_map==1,output_mode,your_map)' r.mapclac 'final=if(first_map=1,0,first_map' ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Re: r.mapcalc and nested if
Hi there, may be the last command need double == r.mapclac 'final=if(first_map==1,0,first_map' cheers milton 2010/4/14 Jarek Jasiewicz jar...@amu.edu.pl thedok78 pisze: Sorry, this is the expression: r.mapcalc 'map2=if(map ==1 ,if(mode(map[-1,-1],map[-1,0],map[-1,1],map[0,1],map[1,1],map[1,0],map[1,-1],map[0,-1])==1,0,mode(map[-1,-1],map[-1,0],map[-1,1],map[0,1],map[1,1],map[1,0],map[1,-1],map[0,-1]),map))' Thanks Luca seem that much easier will be: r.neighbors input=your_map method=mode size=3 output=mode_output r.mapcalc 'first_map=if(your_map==1,output_mode,your_map)' r.mapclac 'final=if(first_map=1,0,first_map' ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user