Feature request #10443

Better documentation on how to use lettering in SAGA Raster calculator

Added by Pedro Venâncio almost 10 years ago. Updated about 6 years ago.

Status:Closed
Priority:Low
Assignee:Victor Olaya
Category:Processing/SAGA
Pull Request or Patch supplied:No Resolution:fixed/implemented
Easy fix?:No Copied to github as #:18855

Description

new description:

see #10443-3

Description
The Grid Calculator calculates a new grid based on existing grids and a mathematical formula. The grid variables are single characters which correspond in alphabetical order to the grid list order ('a' = first grid, 'b' = second grid, ...)
Alternatively you can address with letter 'g' followed by position index (g1, g2, g3, ...). Grids from other systems are addressed similarly, just using letter 'h' (h1, h2, h3, ...)

old description:
I found a problem in Raster calculator, when using the g1, g2, gx format in the Formula. Using a, b​​, ..., it works.

I attach sample data and log info.

- FORMULA "ifelse(eq(g2,1),1,g1)":

SAGA execution commands
io_gdal 0 -TRANSFORM -INTERPOL 0 -GRIDS "/tmp/processing/5b521b3c40614cf0a236986402767fde/probabilidade3.sgrd" -FILES "/home/pedro/EUQGIS2014/workshop_processing/resultados/probabilidade_3.tif" 
io_gdal 0 -TRANSFORM -INTERPOL 0 -GRIDS "/tmp/processing/8a1b5f9633af4617b183fc5ca54fb64c/somatorio.sgrd" -FILES "/home/pedro/EUQGIS2014/workshop_processing/resultados/somatorio.tif" 
grid_calculus "Grid Calculator" -GRIDS "/tmp/processing/5b521b3c40614cf0a236986402767fde/probabilidade3.sgrd" -XGRIDS "/tmp/processing/8a1b5f9633af4617b183fc5ca54fb64c/somatorio.sgrd" -FORMULA "ifelse(eq(g2,1),1,g1)" -RESULT "/home/pedro/EUQGIS2014/workshop_processing/resultados/probabilidade_4_teste.tif.sgrd" 
io_gdal 1 -GRIDS "/home/pedro/EUQGIS2014/workshop_processing/resultados/probabilidade_4_teste.tif.sgrd" -FORMAT 1 -TYPE 0 -FILE "/home/pedro/EUQGIS2014/workshop_processing/resultados/probabilidade_4_teste.tif" 

SAGA execution console output
_____________________________________________

#####   ##   #####    ##
###     ###  ##       ###
###   # ## ##  #### # ##
### ##### ##    # #####
##### #   ##  ##### #   ##
_____________________________________________

_____________________________________________
library path:    /usr/lib/saga/libio_gdal.so
library name:    Import/Export - GDAL/OGR
module name :    GDAL: Import Raster
author      :    O.Conrad (c) 2007 (A.Ringeler)
_____________________________________________

Parameters

Grids: No objects
Files: "/home/pedro/EUQGIS2014/workshop_processing/resultados/probabilidade_3.tif" 
Transformation: yes
Interpolation: Nearest Neighbor

loading: /home/pedro/EUQGIS2014/workshop_processing/resultados/probabilidade_3.tif
Driver: /home/pedro/EUQGIS2014/workshop_processing/resultados/probabilidade_3.tif/
Cells: x 351, y 558
Bands: 1
Transformation x' = 72601.347778 + x * 80.012074 + y * 0.000000
Transformation y' = 146231.038994 + x * 0.000000 + y * -80.012074
loading band [1/1]

Inconsistency detected by ld.so: dl-close.c: 762: _dl_close: Assertion `map->l_init_called' failed!
_____________________________________________

#####   ##   #####    ##
###     ###  ##       ###
###   # ## ##  #### # ##
### ##### ##    # #####
##### #   ##  ##### #   ##
_____________________________________________

_____________________________________________
library path:    /usr/lib/saga/libio_gdal.so
library name:    Import/Export - GDAL/OGR
module name :    GDAL: Import Raster
author      :    O.Conrad (c) 2007 (A.Ringeler)
_____________________________________________

Parameters

Grids: No objects
Files: "/home/pedro/EUQGIS2014/workshop_processing/resultados/somatorio.tif" 
Transformation: yes
Interpolation: Nearest Neighbor

loading: /home/pedro/EUQGIS2014/workshop_processing/resultados/somatorio.tif
Driver: /home/pedro/EUQGIS2014/workshop_processing/resultados/somatorio.tif/
Cells: x 351, y 558
Bands: 1
Transformation x' = 72601.347778 + x * 80.012074 + y * 0.000000
Transformation y' = 146231.038994 + x * 0.000000 + y * -80.012074
loading band [1/1]

Inconsistency detected by ld.so: dl-close.c: 762: _dl_close: Assertion `map->l_init_called' failed!
Error: error in formula: ifelse(eq(g2,1),1,a)
Error: executing module [Grid Calculator]
_____________________________________________

#####   ##   #####    ##
###     ###  ##       ###
###   # ## ##  #### # ##
### ##### ##    # #####
##### #   ##  ##### #   ##
_____________________________________________

