[GRASS-user] Cropping maps

Dear list,

I am trying to crop a raster map into a smaller area, but I am failing.

This wiki page link is quite clear:
“Make boundary into mask using r.mask then copy raster source to new map (g.copy). All cells outside of the mask will be omitted from the new copy.”

r.mask vector=myarea
g.copy --overwrite raster=OldRasterWithBigArea,NewRasterWithSmallArea
r.mask -r

I expected all cell outside were not going to be omitted, but replaced by NULL.

Regards

Marco

On 26/09/17 15:57, Marco Alicera wrote:

Dear list,
I am trying to crop a raster map into a smaller area, but I am failing.

This wiki page link <https://grasswiki.osgeo.org/wiki/Cropping_maps&gt; is quite clear:
"Make boundary into mask using r.mask <https://grass.osgeo.org/grass72/manuals/r.mask.html&gt; then copy raster source to new map (g.copy <https://grass.osgeo.org/grass72/manuals/g.copy.html&gt;\). All cells outside of the mask will be omitted from the new copy."

r.mask vector=myarea
g.copy --overwrite raster=OldRasterWithBigArea,NewRasterWithSmallArea
r.mask -r

I expected all cell outside were not going to be omitted, but replaced by NULL.

I'm not sure I understand your last sentence, but AFAIK, the wiki info is wrong. g.copy works directly on the files and ignores mask and region settings. In your example, OldRasterWithBigArea and NewRasterWithSmallArea should be strictly identical.

You need to use r.mapcalc "new = old" while the mask is set to get a raster with everything outside the mask set to NULL.

Moritz

On 26/09/17 16:17, Moritz Lennert wrote:

On 26/09/17 15:57, Marco Alicera wrote:

Dear list,
I am trying to crop a raster map into a smaller area, but I am failing.

This wiki page link <https://grasswiki.osgeo.org/wiki/Cropping_maps&gt; is
quite clear:
"Make boundary into mask using r.mask
<https://grass.osgeo.org/grass72/manuals/r.mask.html&gt; then copy raster
source to new map (g.copy
<https://grass.osgeo.org/grass72/manuals/g.copy.html&gt;\). All cells
outside of the mask will be omitted from the new copy."

r.mask vector=myarea
g.copy --overwrite raster=OldRasterWithBigArea,NewRasterWithSmallArea
r.mask -r

I expected all cell outside were not going to be omitted, but replaced
by NULL.

I'm not sure I understand your last sentence, but AFAIK, the wiki info
is wrong. g.copy works directly on the files and ignores mask and region
settings. In your example, OldRasterWithBigArea and
NewRasterWithSmallArea should be strictly identical.

You need to use r.mapcalc "new = old" while the mask is set to get a
raster with everything outside the mask set to NULL.

I've rewritten the wiki page to try to make things clearer.

Moritz

For cropping, see also a new addon module called r.clip which clips according the computational region while respecting mask and the original raster resolution:

https://grass.osgeo.org/grass72/manuals/addons/r.clip.html

Testing and feedback welcome.

Vaclav

···

On Tue, Sep 26, 2017 at 10:35 AM, Moritz Lennert <mlennert@club.worldonline.be> wrote:

On 26/09/17 16:17, Moritz Lennert wrote:

On 26/09/17 15:57, Marco Alicera wrote:

Dear list,
I am trying to crop a raster map into a smaller area, but I am failing.

This wiki page link <https://grasswiki.osgeo.org/wiki/Cropping_maps> is
quite clear:
“Make boundary into mask using r.mask
<https://grass.osgeo.org/grass72/manuals/r.mask.html> then copy raster
source to new map (g.copy
<https://grass.osgeo.org/grass72/manuals/g.copy.html>). All cells
outside of the mask will be omitted from the new copy.”

r.mask vector=myarea
g.copy --overwrite raster=OldRasterWithBigArea,NewRasterWithSmallArea
r.mask -r

I expected all cell outside were not going to be omitted, but replaced
by NULL.

I’m not sure I understand your last sentence, but AFAIK, the wiki info
is wrong. g.copy works directly on the files and ignores mask and region
settings. In your example, OldRasterWithBigArea and
NewRasterWithSmallArea should be strictly identical.

You need to use r.mapcalc “new = old” while the mask is set to get a
raster with everything outside the mask set to NULL.

I’ve rewritten the wiki page to try to make things clearer.

Moritz


grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

On Fri, Dec 1, 2017 at 4:26 PM, Vaclav Petras <wenzeslaus@gmail.com> wrote:

For cropping, see also a new addon module called r.clip which clips according the computational region while respecting mask and the original raster resolution:

https://grass.osgeo.org/grass72/manuals/addons/r.clip.html

Testing and feedback welcome.

About https://trac.osgeo.org/grass/browser/grass-addons/grass7/raster/r.clip/r.clip.py#L42

g.region align=original

is sufficient. You don’t need to specify nsres or ewres when aligning to a raster map because nsres and ewres of the raster map are used anyway for alignment.

Markus M

Vaclav

On Tue, Sep 26, 2017 at 10:35 AM, Moritz Lennert <mlennert@club.worldonline.be> wrote:

On 26/09/17 16:17, Moritz Lennert wrote:

On 26/09/17 15:57, Marco Alicera wrote:

Dear list,
I am trying to crop a raster map into a smaller area, but I am failing.

This wiki page link <https://grasswiki.osgeo.org/wiki/Cropping_maps> is
quite clear:
“Make boundary into mask using r.mask
<https://grass.osgeo.org/grass72/manuals/r.mask.html> then copy raster
source to new map (g.copy
<https://grass.osgeo.org/grass72/manuals/g.copy.html>). All cells
outside of the mask will be omitted from the new copy.”

r.mask vector=myarea
g.copy --overwrite raster=OldRasterWithBigArea,NewRasterWithSmallArea
r.mask -r

I expected all cell outside were not going to be omitted, but replaced
by NULL.

I’m not sure I understand your last sentence, but AFAIK, the wiki info
is wrong. g.copy works directly on the files and ignores mask and region
settings. In your example, OldRasterWithBigArea and
NewRasterWithSmallArea should be strictly identical.

You need to use r.mapcalc “new = old” while the mask is set to get a
raster with everything outside the mask set to NULL.

I’ve rewritten the wiki page to try to make things clearer.

Moritz


grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user


grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

On Fri, Dec 1, 2017 at 10:39 AM, Markus Metz <markus.metz.giswork@gmail.com>
wrote:

On Fri, Dec 1, 2017 at 4:26 PM, Vaclav Petras <wenzeslaus@gmail.com>
wrote:
>
> For cropping, see also a new addon module called r.clip which clips
according the computational region while respecting mask and the *original*
raster resolution:
>
> https://grass.osgeo.org/grass72/manuals/addons/r.clip.html
>
> Testing and feedback welcome.

About https://trac.osgeo.org/grass/browser/grass-addons/grass7/
raster/r.clip/r.clip.py#L42

g.region align=original

is sufficient. You don't need to specify nsres or ewres when aligning to a
raster map because nsres and ewres of the raster map are used anyway for
alignment.

Fixed. Thanks MarkusM for the tip.

https://trac.osgeo.org/grass/changeset/71982

r.clip and v.clip are now missing in the Cropping maps wiki page if
somebody wants to contribute some text...

https://grasswiki.osgeo.org/wiki/Cropping_maps

Vaclav