[GRASS-dev] Re: r.neighbors modification

Hamish hamish_nospam at yahoo.com
Mon Nov 27 18:38:42 EST 2006


Martin Wegmann wrote:
> > > you might combine all those flags into one option,
> > > #%option
> > > #% key: size
> > > #% type: integer
> > > #% description: compute var & avg of NxN ring
> > > #% options: 3,5,7,9,11
> > > #% answer: 5
> > > #% required : no
> > > #%END
> >
> > very good - implemented
> 
> is it possible to add a flag when all sizes shall be computed?
> 
> I tried a bit with || statements in the if-then part, but had no luck
> so far. 
> 
> any ideas?


from the parser standpoint:

#% options: 3,5,7,9,11
#% multiple: yes


then you can have e.g. a 2 cell wide ring with

size=5,7


[There are two options here: multiple individual sizes or combination
sizes. The rest talks about multiple sizes within the same map as that's
more interesting to me.]

[Will r.mfilter do the same as the output _avg map?]


from the g.parser help page:
NOTES
An option can be instructed to allow multiple inputs by adding the
following line: 

#% multiple : yes

While this will only directly change the Usage section of the help
screen, the option's environmental string may be easily parsed from
within a script. For example, individual comma separated identities for
an option named "input" can be parsed with the following Bash shell
code: 

IFS=,
for opt in $GIS_OPT_INPUT ; do
    ... "$opt"
done

I am not sure how to do the r.mapcalc part then, maybe >> append each
mapcalc ring size rules to a file, then run r.mapcalc redirecting the
conglomorate file to stdin,

r.mapcalc < $TMP.rulesfile

it would take too much to fully paste all combinations in to the script
without some sort of dynamic rule building.




if you want multiple individual maps, set DO_5=0, DO_7=1 in the loop
and then test for that, e.g.:

DO_3=0
DO_5=0
DO_7=0
# ...

IFS=,
for size in $GIS_OPT_SIZE ; do
  if [ $size -eq 3 ] ; then
    DO_3=1
  fi
  if [ $size -eq 5 ] ; then
    DO_5=1
  fi
  if [ $size -eq 7 ] ; then
    DO_7=1
  fi
# ...

done

(or something like that)


Hamish




More information about the grass-dev mailing list