_____________________________________________
library path:    /usr/lib/saga/libgrid_calculus.so
library name:    Grid - Calculus
module name :    Grid Calculator
author      :    Copyrights (c) 2003 by Andre Ringeler
_____________________________________________

Load grid: /tmp/processing/5b521b3c40614cf0a236986402767fde/probabilidade3.sgrd...

Load grid: /tmp/processing/8a1b5f9633af4617b183fc5ca54fb64c/somatorio.sgrd...

Parameters

Grid system: 80.012074; 351x 558y; 72641.353815x 101624.307639y
Grids: 1 object (probabilidade3)
Grids from different Systems: 1 object (somatorio)
Result: Result
Formula: ifelse(eq(g2,1),1,g1)
Name: Calculation
Take Formula: no
Use NoData: no
Data Type: 4 byte floating point number

Inconsistency detected by ld.so: dl-close.c: 762: _dl_close: Assertion `map->l_init_called' failed!
Error: Grid file could not be opened.
Error: executing module [GDAL: Export Raster]
_____________________________________________

#####   ##   #####    ##
###     ###  ##       ###
###   # ## ##  #### # ##
### ##### ##    # #####
##### #   ##  ##### #   ##
_____________________________________________

_____________________________________________
library path:    /usr/lib/saga/libio_gdal.so
library name:    Import/Export - GDAL/OGR
module name :    GDAL: Export Raster
author      :    O.Conrad (c) 2007
_____________________________________________

Load grid: /home/pedro/EUQGIS2014/workshop_processing/resultados/probabilidade_4_teste.tif.sgrd...
failed
GDAL: Export Raster: could not initialize data objects
Inconsistency detected by ld.so: dl-close.c: 762: _dl_close: Assertion `map->l_init_called' failed!

- FORMULA "ifelse(eq(b,1),1,a)"

SAGA execution commands
grid_calculus "Grid Calculator" -GRIDS "/tmp/processing/5b521b3c40614cf0a236986402767fde/probabilidade3.sgrd" -XGRIDS "/tmp/processing/8a1b5f9633af4617b183fc5ca54fb64c/somatorio.sgrd" -FORMULA "ifelse(eq(b,1),1,a)" -RESULT "/home/pedro/EUQGIS2014/workshop_processing/resultados/probabilidade_4_teste.tif.sgrd" 
io_gdal 1 -GRIDS "/home/pedro/EUQGIS2014/workshop_processing/resultados/probabilidade_4_teste.tif.sgrd" -FORMAT 1 -TYPE 0 -FILE "/home/pedro/EUQGIS2014/workshop_processing/resultados/probabilidade_4_teste.tif" 

SAGA execution console output
_____________________________________________

#####   ##   #####    ##
###     ###  ##       ###
###   # ## ##  #### # ##
### ##### ##    # #####
##### #   ##  ##### #   ##
_____________________________________________

_____________________________________________
library path:    /usr/lib/saga/libgrid_calculus.so
library name:    Grid - Calculus
module name :    Grid Calculator
author      :    Copyrights (c) 2003 by Andre Ringeler
_____________________________________________

Load grid: /tmp/processing/5b521b3c40614cf0a236986402767fde/probabilidade3.sgrd...

Load grid: /tmp/processing/8a1b5f9633af4617b183fc5ca54fb64c/somatorio.sgrd...

Parameters

Grid system: 80.012074; 351x 558y; 72641.353815x 101624.307639y
Grids: 1 object (probabilidade3)
Grids from different Systems: 1 object (somatorio)
Result: Result
Formula: ifelse(eq(b,1),1,a)
Name: Calculation
Take Formula: no
Use NoData: no
Data Type: 4 byte floating point number

