[GRASS-user] r.category value range

Hello!

I trying to set a label for a range of values in a raster.

I am using r.category (grass 7.0)

“r.category map=lwc_2014 separator=‘:’ rules=lwc.rules”

My lwc.rules looks like this:

0:30:0.9
31:90:0.7
91:252:0.5

so, r.category does not seem to read my range, but in stead gives me labels for value 31 (label=90:0.7) and value 91 (label=252:0.5)

Any clues to what I am doing wrong ? or is r.category not working as intended?

Martin

On 04/02/15 11:48, Martin Album Ytre-Eide wrote:

Hello!

I trying to set a label for a range of values in a raster.

I am using r.category (grass 7.0)

"r.category map=lwc_2014 separator=':' rules=lwc.rules"

My lwc.rules looks like this:

0:30:0.9
31:90:0.7
91:252:0.5

so, r.category does not seem to read my range, but in stead gives me
labels for value 31 (label=90:0.7) and value 91 (label=252:0.5)

Any clues to what I am doing wrong ? or is r.category not working as
intended?

You should use r.recode, not r.category.

Moritz

On Wed, Feb 4, 2015 at 1:14 PM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:

On 04/02/15 11:48, Martin Album Ytre-Eide wrote:

Hello!

I trying to set a label for a range of values in a raster.

I am using r.category (grass 7.0)

"r.category map=lwc_2014 separator=':' rules=lwc.rules"

My lwc.rules looks like this:

0:30:0.9
31:90:0.7
91:252:0.5

so, r.category does not seem to read my range, but in stead gives me
labels for value 31 (label=90:0.7) and value 91 (label=252:0.5)

Any clues to what I am doing wrong ? or is r.category not working as
intended?

You should use r.recode, not r.category.

According to the manual, r.category should work with these rules.

Markus M

On 04/02/15 15:23, Markus Metz wrote:

On Wed, Feb 4, 2015 at 1:14 PM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:

On 04/02/15 11:48, Martin Album Ytre-Eide wrote:

Hello!

I trying to set a label for a range of values in a raster.

I am using r.category (grass 7.0)

"r.category map=lwc_2014 separator=':' rules=lwc.rules"

My lwc.rules looks like this:

0:30:0.9
31:90:0.7
91:252:0.5

so, r.category does not seem to read my range, but in stead gives me
labels for value 31 (label=90:0.7) and value 91 (label=252:0.5)

Any clues to what I am doing wrong ? or is r.category not working as
intended?

You should use r.recode, not r.category.

According to the manual, r.category should work with these rules.

You're right. Sorry, I wrote to fast.

Actually the manual also says concerning the example: "The format is given as follows (when separator is set to colon)". So, AFAIU, you have to set the separator parameter to whatever separator you use in the rules.

Moritz

On 04/02/15 15:45, Moritz Lennert wrote:

On 04/02/15 15:23, Markus Metz wrote:

On Wed, Feb 4, 2015 at 1:14 PM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:

On 04/02/15 11:48, Martin Album Ytre-Eide wrote:

Hello!

I trying to set a label for a range of values in a raster.

I am using r.category (grass 7.0)

"r.category map=lwc_2014 separator=':' rules=lwc.rules"

My lwc.rules looks like this:

0:30:0.9
31:90:0.7
91:252:0.5

so, r.category does not seem to read my range, but in stead gives me
labels for value 31 (label=90:0.7) and value 91 (label=252:0.5)

Any clues to what I am doing wrong ? or is r.category not working as
intended?

You should use r.recode, not r.category.

According to the manual, r.category should work with these rules.

You're right. Sorry, I wrote to fast.

Actually the manual also says concerning the example: "The format is
given as follows (when separator is set to colon)". So, AFAIU, you have
to set the separator parameter to whatever separator you use in the rules.

Sorry, I really should take the time before I write. I can reproduce the issue actually:

