On Mon, 2008-03-17 at 22:42 -0700, Hamish wrote:
Nikos Alexandris wrote:
> I am having a hard time to figure out how I could avoid to enter
> interactively new labels for a raster map. I've been reading the last 2
> hours in the list, in GRASS-Book.
>
> Any directions highly appreciated.
....
> Question: IS there a way to add these labels to the raster map
> non-interactively?
In GRASS 6.3 use 'r.category rules=filename'. See the help page.
(new option added in October; may not have filtered into all the docs
yet)
Yep, this is what I was trying. A fragment from my history (yesterday
before posting) confirms my attempts - I really tried hard... 
history | grep r.cat
95 r.cats help
96 r.category help
97 r.category
98 r.category map=glc2000_eu cats=glc2000_legend fs=|
99 r.category map=glc2000_eu cats=glc2000_legend fs="|"
100 r.category map=glc2000_eu cats=glc2000_legend
286 r.category
290 r.cats map=glc2000_eu rules=`db.select glc2000_legend`
294 r.cats map=glc2000_eu rules=`db.select -c glc2000_legend`
296 r.cats map=glc2000_eu fs=| rules=`db.select -c glc2000_legend`
302 r.cats map=glc2000_eu fs=| rules=`db.select -c glc2000_legend |
tr "|" ":"`
304 r.cats map=glc2000_eu rules=`db.select -c glc2000_legend | tr "|"
":"`
305 r.cats map=glc2000_eu rules=`db.select -c glc2000_legend`
306 r.cats map=glc2000_eu fs="|" rules=`db.select -c glc2000_legend`
307 r.cats map=glc2000_eu fs=| rules=`db.select -c glc2000_legend`
308 r.cats map=glc2000_eu fs=| rules=`db.select -c glc2000_legend`
--v
309 r.cats map=glc2000_eu fs=| rules=`db.select -c glc2000_legend`
--V
310 r.cats --v map=glc2000_eu fs=| rules=`db.select -c
glc2000_legend`
316 r.cats glc2000_eu
In GRASS 6.2 you can put a similar ASCII text file in the $MAPSET/cats/
dir, see the Programmers' manual or another map to get the format.
> *Looking at the imported table
> db.select -c glc2000_legend
> 1|Tree Cover, broadleaved, evergreen
> 2|Tree Cover, broadleaved, deciduous, closed
> 3|Tree Cover, broadleaved, deciduous, open
> 4|Tree Cover, needle-leaved, evergreen
> 5|Tree Cover, needle-leaved, deciduous
> 6|Tree Cover, mixed leaf type
> 7|Tree Cover, regularly flooded, fresh water
> 8|Tree Cover, regularly flooded, saline water
> 9|Mosaic: Tree Cover / Other natural vegetation
> 10|Tree Cover, burnt
> 11|Shrub Cover, closed-open, evergreen
> 12|Shrub Cover, closed-open, deciduous
> 13|Herbaceous Cover, closed-open
> 14|Sparse herbaceous or sparse shrub cover
> 15|Regularly flooded shrub and/or herbaceous cover
> 16|Cultivated and managed areas
> 17|Mosaic: Cropland / Tree Cover / Other natural vegetation
> 18|Mosaic: Cropland / Shrub and/or grass cover
> 19|Bare Areas
> 20|Water Bodies
> 21|Snow and Ice
> 22|Artificial surfaces and associated areas
> 23|Irrigated Agriculture
it is very close, just `tr '|' ':'` or `sed -e 's/|/:/'`.
Hopefully ":" in the label names won't cause a problem.
The result from both is the same:
r.category map=glc2000_eu rules=`db.select -c glc2000_legend | tr '|'
':'`
or
r.category map=glc2000_eu rules=`db.select -c glc2000_legend | sed -e
's/|/:/'`
output:
Sorry <Cover,> is not a valid option
Sorry <broadleaved,> is not a valid option
Sorry <evergreen> is not a valid option
Sorry <2:Tree> is not a valid option
Sorry <Cover,> is not a valid option
Sorry <broadleaved,> is not a valid option
Sorry <deciduous,> is not a valid option
Sorry <closed> is not a valid option
Sorry <3:Tree> is not a valid option
Sorry <Cover,> is not a valid option
Sorry <broadleaved,> is not a valid option
Sorry <deciduous,> is not a valid option
Sorry <open> is not a valid option
Sorry <4:Tree> is not a valid option
Sorry <Cover,> is not a valid option
Sorry <needle-leaved,> is not a valid option
Sorry <evergreen> is not a valid option
Sorry <5:Tree> is not a valid option
Sorry <Cover,> is not a valid option
Sorry <needle-leaved,> is not a valid option
Sorry <deciduous> is not a valid option
Sorry <6:Tree> is not a valid option
Sorry <Cover,> is not a valid option
Sorry <mixed> is not a valid option
Sorry <leaf> is not a valid option
Sorry <type> is not a valid option
Sorry <7:Tree> is not a valid option
Sorry <Cover,> is not a valid option
Sorry <regularly> is not a valid option
Sorry <flooded,> is not a valid option
Sorry <fresh> is not a valid option
Sorry <water> is not a valid option
Sorry <8:Tree> is not a valid option
[...]
Finally it worked like this:
1. db.select -c glc2000_legend | tr '|' ':' > glc2000_legend.csv
2. r.category map=glc2000_eu rules=glc2000_legend.csv
("TODO: Respect the fs= field separator setting for input rules.")
Also for GRASS 7 it would be nice to use a consistent fs for all modules,
instead of sometimes |,:,space, ...
Why not directly from the db.table(s)
Given that the category numbers and labels are there as they should be
(in a table imported in the data base), wouldn't it be nice to enable
attachment of such tables in a raster map?
Hamish
Cheers and THANKS!!!
Nikos