Feature request #6893

GRASS r.null

Added by Pedro Venâncio over 11 years ago. Updated over 8 years ago.

Status:Closed
Priority:High
Assignee:Victor Olaya
Category:Processing/GRASS
Pull Request or Patch supplied:No Resolution:
Easy fix?:No Copied to github as #:16018

Description

Hi,

GRASS r.null (setnull / null) algorithm is not implemented in Sextante and I think that would be important.

This issue was raised a few days ago in ML:
http://osgeo-org.1560.n6.nabble.com/Any-tutorial-on-how-to-add-grass-modules-to-sextante-QGIS-td5019125.html

and I also noticed the problem reported by the author of that thread. The algorithm does not use the 'Output' argument, but applies the transformation directly into the original file.
http://grass.osgeo.org/grass64/manuals/r.null.html

So, if the 'Output' argument is used, GRASS gives error:

sextante.runalg("grass:r.val.to.null","/home/pedro/.qgis//sextante/tempdata/sagaconvertdatastoragetypee5ad8e68595349c8bea5762100865ced.tif",485,"250412.000646,322804.257331,400555.0,447300.0",0,None)

GRASS execution commands
g.proj -c proj4="+proj=tmerc +lat_0=39.66666666666666 +lon_0=1 +k=1 +x_0=200000 +y_0=300000 +ellps=intl +towgs84=-304.046,-60.576,103.64,0,0,0,0 +pm=lisbon +units=m +no_defs" 
r.external input="/home/pedro/.qgis//sextante/tempdata/sagaconvertdatastoragetypee5ad8e68595349c8bea5762100865ced.tif" band=1 output=tmp1355833349863 --overwrite -o
g.region n=447300.0 s=400555.0 e=322804.257331 w=250412.000646 res=24.9973262032
r.null map=tmp1355833349863 setnull=485 output=outputa0896271fc83405faac96aba445c5bdc --overwrite
g.region rast=outputa0896271fc83405faac96aba445c5bdc
r.out.gdal -c createopt="TFW=YES,COMPRESS=LZW" input=outputa0896271fc83405faac96aba445c5bdc output="/home/pedro/.qgis//sextante/tempdata/grassrvaltonullbcabc6b3ab254601bc1c47c24ba4a714.tif" 

GRASS execution console output
Cleaning up temporary files ...
Starting GRASS ...
Executing '/home/pedro/.qgis//sextante/grass_batch_job.sh' ...
Welcome to GRASS 6.4.2 (2012) 

GRASS_INFO_MESSAGE(4264,1): N.B. The default region was updated to the new projection, but if you have multiple mapsets g.region -d should be run in each to update the region from the default.
GRASS_INFO_END(4264,1)

GRASS_INFO_MESSAGE(4264,2): Projection information updated!
GRASS_INFO_END(4264,2)

GRASS_INFO_WARNING(4265,1): Over-riding projection check
GRASS_INFO_END(4265,1)

GRASS_INFO_MESSAGE(4265,2): Importing band 1 of 1...
GRASS_INFO_END(4265,2)

GRASS_INFO_MESSAGE(4265,3): Link to raster map <tmp1355833349863> created
GRASS_INFO_END(4265,3)
Desculpe, <output> não é um parâmetro válido

Descrição:
 Manages NULL-values of given raster map.

Palavras chave:
 raster, null data

Uso:
 r.null [-fincr] map=name [setnull=val[-val][,val[-val],...]]
   [null=value] [--verbose] [--quiet]

Flags:
  -f   Only do the work if the map is floating-point
  -i   Only do the work if the map is integer
  -n   Only do the work if the map doesn't have a NULL-value bitmap file
  -c   Create NULL-value bitmap file validating all data cells
  -r   Remove NULL-value bitmap file
 --v   Saída do módulo verbosa
 --q   Saída do módulo silenciosa

Parâmetros:
      map   Name of raster map for which to edit null file
  setnull   Lista de valores de célula para marcar como NULO
     null   O valor que substitui o valor nulo

