[GRASS-user] r.mapcalc changes color table

Dear Grass Users,
I have a large georeferenced digital map.

I successfully imported it into GRASS.

Now I would like to "cut" only a small rectangle -- my investigation
area -- out of this large map.

I used the following approach:

1) import the TIFF
2) select the part of interest in the GRASS monitor
3) set the zoomed area as region (monitor tools)
4) create a boundary vector: v.in.region
5) convert boundary raster to a raster v.to.rast
6) use r.mapcalc to cut: r.mapcalc "cut=if(boundary_raster, large_map,
null())"

This works well for the cutting. But the color table of the large input
map is lost resulting in a strange coloring.
Opened in QGIS, it shows me that there is a "color map" associated with
the layer.
How do I get the same color table in the r.mapcalc result?

Thanks in advance,
Timmie

I used the following approach:

  1. import the TIFF
  2. select the part of interest in the GRASS monitor
  3. set the zoomed area as region (monitor tools)

At this point r.resamp

The output map will match region boundary and resolution with the same category values and color table of the original map.

Pablo.


Novo Windows 7: Seu computador mais simples e fácil. Conheça!


A vida na frente do computador ficou mais simples: Chegou Windows 7! Clique e Conheça

Tim Michelsen wrote:

Dear Grass Users,
I have a large georeferenced digital map.

I successfully imported it into GRASS.

Now I would like to "cut" only a small rectangle -- my investigation
area -- out of this large map.

I used the following approach:

1) import the TIFF
2) select the part of interest in the GRASS monitor
3) set the zoomed area as region (monitor tools)
4) create a boundary vector: v.in.region
5) convert boundary raster to a raster v.to.rast
6) use r.mapcalc to cut: r.mapcalc "cut=if(boundary_raster, large_map,
null())"

This works well for the cutting. But the color table of the large input
map is lost resulting in a strange coloring.
Opened in QGIS, it shows me that there is a "color map" associated with
the layer.
How do I get the same color table in the r.mapcalc result?

Thanks in advance,
Timmie

You can use r.colors' raster option to copy the colour rules over from your original layer.

r.colors map=cut raster=large_map

-- Dan.

Tim Michelsen wrote:

I have a large georeferenced digital map.

I successfully imported it into GRASS.

Now I would like to "cut" only a small rectangle -- my investigation
area -- out of this large map.

I used the following approach:

1) import the TIFF
2) select the part of interest in the GRASS monitor
3) set the zoomed area as region (monitor tools)
4) create a boundary vector: v.in.region
5) convert boundary raster to a raster v.to.rast
6) use r.mapcalc to cut: r.mapcalc "cut=if(boundary_raster, large_map,
null())"

Replace step 6 with:

  g.copy rast=boundary_raster,MASK
  r.resample input=large_map output=cut
  g.remove rast=MASK

This works well for the cutting. But the color table of the large input
map is lost resulting in a strange coloring.
Opened in QGIS, it shows me that there is a "color map" associated with
the layer.
How do I get the same color table in the r.mapcalc result?

You can copy the colour table over with e.g.:

  r.colors map=cut raster=large_map

--
Glynn Clements <glynn@gclements.plus.com>

Glynn Clements wrote:

Tim Michelsen wrote:

I have a large georeferenced digital map.

I successfully imported it into GRASS.

Now I would like to "cut" only a small rectangle -- my investigation
area -- out of this large map.

I used the following approach:

1) import the TIFF
2) select the part of interest in the GRASS monitor
3) set the zoomed area as region (monitor tools)
4) create a boundary vector: v.in.region
5) convert boundary raster to a raster v.to.rast
6) use r.mapcalc to cut: r.mapcalc "cut=if(boundary_raster, large_map,
null())"

Replace step 6 with:

  g.copy rast=boundary_raster,MASK
  r.resample input=large_map output=cut
  g.remove rast=MASK

Can someone perhaps explain why steps 4 and 5 are necessary?
(My understanding is that r.mapcalc anyway observes the region settings)

Couldn't step 6 be simplified to: r.mapcalc cut = large_map
?

Hermann

