[GRASSLIST:2916] Re: Reclassification problem (string with spaces) - solved

Thu Mar 11 22:55:51 EST 2004

```Thanks to the many (internal) e-mails of swlab at cornell.edu, I could
find a solution for the reclassification problem:

r.stats -l in=wr.sud.5.bd.r | cut -d" " -f2- | sort | uniq | awk
'{print (\$0 ": " NR)}' > wr.sud.5.bd.r.recl

\$0 represents the whole line, with -f2- we get all the columns starting
from #2.

cat wr.sud.5.bd.r.recl
Burned: 1
Burned but surviving: 2
Unburned: 3

r.stats -l in=wr.sud.5.bd.r fs=: | awk -F":" 'BEGIN{while((getline line
< "wr.sud.5.bd.r.recl") > 0){split(line,A,":");R[A[1]]=A[2] }}{print
\$1,"=",R[\$2],\$2}' > wr.sud.5.bd.r.recl2

The 'fs' option forces r.stats to use ':' as separator, -F":" forces
awk to use ':' as separator.

cat wr.sud.5.bd.r.recl2
34 =  3 Unburned
81 =  3 Unburned
87 =  3 Unburned
96 =  1 Burned
97 =  2 Burned but surviving
102 =  3 Unburned
...

cat wr.sud.5.bd.r.recl2 | r.reclass in=wr.sud.5.bd.r
out=wr.sud.5.bd.tmp.r

Christof

Department of Geography

On 11.03.2004, at 11:11, Christof Bigler wrote:

> Hi Grass list
>
> I encountered once again some problems with the reclassification of a
> raster map. The map has three category descriptions:
> "Burned", "Burned but surviving", "Unburned". The following problem
> occurs because of the spaces in "Burned but surviving".
>
> When I try to do the following:
> r.stats -l in=wr.sud.5.bd.r | cut -d" " -f2 | sort | uniq | awk
> '{print \$1,NR}' > wr.sud.5.bd.r.recl
>
> I get only the following two categories:
> Burned 1
> Unburned 2
>
> which is not a big problem, since I just have to add the missing
> category:
> Unburned 1
> Burned but surviving 2
> Burned 3
>
> I then write a new reclassification rule:
> r.stats -l in=wr.sud.5.bd.r | awk 'BEGIN{while((getline line <
> "wr.sud.5.bd.r.recl") > 0){split(line,A," ");R[A[1]]=A[2] }}{print
> \$1,"=",R[\$2],\$2}' > wr.sud.5.bd.r.recl2
>
> cat wr.sud.5.bd.r.recl2
> 34 = 1 Unburned
> 81 = 1 Unburned
> 87 = 1 Unburned
> 96 = 3 Burned
> 97 = 3 Burned
> 102 = 1 Unburned
> ...
>
> This looks ok, except of CAT_ID which should be "97 = 2 Burned but
> surviving". Again, I could change this manually, but this could be
> kind of tedious, particularly with long lists.
> Is there a way to prevent that strings with spaces between words are
> cut?
>
>
> Christof
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 2400 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/grass-user/attachments/20040311/774ccaf8/attachment.bin
```