Hi,
I'd like to replace all values/categories "0" by real NULL values.
Furthermore I want to do that in a Python script. I tried to do it
with mapcalc in the script but then I loose the category labels:
grass.mapcalc("$out= if($in==0,null(),$in)",
out = "in",
in = "in")
I am not sure if r.reclass or r.recode can be the right module here?
Anyway if yes, how can they be used with a rule supplied
in the python script (sstdin?). The desired approach should keep the other categories and their labels.
grass.run_command("r.reclass", input="in", output="out", rules=??)
Best regards,
/Johannes
--
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
On 02/03/12 15:09, Johannes Radinger wrote:
Hi,
I'd like to replace all values/categories "0" by real NULL values.
Furthermore I want to do that in a Python script. I tried to do it
with mapcalc in the script but then I loose the category labels:
grass.mapcalc("$out= if($in==0,null(),$in)",
out = "in",
in = "in")
I am not sure if r.reclass or r.recode can be the right module here?
Anyway if yes, how can they be used with a rule supplied
in the python script (sstdin?). The desired approach should keep the other categories and their labels.
grass.run_command("r.reclass", input="in", output="out", rules=??)
Any reason not to use r.null with parameter setnull= ?
Moritz
On 02/03/12 15:09, Johannes Radinger wrote:
> Hi,
>
> I'd like to replace all values/categories "0" by real NULL values.
> Furthermore I want to do that in a Python script. I tried to do it
> with mapcalc in the script but then I loose the category labels:
>
>
> grass.mapcalc("$out= if($in==0,null(),$in)",
> out = "in",
> in = "in")
>
> I am not sure if r.reclass or r.recode can be the right module here?
> Anyway if yes, how can they be used with a rule supplied
> in the python script (sstdin?). The desired approach should keep the
other categories and their labels.
>
> grass.run_command("r.reclass", input="in", output="out", rules=??)
Any reason not to use r.null with parameter setnull= ?
Thank you, I wasn't aware of this module r.null, but thats what I was looking for as my values and my category is 0 (which I want to replace).
Just for my personal interest two questions:
1) What if I want to replace the category "0" with NULL (not the values 0)
2) What would be the correct module if I want to assign another category than NULL to certain values? Is hat module r.category? And how can that be used in pyhton (how are the rules supplied)? Eg. assign all values greater than 0 to 1 all other values NULL.
cheers
Johannes
Moritz
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user
--
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
On 02/03/12 15:56, Johannes Radinger wrote:
Just for my personal interest two questions: 1) What if I want to
replace the category "0" with NULL (not the values 0)
Category 0 = value 0.
Raster values in GRASS are called categorie values.
Or maybe I don't understand what you mean ?
2) What would be the correct module if I want to assign another
category than NULL to certain values? Is hat module r.category? And
how can that be used in pyhton (how are the rules supplied)? Eg.
assign all values greater than 0 to 1 all other values NULL.
If you have a integer values (CELL), then r.reclass.
If you have floating point values, generally r.recode is more appropriate (or just multiply your floating point map by the appropriate number to make it integer).
Moritz
Hi,
-------- Original-Nachricht --------
Datum: Fri, 02 Mar 2012 20:22:30 +0100
Von: Moritz Lennert <mlennert@club.worldonline.be>
An: Johannes Radinger <JRadinger@gmx.at>
CC: grass-user@lists.osgeo.org
Betreff: Re: [GRASS-user] Replace 0 by NULL in categorial raster map
On 02/03/12 15:56, Johannes Radinger wrote:
> Just for my personal interest two questions: 1) What if I want to
> replace the category "0" with NULL (not the values 0)
Category 0 = value 0.
sorry I meant the category named (with label) "0".
Raster values in GRASS are called categorie values.
Or maybe I don't understand what you mean ?
> 2) What would be the correct module if I want to assign another
> category than NULL to certain values? Is hat module r.category? And
> how can that be used in pyhton (how are the rules supplied)? Eg.
> assign all values greater than 0 to 1 all other values NULL.
If you have a integer values (CELL), then r.reclass.
As I have a CELL raster I'd like to use r.reclass. In my special
case I want to assign a Category labeled "1" to all values 1 and want to replace all 0 by NULL. (No other values present only 0 an 1). For the NULL-task I use r.null, and for the 1-task r.reclass.
But how can I simply use a rule in when calling r.reclass in a python script???
grass.run_command("r.reclass",
input = "in",
output = "out",
rules = ???)
/Johannes
If you have floating point values, generally r.recode is more
appropriate (or just multiply your floating point map by the appropriate
number to make it integer).
Moritz
--
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
On 05/03/12 15:56, Johannes Radinger wrote:
Hi,
-------- Original-Nachricht --------
Datum: Fri, 02 Mar 2012 20:22:30 +0100
Von: Moritz Lennert<mlennert@club.worldonline.be>
An: Johannes Radinger<JRadinger@gmx.at>
CC: grass-user@lists.osgeo.org
Betreff: Re: [GRASS-user] Replace 0 by NULL in categorial raster map
On 02/03/12 15:56, Johannes Radinger wrote:
Just for my personal interest two questions: 1) What if I want to
replace the category "0" with NULL (not the values 0)
Category 0 = value 0.
sorry I meant the category named (with label) "0".
In that case you have to first use your label as a new category value. You can do that in r.mapcalc with the @ operator:
r.mapcalc labelmap = @categorymap
But how can I simply use a rule in when calling r.reclass in a python script???
grass.run_command("r.reclass",
input = "in",
output = "out",
rules = ???)
http://lists.osgeo.org/pipermail/grass-user/2011-November/062803.html

To make it easier, here's an example with r.colors that you can transform for r.reclass:
colorrules = '0 255:255:255 \n 1 165:42:42'
grass.write_command('r.colors', map=carte_diff, rules='-', stdin=colorrules, quiet=True)
Moritz