g.copy raster=geology_30m,mygeol
r.category mygeol rules=- separator=':' <<EOF
217:270:1
405:862:2
910:948:3
EOF
r.category mygeol
217 270:1
262
270
405 862:2
583
720
766
862
910 948:3
921
945
946
948

So, yes, there seems to be a bug in r.category. Please file a ticket.

Moritz

On 04/02/15 15:51, Moritz Lennert wrote:

On 04/02/15 15:45, Moritz Lennert wrote:

On 04/02/15 15:23, Markus Metz wrote:

On Wed, Feb 4, 2015 at 1:14 PM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:

On 04/02/15 11:48, Martin Album Ytre-Eide wrote:

Hello!

I trying to set a label for a range of values in a raster.

I am using r.category (grass 7.0)

"r.category map=lwc_2014 separator=':' rules=lwc.rules"

My lwc.rules looks like this:

0:30:0.9
31:90:0.7
91:252:0.5

so, r.category does not seem to read my range, but in stead gives me
labels for value 31 (label=90:0.7) and value 91 (label=252:0.5)

Any clues to what I am doing wrong ? or is r.category not working as
intended?

You should use r.recode, not r.category.

According to the manual, r.category should work with these rules.

You're right. Sorry, I wrote to fast.

Actually the manual also says concerning the example: "The format is
given as follows (when separator is set to colon)". So, AFAIU, you have
to set the separator parameter to whatever separator you use in the rules.

Sorry, I really should take the time before I write. I can reproduce the
issue actually:

g.copy raster=geology_30m,mygeol
r.category mygeol rules=- separator=':' <<EOF
217:270:1
405:862:2
910:948:3
EOF
r.category mygeol
217 270:1
262
270
405 862:2
583
720
766
862
910 948:3
921
945
946
948

So, yes, there seems to be a bug in r.category. Please file a ticket.

Looking at the code, I actually think that r.category works well in terms of setting the label for the range. At least the cats file reads:

# 948 categories

0.00 0.00 0.00 0.00
217:270:1
405:862:2
910:948:3

which looks correct to me.

However, it does not know how to display it in a decent manner. The same goes for d.legend. Or r.what. IIUC, modules that read cat values just don't seem to have been foreseen for this case.

So, for the OP, I would go back to my original answer to suggest using r.recode.

And maybe someone who understands the code better than me can clarify how GRASS is supposed to actually use such range labels ?

Moritz

Hey, thanks!

r.recode worked for me. As mentioned r.category clames it can do this, and in different cases - it might be more usefull to work with labels. I was trying to add labels and then do a "r.mapcalc expression="snow_type= @lwc_2014_05_15" " in order to use the labels as values. But r.recode did this in one go, so that was better. But if one was to use the labels in a label instead of the values - it would be good if the r.category worked as intended. I think I have done that before, so maybe label range (with r.category) works with d.legend? - did you try this Moritz?

Martin

________________________________________
Fra: grass-user-bounces@lists.osgeo.org [grass-user-bounces@lists.osgeo.org] p&#229; vegne av Moritz Lennert [mlennert@club.worldonline.be]
Sendt: 4. februar 2015 16:55
Til: Markus Metz
Kopi: grass-user@lists.osgeo.org
Emne: Re: [GRASS-user] r.category value range

On 04/02/15 15:51, Moritz Lennert wrote:

On 04/02/15 15:45, Moritz Lennert wrote:

On 04/02/15 15:23, Markus Metz wrote:

On Wed, Feb 4, 2015 at 1:14 PM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:

On 04/02/15 11:48, Martin Album Ytre-Eide wrote:

Hello!

I trying to set a label for a range of values in a raster.

I am using r.category (grass 7.0)

"r.category map=lwc_2014 separator=':' rules=lwc.rules"

My lwc.rules looks like this:

0:30:0.9
31:90:0.7
91:252:0.5

so, r.category does not seem to read my range, but in stead gives me
labels for value 31 (label=90:0.7) and value 91 (label=252:0.5)

Any clues to what I am doing wrong ? or is r.category not working as
intended?

You should use r.recode, not r.category.

