[GRASSLIST:5940] reclass imported area files: more awk tricks

cheg01 at attbi.com cheg01 at attbi.com
Tue Apr 1 21:04:59 EST 2003


The behavior of Grass 5.0 when importing .e00 area files has caused me some
heartache the past. I always end up with thousands of areas with unique
type numbers assigned in dig_cats, even though many areas share the same
text label value. I have come up with an awk script and a command line that
will automatically generate reclass input files to create maps that use the
text label to identify type instead of the arbitrary number assigned by
grass at import time.

First cd to the relevant dig_cats directory.
If your vector file name is $MAP, the command line to create the reclass
file is:

              sort -k 2 -t : $MAP | awk -f reclass.awk > reclass


To fix the vector file, the commands are:

cat reclass | v.reclass -d type=area input=$MAP output=`echo $MAP`_reclass;
v.support `echo $MAP`_reclass;

The same basic process works for raster files if you do it the "cats"
directory and use "r.reclass input=$MAP output=`echo $MAP`_reclass" instead
of v.reclass.

The reclass.awk file is:

##########################################
#   reclass.awk
#   input must be sorted by cat label before running this!
##########################################

 BEGIN { FS=":" ; ind=0 }

/^[#%A-Za-z0]../ { next }

/^[1-9]../ {
if (ind==0) {
   test = $2
   ind++
}

if ($2 != test) ind++
test=$2
printf("%d=%d %s\n",$1,ind,$2)
}
##########################################




More information about the grass-user mailing list