GRASS_INFO_ERROR(4268,1): Raster map <outputa0896271fc83405faac96aba445c5bdc> not found
GRASS_INFO_END(4268,1)

GRASS_INFO_ERROR(4269,1): Raster map or group <outputa0896271fc83405faac96aba445c5bdc> not found
GRASS_INFO_END(4269,1)
Closing monitors ...
Cleaning up temporary files ...
Batch job '/home/pedro/.qgis//sextante/grass_batch_job.sh' (defined in GRASS_BATCH_JOB variable) was executed.
Goodbye from GRASS GIS
Cleaning up temporary files ...
Starting GRASS ...
Executing '/home/pedro/.qgis//sextante/grass_batch_job.sh' ...
Welcome to GRASS 6.4.2 (2012) 

GRASS_INFO_ERROR(4326,1): Raster map <outputa0896271fc83405faac96aba445c5bdc> not found
GRASS_INFO_END(4326,1)

GRASS_INFO_ERROR(4327,1): Raster map or group <outputa0896271fc83405faac96aba445c5bdc> not found
GRASS_INFO_END(4327,1)
Closing monitors ...
Cleaning up temporary files ...
Batch job '/home/pedro/.qgis//sextante/grass_batch_job.sh' (defined in GRASS_BATCH_JOB variable) was executed.
Goodbye from GRASS GIS

On the contrary, if 'Output' is not used, GRASS applies the transformation to the temporary 'Input' file, but that is not reflected in the original file.

sextante.runalg("grass:r.val.to.null","/home/pedro/Comunicacoes/Encontro_SMPC/Dados_Geograficos/MDT/mdt_rst_5_int_truncated.tif","500-600","250412.000646,322804.257331,400555.0,447300.0")

GRASS execution commands
g.proj -c proj4="+proj=tmerc +k=1 +lon_0=1 +no_defs +x_0=200000 +ellps=intl +nadgrids=/usr/share/proj/ptLX_e89.gsb +units=m +lat_0=39.66666666666666 +wktext +y_0=300000 +pm=lisbon" 
r.external input="/home/pedro/Comunicacoes/Encontro_SMPC/Dados_Geograficos/MDT/mdt_rst_5_int_truncated.tif" band=1 output=tmp13558497801810 --overwrite -o
g.region n=447300.0 s=400555.0 e=322804.257331 w=250412.000646 res=24.9973262032
r.null map=tmp13558497801810 setnull=500-600 --overwrite

GRASS execution console output
Cleaning up temporary files ...
Starting GRASS ...
Executing '/home/pedro/.qgis//sextante/grass_batch_job.sh' ...
Welcome to GRASS 6.4.2 (2012) 

GRASS_INFO_MESSAGE(6054,1): N.B. The default region was updated to the new projection, but if you have multiple mapsets g.region -d should be run in each to update the region from the default.
GRASS_INFO_END(6054,1)

GRASS_INFO_MESSAGE(6054,2): Projection information updated!
GRASS_INFO_END(6054,2)

GRASS_INFO_WARNING(6055,1): Over-riding projection check
GRASS_INFO_END(6055,1)

GRASS_INFO_MESSAGE(6055,2): Importing band 1 of 1...
GRASS_INFO_END(6055,2)

GRASS_INFO_MESSAGE(6055,3): Link to raster map <tmp13558497801810> created
GRASS_INFO_END(6055,3)

Closing monitors ...
Cleaning up temporary files ...
Batch job '/home/pedro/.qgis//sextante/grass_batch_job.sh' (defined in GRASS_BATCH_JOB variable) was executed.
Goodbye from GRASS GIS

How can this be solved? In my view, it would be better Sextante generate a new file with the transformation values applied, keeping the input file untouched.

Associated revisions

Revision 91e222e1
Added by Alexander Bruy over 8 years ago

Merge pull request #2781 from medspx/processing_grass7_rnull

