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
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.
-
In GRASS GIS, clipping of rasters is usually not needed because
modules respect the current computational region and clipping
(with possible resampling) is done automatically.
-
If the user needs to clip raster map according to another raster map or
according to a vector map,
the g.region should be used first
before running the r.clip module.
-
The extent of the resulting map might be slightly different based on how
the cells of the input raster align with the cells of the computational
region. The mechanism for aligning in the background is the one used in
g.region. If an exact match is
desired, the user is advised to resolve the cell alignment ahead using
g.region and then use
r.clip with the -r flag.
The following examples are using the full North Carolina sample
location.
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
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:
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:
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
...
g.region,
g.copy,
r.mask,
r.patch,
r.proj,
r.mapcalc,
r.resample,
r.resamp.rst,
v.clip
Vaclav Petras,
NCSU GeoForAll Lab
SOURCE CODE
Available at:
r.clip source code
(history)
Latest change: Tuesday Nov 05 09:35:47 2024 in commit: f00067506253c89598cffadc3c7fa07cff7233fd
Main index |
Raster index |
Topics index |
Keywords index |
Graphical index |
Full index
© 2003-2024
GRASS Development Team,
GRASS GIS 8.5.0dev Reference Manual