[GRASS-dev] Default content for the "answer" to G_OPT_F_INPUT

Nikos Alexandris nik at nikosalexandris.net
Wed Apr 18 02:17:26 PDT 2018


* Helmut Kudrnovsky <hellik at web.de> [2018-04-17 07:40:59 -0700]:

>NikosAlexandris wrote
>> Yet my intention was/is to use a hardcoded string of rules. Not a path to
>> a file.
>>
>> It appears the only option is to document, the rules, and suggest a copy
>> and paste in to the corresponding field.
>>
>> Can the parser be extended in this regard with yet another option? Perhaps
>> I missed some existing option (?).
>
>https://trac.osgeo.org/grass/browser/grass-addons/grass7/vector/v.habitat.dem/v.habitat.dem.py#L568
>
>in this script I write out a text file for a predefined color rule and later
>on
>
>https://trac.osgeo.org/grass/browser/grass-addons/grass7/vector/v.habitat.dem/v.habitat.dem.py#L579
>
>I use it. it's an ugly hack, maybe you can use it without writing a text
>file.

Helmut,

do you need to write out the rules to a file? If not, you may do
something like:

# set rules as a string

POTENTIAL_COLORS = """ # Cubehelix color table generated using:
#   r.colors.cubehelix -dn ncolors=3 map=recreation_potential nrotations=0.33 gamma=1.5 hue=0.9 dark=0.3 output=recreation_potential.colors
0.000% 55:29:66
33.333% 55:29:66
33.333% 157:85:132
66.667% 157:85:132
66.667% 235:184:193
100.000% 235:184:193"""

# shortcuts
from grass.pygrass.modules.shortcuts import raster as r

# (re-)use later in the script
r.colors(map=recreation_potential, rules='-', stdin = POTENTIAL_COLORS)

Nikos
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20180418/f9393f23/attachment.sig>


More information about the grass-dev mailing list