Good day,
I was interested in running some statistics on the correlation
between two raster maps. I would like to get the output generated
by r.coin into a more usable format for import into a stat or
spreadsheet program, aka a "flat file".My question is: does anybody know how to change the format of the
r.coin output, or how to extract the same sort of data without going
through r.coin?Many thanks in advance,
Scott
-------------------------------------------------------------------------
Scott Miller e-mail: miller@tucson.ars.ag.gov
USDA ARS SWRC phone: 520-670-6380 ext. 156
2000 E. Allen Rd.
Tucson, AZ 85719
-------------------------------------------------------------------------
You can use r.report to create output that is human readable.
But if you want to send output to a script for conversion to
a spreadsheet readable file I suggest using r.stats. It does
the coincident area calculations on one or several maps and
sends the output to a space delineated flat file, although you
can specify another field separator.
As a general rule it is quite helpful to look at the end of entries
in the GRASS manual in the "SEE ALSO" section. The r.coin entry
mentions both of these programs.
Here is an example of a script pair I wrote using r.stats
to create a Lotus 123 readable file. The first script is long because
it is an interactive one. But it could be shortened and piped
with the second to create a commandline version.
grass123:
--------------------------------------------------------
#! /bin/sh
rm lotus.in
echo
echo "This program generates a report file for one or"
echo "two raster files (calculated in square meters)"
echo "for import directly into Lotus 123"
i=0
while [ 0 = $i ]
do
echo
echo "How many raster files will be examined (1 or 2)?"
read numbermaps < "/dev/tty"
if [ 1 = "$numbermaps" ] || [ 2 = "$numbermaps" ]
then
i=1
fi
done
fullname=0
g.ask type=old element=cell prompt="Enter the name a raster file: "
unixfile=/tmp/g.ask$$
. /tmp/g.ask$$
if [ 0 = "$fullname" ]
then
exit 1
fi
map_1=$fullname
if [ 2 = "$numbermaps" ]
then
fullname=0
g.ask type=old element=cell prompt="Enter the name a raster file: "
unixfile=/tmp/g.ask$$
. /tmp/g.ask$$
if [ 0 = "$fullname" ]
then
exit 1
fi
map_2=$fullname
fi
echo
echo "Enter the name of the lotus importable file to be generated"
read lotus_in < "/dev/tty"
echo "Your data will be saved as" `pwd`/$lotus_in
r.stats -lza input=$map_1,$map_2 fs=% output=/tmp/rstats.$$
make123 < /tmp/rstats.$$ >> $lotus_in
rm /tmp/rstats.$$
echo
echo "Now you must start lotus and import the file using "
echo "/ File Import Numbers"
--------------------------------------------------------
make123:
--------------------------------------------------------
#! /usr/local/bin/gawk -f
#takes GRASS r.stats output and creates a new ascii file
#for import to lotus
BEGIN { FS = "%"
OFS=","
getline
if (NF>3)
{
i=2
printf("\n") > "/dev/tty"
printf("\"FIRST RASTER FILE:\"\t\t\"SECOND RASTER FILE:\"\t\"AREA:\"\n")
printf("\"Cat#\"\t\"Category\"\t\t\"Cat#\"\t\"Category\"\t\n")
}
else
{
i=1
printf("\n") > "/dev/tty"
printf("\"FIRST RASTER FILE:\"\t\t\"AREA:\"\n")
printf("\"Cat#\"\t\"Category\"\t\n")
}
if (i==2)
{if ($1>0) {printf("%d\t\"%s\"\t\t%d\t\"%s\"\t\t%f\n",$1,$2,$3,$4,$5)}}
else
{if ($1>0) {printf("%d\t\"%s\"\t\t%f\n",$1,$2,$3,$4,$5)}}
}
{
if (i==2)
{if ($1>0) {printf("%d\t\"%s\"\t\t%d\t\"%s\"\t\t%f\n",$1,$2,$3,$4,$5)}}
else
{if ($1>0) {printf("%d\t\"%s\"\t\t%f\n",$1,$2,$3,$4,$5)}}
}
--------------------------------------------------------