Learn R Programming

terra (version 1.8-5)

click: Query by clicking on a map

Description

Click on a map (plot) to get the coordinates or the values of a SpatRaster or SpatVector at that location. For a SpatRaster you can also get the coordinates and cell number of the location.

This does to work well on the default RStudio plotting device. To work around that, you can first run dev.new(noRStudioGD = TRUE) which will create a separate window for plotting, then use plot() followed by click() and click on the map.

Usage

# S4 method for SpatRaster
click(x, n=10, id=FALSE, xy=FALSE, cell=FALSE, type="p", show=TRUE, ...)

# S4 method for SpatVector click(x, n=10, id=FALSE, xy=FALSE, type="p", show=TRUE, ...)

# S4 method for missing click(x, n=10, id=FALSE, type="p", show=TRUE, ...)

Value

The value(s) of x at the point(s) clicked on (or touched by the box drawn). A data.frame with the value(s) of all layers of SpatRaster x for the cell(s) clicked on; or with the attributes of the geometries of SpatVector x that intersect with the box drawn).

Arguments

x

SpatRaster or SpatVector, or missing

n

number of clicks on the plot (map)

id

logical. If TRUE, a numeric ID is shown on the map that corresponds to the row number of the output

xy

logical. If TRUE, xy coordinates are included in the output

cell

logical. If TRUE, cell numbers are included in the output

type

one of "n", "p", "l" or "o". If "p" or "o" the points are plotted; if "l" or "o" they are joined by lines. See locator

show

logical. Print the values after each click?

...

additional graphics parameters used if type != "n" for plotting the locations. See locator

See Also

draw

Examples

Run this code
if (FALSE) {
r <-rast(system.file("ex/elev.tif", package="terra"))
plot(r)
click(r, n=1)
## now click on the plot (map)
}

Run the code above in your browser using DataLab