[GRASS-dev] [GRASS GIS] #3431: r.mapcalculator script for QGIS processing

#3431: r.mapcalculator script for QGIS processing
----------------------------------------+-------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.2.3
Component: Python | Version: 7.2.2
Keywords: r.mapcalculator, r.mapcalc | CPU: Unspecified
Platform: Unspecified |
----------------------------------------+-------------------------
A wish received via personal email:

On Mon, Oct 23, 2017 at 10:06 AM, a QGIS developer wrote:
> it would be great to have the GRASS raster calculator back
> in Processing. Since GRASS7 r.mapcalculator
> been "lost" in Processing (because it also has not been ported from
> GRASS64 to 7, correct?) and the attempt to make r.mapcalc work was not
> completely successful (see: https://issues.qgis.org/issues/6894) If
> you could help with that it would be *much* appreciated!

The old parameters were:

https://grass.osgeo.org/grass64/manuals/r.mapcalculator.html

Apparently the interest in the QGIS community is high to get a wrapper
back as it used to exist in G6.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
--------------------------+----------------------------------------
  Reporter: neteler | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.4.0
Component: Python | Version: 7.2.2
Resolution: | Keywords: r.mapcalculator, r.mapcalc
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------------------
Changes (by neteler):

* milestone: 7.2.3 => 7.4.0

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
--------------------------+----------------------------------------
  Reporter: neteler | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: 7.2.2
Resolution: | Keywords: r.mapcalculator, r.mapcalc
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------------------

Comment (by Neteler):

How hard would it be to implement a simple solution?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:5&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: 7.2.2
Resolution: | Keywords: r.mapcalculator, r.mapcalc,
       CPU: | r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------
Changes (by wenzeslaus):

* keywords: r.mapcalculator, r.mapcalc => r.mapcalculator, r.mapcalc,
     r3.mapcalculator, r3.mapcalc, QGIS
* owner: grass-dev@… => wenzeslaus

Comment:

1) Here things I plan to use to get started implementing a simple
solution, i.e. what was in 6.4. Please, let me know if you know about
more.

*
source:grass/branches/releasebranch_6_4/scripts/r.mapcalculator/r.mapcalculator
*
source:grass/branches/releasebranch_6_4/scripts/r3.mapcalculator/r3.mapcalculator
* r67000 list maps flag (#2592)

2) Also, [https://issues.qgis.org/issues/6894#note-25 QGIS issue 6894,
note 25] says:

> Victor had created a new raster calculator using native QGIS
classes...But in QGIS 2.x, r.mapcalc is still a must needed algorithm

So will this be even used? This being useful for other programs would be a
good reason to have this.

3) Related to the generalization. What about other algebra modules, e.g.
t.rast.mapcalc? Do we need a wrapper for each of those?

4) Since the simple solution is keeping the functionality in a separate
module, I suggest to rethink the name of the module. r.mapcalc versus
r.mapcalculator​ might be little confusing.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:6&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: 7.2.2
Resolution: | Keywords: r.mapcalculator, r.mapcalc,
       CPU: | r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by wenzeslaus):

See sandbox for source code (Subversion history preserved, but it is a
complete rewrite anyway):

source:sandbox/wenzeslaus/r.mapcalculator (r73642)

{{{
Usage:
  r.mapcalculator [-sqc] expression=string [a=name] [b=name] [c=name]
    [d=name] [e=name] [f=name] output=value [seed=value] [--help]
    [--verbose] [--quiet] [--ui]

Flags:
   -s Generate random seed (result is non-deterministic)
   -q Quote the map names
   -c Case sensitive variable names

Parameters:
   expression Formula (e.g. A-B or A*C+B)
            a A
            b B
            c C
            d D
            e E
            f F
       output Name for output raster map
         seed Seed for rand() function
}}}

{{{
r.mapcalculator expression="0" output=zeros
r.mapcalculator expression="1" output=ones
r.mapcalculator expression="2" output=twos
r.mapcalculator expression="(A * B) / 2 + 3 * C" a=zeros b=ones c=twos
output=result2
}}}

