click_sample | R Documentation |
Function for sampling the RGB values at n points of an image within n categories, using the click() function from the raster package. These values can then be used to define thresholds for reclassifying the raster image.
click_sample(in.raster, cats = NULL, npoints = 10, print.values = FALSE, type = "p", plot.cols = TRUE, ...)
in.raster |
The SpatRaster to sample. Only works for an image file, and bands MUST be named "red", "green", and "blue" (exactly, in that order) for it to work. |
cats |
A vector of the names of land-use categories of interest (string). |
npoints |
The number of times to sample each category. More points means more representative results, but generally the default is enough if you make sure that you sample the full range of colours for each category, provided points are well chosen. Default = 10. |
print.values |
Logical. Print the RGB values of each point as you go. Default = FALSE. |
type |
Logical. From |
plot.cols |
Logical. Produce the plot of max or min colours once sampling is finished. Requires packages |
... |
additional parameters passed to |
Returns a list with three objects:
sample.table |
Dataframe. The values for each point clicked and the category they were assigned in. |
colour.summary |
Dataframe. Summary of max, min and mean values for each colour band in each category |
colour.plot |
Plot. Visualises the values in colour.summary and check they fit expectations. |
Alistair Auffret and Adam Kimberley
Auffret, A.G., Kimberley, A., et al., 2017, HistMapR: Rapid digitization of historical maps in R, Methods in Ecology and Evolution, doi: 10.1111/2041-210X.12788., Link. GitHub repository.
Hijmans, R.J. (2023) terra: Spatial Data Analysis. R package version 1.7-29, https://CRAN.R-project.org/package=terra.
ras.loc <- system.file("data/ras.smoothed.tiff", package="HistMapR")
ras.smoothed <- rast(ras.loc)
click_sample(in.raster=ras.smoothed, cats = c("Arable", "Open", "Forest"), npoints = 3, print.values = FALSE, type = "p", plot.cols = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.