Inconsistency detected by ld.so: dl-close.c: 762: _dl_close: Assertion `map->l_init_called' failed!
_____________________________________________

#####   ##   #####    ##
###     ###  ##       ###
###   # ## ##  #### # ##
### ##### ##    # #####
##### #   ##  ##### #   ##
_____________________________________________

_____________________________________________
library path:    /usr/lib/saga/libio_gdal.so
library name:    Import/Export - GDAL/OGR
module name :    GDAL: Export Raster
author      :    O.Conrad (c) 2007
_____________________________________________

Load grid: /home/pedro/EUQGIS2014/workshop_processing/resultados/probabilidade_4_teste.tif.sgrd...

Parameters

Grid system: 80.012074; 351x 558y; 72641.353815x 101624.307639y
Grid(s): 1 object (probabilidade_4_teste.tif)
File: /home/pedro/EUQGIS2014/workshop_processing/resultados/probabilidade_4_teste.tif
Format: GeoTIFF
Data Type: match input data
Set Custom NoData: no
NoData Value: 0.000000
Creation Options:

Band 1

This only happens when you use more than one raster in the formula.

And it is a regression, as it only happens in the master version. With 2.2.0-2 which is in plugins, it works ok.

As it is a regression, I put it as blocker.

probabilidade_3.tif (768 KB) Pedro Venâncio, 2014-06-03 02:33 PM

somatorio.tif (768 KB) Pedro Venâncio, 2014-06-03 02:33 PM

History

#1 Updated by Giovanni Manghi almost 10 years ago

  • Priority changed from Severe/Regression to Normal

Hi Pedro,

I made a few tests and the result is that is a SAGA issue.

In SAGA 2.10 grid calculator there is now a -XGRIDS parameter that is now used by processing in QGIS master (it wasn't used in 2.2).

With this parameter and the g1,g2...gx format SAGA fails to create the output. If using a,b... x it works.

I'm not sure that we should leave this open.

testes

works:

saga_cmd grid_calculus "Grid Calculator" -GRIDS "r1saga.sgrd" -XGRIDS "r2saga.sgrd" -FORMULA "ifelse(eq(b,1),1,a)" -RESULT "RESULT.tif.sgrd"

does not work:

saga_cmd grid_calculus "Grid Calculator" -GRIDS "r1saga.sgrd" -XGRIDS "r2saga.sgrd" -FORMULA "ifelse(eq(g2,1),1,g1)" -RESULT "RESULT.tif.sgrd"

works:

saga_cmd grid_calculus "Grid Calculator" -GRIDS "r1saga.sgrd;r2saga.sgrd" -FORMULA "ifelse(eq(g2,1),1,g1)" -RESULT "RESULT2.tif.sgrd"

#2 Updated by Victor Olaya almost 10 years ago

some explanation on this

We are now using the XGRIDS parameter, which allows saga to use rasters with a differente grid system (extent + grid resolution), so SAGA takes care of that and Processing does not have to do the resampling (which was buggy and error-prone). I think that, if the g1,g2... syntax cannot be used now, it should be documented, and we should assume that as a minor problem, which is worth considering the stability what we gain by skipping the resampling phase

Hope this helps

#3 Updated by Pedro Venâncio almost 10 years ago

Hi Giovanni and Victor,

That's it. I've been searching, and to refer the XGRIDS, we should use the letter h:

Description
The Grid Calculator calculates a new grid based on existing grids and a mathematical formula. The grid variables are single characters which correspond in alphabetical order to the grid list order ('a' = first grid, 'b' = second grid, ...)
Alternatively you can address with letter 'g' followed by position index (g1, g2, g3, ...). Grids from other systems are addressed similarly, just using letter 'h' (h1, h2, h3, ...)

We need to put this in the Help tab.

The easiest is to use the letters a, b, c, ..., but in this case I get a question, and assuming that we have more variables than the letters of the alphabet, what do we do?

Another doubt Victor, Processing analyzes the input grids and checks if they have different systems, placing the grids of different systems in XGRIDS and equals to the first grid in GRIDS?
And if there are more grids in different systems than two? All grids in different systems go for XGRIDS?

And finally, my biggest question, what is the operation that is performed with grids that are in XGRIDS? Resampling? With which algorithm?

Thanks!

#4 Updated by Giovanni Manghi almost 10 years ago

Another doubt Victor, Processing analyzes the input grids and checks if they have different systems, placing the grids of different systems in XGRIDS and equals to the first grid in GRIDS?

it seems to me that thr first raster goes to grids and the others to xgrids, even if they have the same crs.

#5 Updated by Pedro Venâncio almost 10 years ago

it seems to me that thr first raster goes to grids and the others to xgrids, even if they have the same crs.

It is not the CRS Giovanni, but the grid system. But in reality that is what it does:

Grid system: 79.945794; 351x 558y; 72641.353815x 101624.307639y
Grids: 1 object (aa2003)
Grids from different Systems: 2 objects (aa2005, aa2004)
Result: Result
Formula: a+b+c
Name: Calculation
Take Formula: no
Use NoData: no
Data Type: 4 byte floating point number

even though all have the same grid system. But as far as I can think, there should be no inconvenience in it, because all of them have the same extent and grid resolution.

Anyway, I wonder how SAGA makes the adjustment, because if it does the resampling of XGRIDS, in the above situation, at least it makes unnecessary processing.

#6 Updated by Jürgen Fischer almost 10 years ago

  • Target version changed from Version 2.4 to Future Release - High Priority

#7 Updated by Alexander Bruy over 9 years ago

  • Category changed from 94 to Processing/SAGA

#8 Updated by Giovanni Manghi almost 9 years ago

  • Tracker changed from Bug report to Feature request
  • Target version changed from Future Release - High Priority to Future Release - Lower Priority
  • Priority changed from Normal to Low
  • Subject changed from Raster calculator error using gx in formula to Better documentation on how to use lettering in SAGA Raster calculator

#9 Updated by Giovanni Manghi almost 7 years ago

  • Easy fix? set to No

#10 Updated by Jürgen Fischer over 6 years ago

  • Description updated (diff)

#11 Updated by Pedro Venâncio over 6 years ago

  • Status changed from Open to Closed

This feature request was already applied. The description is very clear now:

It requires a base layer, and a set of additional layers. The base layer is identified as "a" in the formula, while the additional layers are identified as "b, c, d...", using the order in which they appear in the multiple selection dialog.

Thanks!

#12 Updated by Giovanni Manghi about 6 years ago

  • Resolution set to fixed/implemented

Also available in: Atom PDF