If you don't have sandbox repo, you can install also using:

{{{
g.extension r.mapcalculator
url=https://trac.osgeo.org/grass/browser/sandbox/wenzeslaus/r.mapcalculator
}}}

I tried to cover in the documentation what are the differences to 5/6
version and r.mapcalc. Let me know what you think!

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:7&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: 7.2.2
Resolution: | Keywords: r.mapcalculator, r.mapcalc,
       CPU: | r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by neteler):

Great work! Successfully tested by Giovanni Manghi in QGIS (reported to me
via personal email).

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:8&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: 7.2.2
Resolution: | Keywords: r.mapcalculator, r.mapcalc,
       CPU: | r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by neteler):

Replying to [comment:6 wenzeslaus]:
> 4) Since the simple solution is keeping the functionality in a separate
module, I suggest to rethink the name of the module. r.mapcalc versus
r.mapcalculator​ might be little confusing.

How about: r.mapcalc.simple
?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:9&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: 7.2.2
Resolution: | Keywords: r.mapcalculator, r.mapcalc,
       CPU: | r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by wenzeslaus):

Replying to [comment:9 neteler]:
> Replying to [comment:6 wenzeslaus]:
> > 4) Since the simple solution is keeping the functionality in a
separate module, I suggest to rethink the name of the module. r.mapcalc
versus r.mapcalculator​ might be little confusing.
>
> How about: r.mapcalc.simple ?

This works for me. It is to certain extent applicable to other modules, it
is similar to the names of pseudo-modules in QGIS, and we can call the
raster algebra in this module a ''simple raster algebra'' or a
''simplified raster algebra''.

5) We need test for moving this to the core.

6) Are we backporting it to 7.6?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:10&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: 7.2.2
Resolution: | Keywords: r.mapcalculator, r.mapcalc,
       CPU: | r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by neteler):

Replying to [comment:10 wenzeslaus]:
> Replying to [comment:9 neteler]:
> > How about: r.mapcalc.simple ?
>
> This works for me. It is to certain extent applicable to other modules,
it is similar to the names of pseudo-modules in QGIS, and we can call the
raster algebra in this module a ''simple raster algebra'' or a
''simplified raster algebra''.

Yes, fine.

> 5) We need test for moving this to the core.

Please do :slight_smile:

> 6) Are we backporting it to 7.6?

Yes, please. It is requested frequently and will not break anything.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:11&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: 7.2.2
Resolution: | Keywords: r.mapcalculator, r.mapcalc,
       CPU: | r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by PedroNGV):

Replying to [comment:11 neteler]:
> > 6) Are we backporting it to 7.6?
>
> Yes, please. It is requested frequently and will not break anything.

Hi all,

Can it be backported to 7.4 also? Ir would be good to use with QGIS 2.18.

Thanks!

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:12&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: 7.2.2
Resolution: | Keywords: r.mapcalculator, r.mapcalc,
       CPU: | r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by hellik):

Replying to [comment:12 PedroNGV]:
> Replying to [comment:11 neteler]:
> > > 6) Are we backporting it to 7.6?
> >
> > Yes, please. It is requested frequently and will not break anything.
>
> Hi all,
>
> Can it be backported to 7.4 also? It would be good to use with QGIS
2.18.
>
> Thanks!

what is the reason not to use QGIS 3.x? it's pretty stable now.

the focus of GRASS will be in the next step of releases, See

https://lists.osgeo.org/pipermail/grass-dev/2018-November/090600.html

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:13&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: 7.2.2
Resolution: | Keywords: r.mapcalculator, r.mapcalc,
       CPU: | r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by PedroNGV):

