auto labelling
Lars Schylberg
larss at fmi.kth.se
Tue Jul 27 10:05:21 EDT 1993
> Can GRASS do this? I meant to label areas
> either in vect or rast by pulling out the
> corresponding cats and drawing them on top
> of the areas.
>
> --Xin
> zhuang at access.digex.com
I wrote a little script that labels raster areas a couple of months ago.
The script doesn't check if the label falls inside the polygon or if there is
overlap of the labels. It just computes the mean coordinate for each area.
The input raster map should be a map that is a result from r.clump. Well this
script has worked quite well for my purpose. The result is a site list with label
coordinates and p.map output. I have included the script below.
Just note that it uses gawk instead of awk.
Have fun.
Lars
Lars Schylberg Email: larss at fmi.kth.se
Dept. of Geodesy and Photogrammetry
Royal Institute of Technology (KTH) Tel. +46 8 790 86 33
S-100 44 STOCKHOLM, SWEDEN Fax. +46 8 790 66 10
---- cut here -------
#!/bin/sh
#
# label.obj.sh
#
# Author: Lars Schylberg ( larss at fmi.kth.se )
# Department of Photogrammetry
# Royal Inst. of Technolgy
# Stockholm, Sweden
#
# Date: 930510
# History of changes:
#
#--------------------------------------------------------------------------
# Check if GRASS is running
#
test "$GISRC" || echo "GRASS is not running" || exit 2
#----------------------------------------------------------------------------
#
# Evaluate arguments
#
if [ $# != 2 ]
then
echo
echo Usage: `basename $0`
echo ' input=mapname '
echo ' sitefile=name '
echo
exit 1
fi
#
# Parse input arguments
#
for i do
case $i in
input*)
IN=`echo $i | sed s/input=//` ;;
in*)
IN=`echo $i | sed s/in=//` ;;
i*)
IN=`echo $i | sed s/i=//` ;;
sitefile=*)
OUT=`echo $i | sed s/sitefile=//` ;;
site=*)
OUT=`echo $i | sed s/site=//` ;;
si=*)
OUT=`echo $i | sed s/si=//` ;;
s=*)
OUT=`echo $i | sed s/s=//` ;;
*)
echo ""
echo "Unrecognized option: $i"
echo 'Options: input=mapname '
echo ' sitefile=name '
echo
exit 1
esac
done
#----------------------------------------------------------------
# Check the input arguments
eval `g.findfile element=cell file=$IN`
if [ ! "$file" ] ; then
echo "$IN - cell file not found"
exit 2
fi
eval `g.findfile element=site_lists file=$OUT`
if [ "$file" ] ; then
echo "$OUT - site list exist already "
exit 2
fi
#---------------------------------------------------------------
r.stats -1gz in=$IN | \
gawk '{ x[$3]+=$2 ; y[$3]+=$1; n[$3]++ } \
END { for ( i in n ) printf "%d|%d|%d\n", y[i]/n[i], x[i]/n[i], i }' \
> $LOCATION/site_lists/$OUT
# Create p.map input
echo "raster $IN" > ~/p.input.$$
echo "sites $OUT" >> ~/p.input.$$
echo "color black" >> ~/p.input.$$
echo "size 1" >> ~/p.input.$$
echo "desc y" >> ~/p.input.$$
echo "end" >> ~/p.input.$$
# run p.map
#p.select -q painter=ppm
p.select -q painter=preview
p.map input=~/p.input.$$
# ppmtopgm ~/paint.ppm | pgmtops -rle -scale 0.7 > $1.ps
rm -f ~/p.input.$$
More information about the grass-dev
mailing list