A wrapper around gdalraster::plot_raster
that simplifies the
process of plotting a raster file.
Usage
plot_raster_src(
x,
bands = 1,
pal = grDevices::hcl.colors(10, "Viridis"),
nbands = length(bands),
title = c("description", "dttm", "none"),
col_tbl = NULL,
maxColorValue = 1,
normalize = TRUE,
adj_low = 0.8,
minmax_def = NULL,
minmax_pct_cut = NULL,
col_map_fn = if (nbands == 1) {
scales::colour_ramp(pal, alpha = FALSE)
} else {
NULL
},
xlim = NULL,
ylim = NULL,
interpolate = TRUE,
asp = 1,
axes = TRUE,
main = "",
xlab = "",
ylab = "",
xaxs = "r",
yaxs = "r",
legend = if (nbands == 1) TRUE else FALSE,
digits = 2,
na_col = grDevices::rgb(0, 0, 0, 0),
...
)
# S3 method for class 'vrt_block'
plot(x, ..., config_options = gdal_config_opts())
# S3 method for class 'vrt_stack'
plot(x, ..., config_options = gdal_config_opts())
# S3 method for class 'vrt_stack_warped'
plot(x, ..., config_options = gdal_config_opts())
# S3 method for class 'vrt_collection'
plot(x, item, ..., config_options = gdal_config_opts())
Arguments
- x
A path to a raster file
- bands
a numeric vector of band numbers to plot must be of length 1 or 3.
- pal
a character vector of colors to use when plotting a single band.
- nbands
The number of bands in
data
. Must be either 1 (grayscale) or 3 (RGB). For RGB,data
are interleaved by band. Ifnbands
isNULL
(the default), thennbands = 3
is assumed if the input data contain 3 bands, otherwise band 1 is used.- title
a character string indicating what to use as the title of the plot. One of "description", "dttm", or "none". If "description" the band description (name) is used, if "dttm" the datetime of the block is used, if "none" no title is used. Ignored if main is provided.
- col_tbl
A color table as a matrix or data frame with four or five columns. Column 1 contains the numeric pixel values. Columns 2:4 contain the intensities of the red, green and blue primaries (
0:1
by default, or use integer0:255
by settingmaxColorValue = 255
). An optional column 5 may contain alpha transparency values,0
for fully transparent to1
(ormaxColorValue
) for opaque (the default if column 5 is missing). Ifdata
is aGDALRaster
object, a built-in color table will be used automatically if one exists in the dataset.- maxColorValue
A number giving the maximum of the color values range in
col_tbl
(see above). The default is1
.- normalize
Logical.
TRUE
to rescale pixel values so that their range is[0,1]
, normalized to the full range of the pixel data by default (min(data)
,max(data)
, per band). Ignored ifcol_tbl
is used. Setnormalize
toFALSE
if a color map function is used that operates on raw pixel values (seecol_map_fn
below).- adj_low
a numeric value to adjust the lower quantile value by. useful for example when sea presents as very dark.
- minmax_def
Normalize to user-defined min/max values (in terms of the pixel data, per band). For single-band grayscale, a numeric vector of length two containing min, max. For 3-band RGB, a numeric vector of length six containing b1_min, b2_min, b3_min, b1_max, b2_max, b3_max.
- minmax_pct_cut
Normalize to a truncated range of the pixel data using percentile cutoffs (removes outliers). A numeric vector of length two giving the percentiles to use (e.g.,
c(2, 98)
). Applied per band. Ignored ifminmax_def
is used.- col_map_fn
An optional color map function (default is
grDevices::gray
for single-band data orgrDevices::rgb
for 3-band). Ignored ifcol_tbl
is used. Setnormalize
toFALSE
if using a color map function that operates on raw pixel values.- xlim
Numeric vector of length two giving the x coordinate range. If
data
is aGDALRaster
object, the default is the raster xmin, xmax in georeferenced coordinates, otherwise the default uses pixel/line coordinates (c(0, xsize)
).- ylim
Numeric vector of length two giving the y coordinate range. If
data
is aGDALRaster
object, the default is the raster ymin, ymax in georeferenced coordinates, otherwise the default uses pixel/line coordinates (c(ysize, 0)
).- interpolate
Logical indicating whether to apply linear interpolation to the image when drawing (default
TRUE
).- asp
Numeric. The aspect ratio y/x (see
?plot.window
).- axes
Logical.
TRUE
to draw axes (the default).- main
The main title (on top).
- xlab
Title for the x axis (see
?title
).- ylab
Title for the y axis (see
?title
).- xaxs
The style of axis interval calculation to be used for the x axis (see
?par
).- yaxs
The style of axis interval calculation to be used for the y axis (see
?par
).- legend
Logical indicating whether to include a legend on the plot. Currently, legends are only supported for continuous data. A color table will be used if one is specified or the raster has a built-in color table, otherwise the value for
col_map_fn
will be used.- digits
The number of digits to display after the decimal point in the legend labels when raster data are floating point.
- na_col
Color to use for
NA
as a 7- or 9-character hexadecimal code. The default is transparent ("#00000000"
, the return value ofrgb(0,0,0,0)
).- ...
Other parameters to be passed to
plot.default()
.- config_options
A named character vector of gdal config options to set before attempting to read the VRT.
- item
The numeric index of the item, in the vrt_collection, to plot