First,
thanks to all who responded. I will try and apply that later.

6) use r.mapcalc to cut: r.mapcalc "cut=if(boundary_raster, large_map,
null())"

Replace step 6 with:

    g.copy rast=boundary_raster,MASK
    r.resample input=large_map output=cut
    g.remove rast=MASK

Can someone perhaps explain why steps 4 and 5 are necessary?
(My understanding is that r.mapcalc anyway observes the region settings)

Couldn't step 6 be simplified to: r.mapcalc cut = large_map
?

I don't know. That was the approach I have always seen and been told.

The question is:
when do I use r.resample and when do I use r.mapcalc to cut a smaller
portion from a large raster map?

from the man page:
The method by which resampling is conducted is "nearest neighbor" (see
r.neighbors). The resulting raster map layer will have the same
resolution as the resolution of the current geographic region (set using
g.region).

I actually do not want to extract by sampling than rather copy a smaller
area from the large map.

It would be nice to receive a best practice confirmation on this by a
GRASS power user.

Is there a "best practice page" in the wiki where this could be added?

Thanks in advance,
Timmie

Hermann Peifer wrote:

>> I have a large georeferenced digital map.
>>
>> I successfully imported it into GRASS.
>>
>> Now I would like to "cut" only a small rectangle -- my investigation
>> area -- out of this large map.
>>
>> I used the following approach:
>>
>> 1) import the TIFF
>> 2) select the part of interest in the GRASS monitor
>> 3) set the zoomed area as region (monitor tools)
>> 4) create a boundary vector: v.in.region
>> 5) convert boundary raster to a raster v.to.rast
>> 6) use r.mapcalc to cut: r.mapcalc "cut=if(boundary_raster, large_map,
>> null())"
>
> Replace step 6 with:
>
> g.copy rast=boundary_raster,MASK
> r.resample input=large_map output=cut
> g.remove rast=MASK
>

Can someone perhaps explain why steps 4 and 5 are necessary?
(My understanding is that r.mapcalc anyway observes the region settings)

I wasn't paying attention. For a rectangular area, you can just change
the region then make a copy with r.resample or r.mapcalc. I was
assuming an arbitrary (not necessarily rectangular) region.

For a rectangular region, steps 3 through 6 can be replaced with a
single call to r.resample.

Couldn't step 6 be simplified to: r.mapcalc cut = large_map
?

Which is equivalent to "r.resample in=large_map out=cut". Using
r.resample is probably more convenient from the GUI, as you can select
the input from a list.

--
Glynn Clements <glynn@gclements.plus.com>

Tim Michelsen wrote:

>>> 6) use r.mapcalc to cut: r.mapcalc "cut=if(boundary_raster, large_map,
>>> null())"
>>
>> Replace step 6 with:
>>
>> g.copy rast=boundary_raster,MASK
>> r.resample input=large_map output=cut
>> g.remove rast=MASK
>>
>
> Can someone perhaps explain why steps 4 and 5 are necessary?
> (My understanding is that r.mapcalc anyway observes the region settings)
>
>
> Couldn't step 6 be simplified to: r.mapcalc cut = large_map
> ?
I don't know. That was the approach I have always seen and been told.

The question is:
when do I use r.resample and when do I use r.mapcalc to cut a smaller
portion from a large raster map?

"r.mapcalc 'cut = large_map'" is equivalent to "r.resample in=large_map out=cut".

from the man page:
The method by which resampling is conducted is "nearest neighbor" (see
r.neighbors). The resulting raster map layer will have the same
resolution as the resolution of the current geographic region (set using
g.region).

I actually do not want to extract by sampling than rather copy a smaller
area from the large map.

If the current region has the same resolution as the input map, then
there will be a 1:1 correspondence between input cells and output
cells.

All raster modules perform nearest-neighbour resampling, as the
underlying GRASS libraries automatically resample input maps to the
current region.

The modules which perform other types of resampling (r.resamp.interp,
r.resamp.stats, r.resamp.rst) set the current region resolution and
alignment to match the input map, making the nearest-neighbour
resampling step a no-op.

--
Glynn Clements <glynn@gclements.plus.com>