[processing] add r.null GRASS7 algorithm (fix #6893)

History

#1 Updated by Pedro Venâncio about 11 years ago

  • Priority changed from Normal to High

I think the functions r.null.to (null parameter) and r.null.val (setnull parameter) are very important, so I raise the priority level of this feature request.

Thanks!

(Same request in #7199)

#2 Updated by Giovanni Manghi about 11 years ago

Hi Victor, sorry for bugging, just would like to know if there would be an easy way/workaround to get r.null in SEXTANTE. Cheers!

#3 Updated by Markus Neteler almost 11 years ago

Hi,

the fix will be easy - from your command list above you can see:

...
r.null map=tmp1355833349863 setnull=485 output=outputa0896271fc83405faac96aba445c5bdc --overwrite
^^^^^^^^^^^^^
...
GRASS_INFO_END(4265,3)
Desculpe, <output> não é um parâmetro válido
...
Uso:
r.null [-fincr] map=name [setnull=val[
...

There should be no "output" parameter as the map is updated in place for NULL values.

#4 Updated by Pedro Venâncio about 10 years ago

Hi Markus,

But Processing seems to request always an output parameter. How can we solve this and add this two important tools to Processing?

Thanks!

#5 Updated by Giovanni Manghi about 10 years ago

Pedro Venâncio wrote:

Hi Markus,

But Processing seems to request always an output parameter. How can we solve this and add this two important tools to Processing?

Thanks!

it has to be fixed processing side: any GRASS tool that modifies the input instead of creating a new output must be taken into account as a special case, and add the proper code. Another case is v.distance. It is not a huge amount of work, but still there is a bit to do.

#6 Updated by Giovanni Manghi over 9 years ago

  • Category deleted (59)
  • Project changed from 78 to QGIS Application

#7 Updated by Giovanni Manghi over 9 years ago

  • Category set to Processing/GRASS

#8 Updated by Médéric RIBREUX over 8 years ago

  • Status changed from Open to Feedback

Hello,

I would like to work on this feature request and I need some feedback about the implementation:

  • To respect Processing main design, an output is nearly required, particularly if you want to chain algorithms.
  • I imagine to have an output which will be the transformed input raster.
  • You can use setnull and null parameters together (using the two parameters at the same time under GRASS just works) and I think that it can be a real use case (set a bunch of values to null and then set all the null values to another one).
  • So, I would like to make just one algorithm with both parameters. But feel free to tell me your different use cases for having two tools (r.null.to and r.nul.setval).

Is there anything that I am missing ?

#9 Updated by Giovanni Manghi over 8 years ago

  • Status changed from Feedback to Open

Hi Médéric,

I would like to work on this feature request and I need some feedback about the implementation:

  • To respect Processing main design, an output is nearly required, particularly if you want to chain algorithms.
  • I imagine to have an output which will be the transformed input raster.
  • You can use setnull and null parameters together (using the two parameters at the same time under GRASS just works) and I think that it can be a real use case (set a bunch of values to null and then set all the null values to another one).
  • So, I would like to make just one algorithm with both parameters. But feel free to tell me your different use cases for having two tools (r.null.to and r.nul.setval).

Is there anything that I am missing ?

very nice to have someone takle this ticket, this is a much missing tool in Processing/GRASS that is available in native GRASS and the QGIS/GRASS plugin.

I'm note sure I understand your notes, anyway the issue here is "easy": most of GRASS tools produce an (new) output from inputs and parameters, but a few ones instead are modifying an input (a GRASS raster or vector), so not creating anything new. Processing can't handle this kind of tools out of the box. The other tool that works this way and we miss a lot is v.distance (there is also a ticket for that).

#10 Updated by Médéric RIBREUX over 8 years ago

  • Estimated time set to 6.00
  • Status changed from Open to In Progress

Hello,

I've made a Pull-Request for this feature request . As said, the main problem was that you can't use r.external with r.null. I've used r.in.gdal instead (with the ext mechanism) and the raster file is imported into the temporary GRASS database. This could lead to file size problems for large rasters as the raster is duplicated.

But this is the only way I've found so far to make r.null works into Processing.

As this is a new feature, it will be implemented in 2.16.

#11 Updated by Alexander Bruy over 8 years ago

  • Status changed from In Progress to Closed

Also available in: Atom PDF