[GRASS-dev] all categories copied over to new map

Moritz Lennert mlennert at club.worldonline.be
Thu Sep 17 02:56:52 PDT 2015


On 16/09/15 10:48, Paulo van Breugel wrote:
>
>
> On 16-09-15 09:49, Moritz Lennert wrote:
>> On 15/09/15 20:08, Paulo van Breugel wrote:
>>> Suppose I have a categorical raster map and I want to 'cut out' a subset
>>> (with g.region to set a small region and r.mapcalc to create the new
>>> map). This map has a smaller number of categories, as is shown using
>>> e.g., r.category. However, when plotting the legend, all the categories
>>> of the original map are included in the legend. Checking the 'cats' file
>>> shows that it indeed lists all original categories and labels, including
>>> for those categories not present in the new map. This doesn't make sense
>>> to me, but perhaps I am missing something here?
>>
>> AFAIK, the legend is determined by the color table, and the color
>> table is probably just copied as is from the input to the output map.
>> You can check with r.colors.out. If you redefine a color table with
>> only the relevant categories, then the legend should reflect that.
>
> Hi Moritz, that is what I thought, and as the whole color table does
> indeed get copied over, I wrote a small script to remove the 'redundant
> color definitions. However, that did not help, the whole 'old' legend is
> still showing.  I had missed that -n flag, so I'll give that a try. Is
> there a similar option in ps.map to omit categories without label?
>
>   From a more conceptual point of view, is there any reason the whole
> category table is copied over to the new cats file?

Probably not. IIUC, this only happens when you have a formula of the 
form "new = old".

An easy work around:

r.category new  | r.category new rules=-

The resulting cats file only contains the cats actually present and you 
can thus use d.legend -n to only show those.

Moritz




More information about the grass-dev mailing list