[GRASS-user] 6.4 vs 7.0

Hamish hamish_b at yahoo.com
Sat Jan 16 18:41:49 EST 2010

Hi Paolo,

> I have some scripts which perfectly work in GRASS 6.4
> whereas in GRASS 7.0 they give  problems.

that is to be expected. Compatibility is not guaranteed between major
versions. this frees us up to fix things which we were locked into

> Here some examples:
> r.mapcalc 'grid1=rand(1,10)' #works in GRASS 6.4;
> ## in 7.0 I need:
> r.mapcalc expr='grid1=rand(1,10)' –overwrite

r.mapcalc in GRASS 7 now uses the GRASS parser (for --help, --quiet, etc)
so now behaves like all other GRASS modules.

If you use "
  r.mapcalc "result = map * 4

it will work on both versions. Important is the space around the "=" so
that GRASS's parser doesn't try and match a "result=" option. See the
r.mapcalc man page in GRASS 7 for details. GRASS_VERBOSE can be passed
as an enviro variable as well.

> echo "UPDATE polyNoTopology \
>   SET label='poly$a' WHERE cat=$index" | db.execute ##works
> in GRASS 6.4; in 7.0 I need:
> echo "UPDATE polyNoTopology \
>   SET label='poly$a' WHERE cat=$index" | db.execute in=-

here "input=" has been set to be a required input. AFAIU this is so the
option appears on the first tab of the module GUI window ("Required").
I've complained about that before, so won't repeat myself, but what is
really needed IMO is a new item added somewhere to help order the GUI
sections so these GUI-at-the-expense-of-the-CLI hacks can be avoided.

> echo "5,3" | v.in.ascii out=point fs="," cat=0 --o # works
> perfectly in 6.4 but not in 7.0
> ## in 7.0 I have to create a file (perhaps, is there a
> better way?)
> echo "5,3">coord
> v.in.ascii input=coord out=point fs="," cat=0 --o
> Is there a rule of thumb for  this... new syntax ?

in general using "-" as the input filename should tell it to read from
stdin instead of a real file. If that doesn't work then it's a bug.
Support for this is slowly being added to grass 6.5svn, just because it
should, regardless of what happens with option=Required or no.
 (AFAIK input=- for stdin is an old unix tradition)

> (e.g. “no pipe at all”?)

that wouldn't be very nice.

> Do I have to test version (g.version) in all my (bash) scripts ?

If you intend to use them over multiple (major) versions, then Yes!

> (ok: perhaps python scripting should be a solution; I'm trying...)

fwiw, that won't help much if the module options change. I guess the
verbose and overwrite stuff will be automatically handled by the grass.py
package, and command line options passed as a single expression won't be
treated like an option, so yes actually python could help in some cases.
just be sure to use the grass.package and not just make system() calls.

note that grass 7 is still in development and will continue to change,
so any scripts written for gr7 today might not work tomorrow or in the
final release.



More information about the grass-user mailing list