[GRASSLIST:5024] Re: Looking for something like r.grow, but that retains value

> I'm looking to 'grow' a line in a raster much like r.grow would do,
> but have the new cells take on the value of its nearest tangential
> neighbor- not 1. Basically I have a thin line of varying data which I
> am trying to emphasize, to make it easier to see.

I thought r.grow would have suited your purpose. The man pages say that the -b switch forces the output to be binary, by default though, the attribute of the source is preserved.

r.grow man page:
"If the -b flag is not used, these cells will retain their original non-zero
category values. ***In either case, all cells whose category value is changed
from 0 during the growing process are assigned a category value of 1 in the
output map.***"

My original line retains its values, but the new 'grown' cells around it are category 1. I would like them to take on the value of their nearest tangential neighbor in the output map...

Here's a shell script I wrote to do exactly this.

-- Pat

<DEFANGED_Script>

echo ""
echo Grow into zero cells v0003
g.ask type=old element=cell desc=raster prompt="Enter source file"
unixfile=/tmp/$$ eval `cat /tmp/$$` rm -f /tmp/$$ if [ ! "$file" ] then
    exit 0
fi
src="${fullname}"

echo "$src"

gotit=0
while test $gotit -eq 0
do
  echo -n "iterations: "
  read itrs
  if test $itrs -ge 1 -a $itrs -lt 30
  then
    gotit=1
  else
    echo Sorry, iterations must be greater than 0 and less
than 30
  fi
done

echo ""
echo Running r.mapcalc, please stand by.
echo Your new map will be named grown. Please consider renaming. echo
""

# Note: no space allowed after \\:
r.mapcalc << EOF
grown = if( $src, $src, \\
   if($src[0,-1], $src[0,-1], \\
    if( $src[0,1], $src[0,1], \\
     if($src[-1,0], $src[-1,0], \\
      if( $src[1,0], $src[1,0] \\
  )))))
EOF

#Remove nulls created at edges
r.mapcalc 'grown=if(isnull(grown),0,grown)'

  echo "iteration=1"

i=2
while [ $i -le $itrs ]
do
r.mapcalc << EOF
  grown = if( grown, grown, \\
     if(grown[0,-1], grown[0,-1], \\
       if( grown[0,1], grown[0,1], \\
         if(grown[-1,0], grown[-1,0], \\
           if( grown[1,0], grown[1,0] \\
    )))))
EOF

#Remove nulls created at edges
r.mapcalc 'grown=if(isnull(grown),0,grown)'
  echo "iteration=$i"
  let i=$i+1
done

echo ""
echo New map created and named grown. Consider renaming

</Script>