[GRASSLIST:5946] Re: reclass imported area files: more awk tricks
Ezra Glenn
eglenn at mcgregorlaw.com
Wed Apr 2 10:17:19 EST 2003
This seems somewhat similar to a sed script I've been using, provided by
Michel Wurtz, I believe, that takes the desired dig_cats file as input
for a v.reclass (or r.reclass). The basic syntax is something like:
sed -e '1,4d' -e 's/:/=/' < desired dig_cats_file | v.reclass input=map
output=map.reclass_attribute_name
(The first half of the sed expression strips off the dig_cats header
lines, the second half changes the colons in the file to "=", which is
just the syntax v.reclass (or r.reclass) wants.
Ezra Glenn, AICP
Land Use & Environmental Planner
McGregor & Associates, P.C.
60 Temple Place, Suite 410
Boston, MA 02111
phone: 617.338.6464 x118
fax: 617.338.0737
email: eglenn at mcgregorlaw.com
web: www.mcgregorlaw.com
----
cheg01 at attbi.com wrote:
> 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