Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

strech

Stretch


Description

Linear stretch of values in a Raster object. Provide the desired output range (minv and maxv) and the lower and upper bounds in the original data, either as quantiles (if minq=0 and maxq=1 you use the minimum and maximum cell values), or as actual values (smin and smax; e.g. precomputed quantile values). If smin and smax are both not NA, minq and maxq are ignored.

Usage

## S4 method for signature 'Raster'
stretch(x, minv=0, maxv=255, minq=0, maxq=1, smin=NA, smax=NA,
          samplesize=1000000, filename='', ...)

Arguments

x

Raster object

minv

numeric >= 0 and smaller than maxv. lower bound of stretched value

maxv

numeric <= 255 and larger than maxv. upper bound of stretched value

minq

numeric >= 0 and smaller than maxq. lower quantile bound of original value. Ignored if smin is supplied

maxq

numeric <= 1 and larger than minq. upper quantile bound of original value. Ignored if smax is supplied

smin

numeric < smax. user supplied lower value for the layers, to be used instead of a quantile computed by the function itself

smax

numeric > smin. user supplied upper value for the layers, to be used instead of a quantile computed by the function itself

samplesize

numeric > 1. If samplesize < ncell(x), a regular sample of samplesize is taken from x to compute the quantiles (to speed things up)

filename

character. Filename for the output Raster object (optional)

...

additional arguments as for writeRaster

Value

Raster

See Also

stretch argument in plotRGB

Examples

r <- raster(nc=10, nr=10)
values(r) <- rep(1:2, 50)
stretch(r)
s <- stack(r, r*2)
stretch(s)

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.