GRASS logo

NAME

r.clip - Extracts portion of the input map which overlaps with the current region
Extracts portion of the input raster map which is in the current computational region

KEYWORDS

raster, extract, clip, crop, trim, extent

SYNOPSIS

r.clip
r.clip --help
r.clip [-r] input=name output=name [--overwrite] [--help] [--verbose] [--quiet] [--ui]

Flags:

-r
Resample input raster according to the computational region
By default cell size and alignment of the original raster is preserved
--overwrite
Allow output files to overwrite existing files
--help
Print usage summary
--verbose
Verbose module output
--quiet
Quiet module output
--ui
Force launching GUI dialog

Parameters:

input=name [required]
Name of input raster map
output=name [required]
Name for output raster map

Table of contents

DESCRIPTION

The module extracts portion of the input raster map according to the current computational region. The areas outside of the computational region are clipped and only the inner part is kept. The input raster map is left intact and a new (clipped) output raster map is created in the process.

By default the cell size and the cell alignment of the original raster are preserved. In other words, the output map inherits its resolution and cell positions (grid) from the input raster rather than the computational region.

If resampling into the cells size and cell alignment of the current computational is desired, the module can perform a nearest neighbor resampling when the -r flag is used. If a more advanced resampling is required, the user is advised to use one of the dedicated resampling modules.

If mask (r.mask) is active, it is respected and the output raster map will contain NULL (no data) values according to the mask. Otherwise, values in the input raster map are simply transferred to the output raster map.

The color table of the output raster map is set according to the input raster map, so that the colors in both raster maps will match.

NOTES

EXAMPLES

The following examples are using the full North Carolina sample location.

Clip according to a raster map

First we set the computational region to match the raster map called elev_lid792_1m which we want to use for clipping:
g.region raster=elev_lid792_1m
Now, the following will clip raster map called elevation according to the extent of elev_lid792_1m raster map creating a new raster map called elevation_clipped:
r.clip input=elevation output=elevation_clipped

Clip and then compare the resolutions

The following example clips (crops) raster map called elevation according to the current region resulting in a new raster map called clipped_elevation. The computational region will be set match raster map called elev_lid792_1m since this the extent we want to work with in this example.

First we set the computational region to match a raster map called elev_lid792_1m:

g.region raster=elev_lid792_1m
This is the computational region we want to have. Now we check the new region using:
g.region -g
In the output, we can see extent, resolution in both directions, and number of rows and columns:
...
n=220750
s=220000
w=638300
e=639000
nsres=1
ewres=1
rows=750
cols=700
cells=525000
...
Now we perform the clipping:
r.clip input=elevation output=clipped_elevation
Finally, we check the size of the new raster map using:
r.info map=clipped_elevation -g
In the output, we can see that the extent is the same (exactly the same in this case) as the computational region while the resolution and number of cells are different:
...
north=220750
south=220000
east=639000
west=638300
nsres=10
ewres=10
rows=75
cols=70
cells=5250
...
The reason for this is that the elevation map was not resampled, instead the cell values and positions were preserved. The number of cells depends on the resolution which was derived from the original elevation map. To see it, we can use the following:
r.info map=elevation -g
The output shows the resolution used for the new clipped_elevation as well as much higher number of cells and larger extent of the original map:
...
north=228500
south=215000
east=645000
west=630000
nsres=10
ewres=10
rows=1350
cols=1500
cells=2025000
...

SEE ALSO

g.region, g.copy, r.mask, r.patch, r.proj, r.mapcalc, r.resample, r.resamp.rst, v.clip

AUTHOR

Vaclav Petras, NCSU GeoForAll Lab

SOURCE CODE

Available at: r.clip source code (history)

Latest change: Thursday Feb 03 09:32:35 2022 in commit: f17c792f5de56c64ecfbe63ec315307872cf9d5c


Main index | Raster index | Topics index | Keywords index | Graphical index | Full index

© 2003-2023 GRASS Development Team, GRASS GIS 8.2.2dev Reference Manual