Replying to [comment:13 hellik]:
> Replying to [comment:12 PedroNGV]:
> > Replying to [comment:11 neteler]:
> > > > 6) Are we backporting it to 7.6?
> > >
> > > Yes, please. It is requested frequently and will not break anything.
> >
> > Hi all,
> >
> > Can it be backported to 7.4 also? It would be good to use with QGIS
2.18.
> >
> > Thanks!
>
> what is the reason not to use QGIS 3.x? it's pretty stable now.
>
> the focus of GRASS will be in the next step of releases, See
>
> https://lists.osgeo.org/pipermail/grass-dev/2018-November/090600.html
>
>

QGIS 2.18 will be the LTR version until 22-02-2019. Besides that, as much
of QGIS plugins were not yet updated to Python 3 and so, to QGIS 3, it is
expected that QGIS 2.18 keeps being used for quite some time.

But as GRASS roadmap is pointing 7.6 final release to the end of this
year, that should be enough to introduce that version in QGIS 2.18!

Thanks for the info about the release roadmap!

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:14&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: 7.2.2
Resolution: | Keywords: r.mapcalculator, r.mapcalc,
       CPU: | r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by neteler):

Replying to [comment:10 wenzeslaus]:
> 5) We need test for moving this to the core.

Test case added in r73751.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:15&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: 7.2.2
Resolution: | Keywords: r.mapcalculator, r.mapcalc,
       CPU: | r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by neteler):

If there are no objections, I'll move the r.mapcalculator in the sandbox
SVN to trunk, renaming it to `r.mapcalc.simple`

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:16&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: 7.2.2
Resolution: | Keywords: r.mapcalculator, r.mapcalc,
       CPU: | r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by martinl):

Replying to [comment:16 neteler]:
> If there are no objections, I'll move the r.mapcalculator in the sandbox
SVN to trunk, renaming it to `r.mapcalc.simple`

+1

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:17&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: svn-trunk
Resolution: | Keywords: r.mapcalc.simple, r.mapcalculator,
       CPU: | r.mapcalc, r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------
Changes (by neteler):

* keywords: r.mapcalculator, r.mapcalc, r3.mapcalculator, r3.mapcalc, QGIS
     =>
     r.mapcalc.simple, r.mapcalculator, r.mapcalc, r3.mapcalculator,
     r3.mapcalc, QGIS
* version: 7.2.2 => svn-trunk

Comment:

Replying to [comment:16 neteler]:
> If there are no objections, I'll move the r.mapcalculator in the sandbox
SVN to trunk, renaming it to `r.mapcalc.simple`

Moved to trunk in r73791. Please test.

Keeping open for backport.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:18&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: svn-trunk
Resolution: | Keywords: r.mapcalc.simple, r.mapcalculator,
       CPU: | r.mapcalc, r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by martinl):

In [changeset:"73794" 73794]:
{{{
#!CommitTicketReference repository="" revision="73794"
r.mapcalc.simple: more guisections, description cosmetics, see #3431
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:19&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: svn-trunk
Resolution: | Keywords: r.mapcalc.simple, r.mapcalculator,
       CPU: | r.mapcalc, r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by martinl):

Any idea where to put to the menu? `Raster -> Simplified raster map
calculator`?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:20&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: svn-trunk
Resolution: | Keywords: r.mapcalc.simple, r.mapcalculator,
       CPU: | r.mapcalc, r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by neteler):

Replying to [comment:18 neteler]:
> Keeping open for backport.

backported in r73803 (relbranch76) and r73804 (relbranch74)

Open: menu entry

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:21&gt;
GRASS GIS <https://grass.osgeo.org>

#3431: r.mapcalculator script for QGIS processing
-------------------------+-------------------------------------------------
  Reporter: neteler | Owner: wenzeslaus
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.6.0
Component: Python | Version: svn-trunk
Resolution: | Keywords: r.mapcalc.simple, r.mapcalculator,
       CPU: | r.mapcalc, r3.mapcalculator, r3.mapcalc, QGIS
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by martinl):

Menu entry added in r73829, see [[Image(mapcalc-menu-entry.png)]]

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3431#comment:22&gt;
GRASS GIS <https://grass.osgeo.org>