According to the manual, r.category should work with these rules.

You're right. Sorry, I wrote to fast.

Actually the manual also says concerning the example: "The format is
given as follows (when separator is set to colon)". So, AFAIU, you have
to set the separator parameter to whatever separator you use in the rules.

Sorry, I really should take the time before I write. I can reproduce the
issue actually:

g.copy raster=geology_30m,mygeol
r.category mygeol rules=- separator=':' <<EOF
217:270:1
405:862:2
910:948:3
EOF
r.category mygeol
217 270:1
262
270
405 862:2
583
720
766
862
910 948:3
921
945
946
948

So, yes, there seems to be a bug in r.category. Please file a ticket.

Looking at the code, I actually think that r.category works well in
terms of setting the label for the range. At least the cats file reads:

# 948 categories

0.00 0.00 0.00 0.00
217:270:1
405:862:2
910:948:3

which looks correct to me.

However, it does not know how to display it in a decent manner. The same
goes for d.legend. Or r.what. IIUC, modules that read cat values just
don't seem to have been foreseen for this case.

So, for the OP, I would go back to my original answer to suggest using
r.recode.

And maybe someone who understands the code better than me can clarify
how GRASS is supposed to actually use such range labels ?

Moritz
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

On 05/02/15 11:12, Martin Album Ytre-Eide wrote:

Hey, thanks!

r.recode worked for me. As mentioned r.category clames it can do
this, and in different cases - it might be more usefull to work with
labels. I was trying to add labels and then do a "r.mapcalc
expression="snow_type= @lwc_2014_05_15" " in order to use the labels
as values. But r.recode did this in one go, so that was better. But
if one was to use the labels in a label instead of the values - it
would be good if the r.category worked as intended. I think I have
done that before, so maybe label range (with r.category) works with
d.legend? - did you try this Moritz?

Yes, as I said: "However, it does not know how to display it in a decent manner. The same goes for d.legend. Or r.what. IIUC, modules that read cat values just don't seem to have been foreseen for this case."

I did not think about r.mapcalc. If you know that this worked with a specific version of GRASS, it would be interesting for us to know. That would allow us to retrace the changes that might have broken that feature.

Moritz

On Thu, Feb 5, 2015 at 11:40 AM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:

On 05/02/15 11:12, Martin Album Ytre-Eide wrote:

Hey, thanks!

r.recode worked for me. As mentioned r.category clames it can do
this, and in different cases - it might be more usefull to work with
labels. I was trying to add labels and then do a "r.mapcalc
expression="snow_type= @lwc_2014_05_15" " in order to use the labels
as values. But r.recode did this in one go, so that was better. But
if one was to use the labels in a label instead of the values - it
would be good if the r.category worked as intended. I think I have
done that before, so maybe label range (with r.category) works with
d.legend? - did you try this Moritz?

Yes, as I said: "However, it does not know how to display it in a decent
manner. The same goes for d.legend. Or r.what. IIUC, modules that read cat
values just don't seem to have been foreseen for this case."

I think you would need to go back to GRASS 4.x to find out how these
rules were handled (back then by r.support). These rules, and the
format options, are pretty powerful, and it would be nice to have them
restored in GRASS 7.x.

Markus M

I did not think about r.mapcalc. If you know that this worked with a
specific version of GRASS, it would be interesting for us to know. That
would allow us to retrace the changes that might have broken that feature.

Moritz

Hi,

Il 04/02/2015 15:45, Moritz Lennert ha scritto:

My lwc.rules looks like this:

0:30:0.9
31:90:0.7
91:252:0.5

so, r.category does not seem to read my range, but in stead gives me
labels for value 31 (label=90:0.7) and value 91 (label=252:0.5)

Any clues to what I am doing wrong ? or is r.category not working as
intended?

i'm not sure to remember correctly but i think ranges should look like:

  0:30:0.9:0.9
31:90:0.7:0.7
91:252:0.5:0.5

maybe you can try if you get the expected result ...