[GRASSLIST:5026] Re: Looking for something like r.grow, but that retains value
Patrick Dunlavey
pat at pdcarto.com
Thu Nov 21 09:19:50 EST 2002
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>
More information about the grass-user
mailing list