minimum size script

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

minimum size script

Scott Tweddale

Due to popular demand, here is a simple but very useful script written by
Michael Shapiro of USA-CERL which analyzes an input raster map and "filters"
out any continous areas which are not above a minimum size specified by the
user.  In this case, the areal units are square meters, but this can
obviously be changed within the script to suit your specific applications.

:
g.ask element=cell type=old prompt="Rasterfile to be analyzed" unixfile=/tmp/$$
. /tmp/$$
rm -f /tmp/$$
if [ "$name" = "" ]
then
        exit
fi
input="$fullname"

g.ask element=cell type=new prompt="Result map" unixfile=/tmp/$$
. /tmp/$$
rm -f /tmp/$$
if [ "$name" = "" ]
then
        exit
fi
output="$name"

echo -n "Minimum size (in meters): "
read meters
set -x
r.stats -a "$input" | awk "\$2 > $meters { print \$1 \"=\" \$1 }" | r.reclass in="$input" out="$output"

Scott Tweddale
U. of Illinois GIS Lab/USA-CERL