Learn R Programming

rasterVis (version 0.51.6)

Interaction: Interaction with trellis objects.

Description

chooseRegion provides a set of points (in the form of a SpatialPoints) inside a region defined by several mouse clicks. identifyRaster labels and returns points of a trellis graphic according to mouse clicks.

Usage

chooseRegion(sp = TRUE, proj = as.character(NA))
# S4 method for Raster
identifyRaster(object, layer=1, values=FALSE, pch=13, cex=0.6, col='black',...)

Arguments

sp

logical, if TRUE the result is a SpatialPoints object, otherwise it is a logical vector as returned by in.out

proj

A character string for the proj4string of SpatialPoints.

object

A Raster object.

layer

A numeric or character which should indicate the layer to be chosen.

values

logical, if TRUE the values are returned.

pch, cex, col

Graphical parameters for panel.identify and panel.link.splom.

...

Additional arguments for trellis.focus,panel.link.splom and panel.identify.

Author

Oscar Perpiñán Lamigueiro

Details

When called, these functions wait for the user to identify points (in the panel being drawn) via mouse clicks. Clicks other than left-clicks close the region (for chooseRegion) and the procedure (for identifyRaster).

See Also

panel.identify,panel.link.splom, trellis.focus, grid.locator

Examples

Run this code
library(raster)

f <- system.file("external/test.grd", package="raster")
r <- raster(f)
levelplot(r)
##Do not close the last graphical window
##Use the left button of the mouse to identify points and the right button to finish
chosen_r <- identifyRaster(r, values=TRUE)
chosen_r
s <- stack(r, r-500, r+500)
levelplot(s)
chosen_s <- identifyRaster(s, values=TRUE)
chosen_s

if (FALSE) {
##The package mgcv is needed for the next example
##Use the left button of the mouse to build a border with points, and the right button to finish.
##The points enclosed by the border will be highlighted and returned as a SpatialPoints object.
levelplot(s)
reg <- chooseRegion()
summary(reg)
}

if (FALSE) {
##Solar irradiation data from CMSAF http://dx.doi.org/10.5676/EUM_SAF_CM/RAD_MVIRI/V001

dataURL <- "https://raw.github.com/oscarperpinan/bookvis/master/data/"

old <- setwd(tempdir())
download.file(paste0(dataURL, "SISmm2008_CMSAF.zip"),
   "SISmm2008_CMSAF.zip", method='wget')
unzip("SISmm2008_CMSAF.zip")

listFich <- dir(pattern='\\.nc')
stackSIS <- stack(listFich)
stackSIS <- stackSIS*24 ##from irradiance (W/m2) to irradiation Wh/m2
setwd(old)

idx <- seq(as.Date('2008-01-15'), as.Date('2008-12-15'), 'month')

SISmm <- setZ(stackSIS, idx)
names(SISmm) <- month.abb

levelplot(SISmm)

##Do not close the last graphical window
##Interaction
##Use the left button of the mouse to identify points and the right button to finish
chosen <- identifyRaster(SISmm, layer=3, values=TRUE)
chosen
##Use the left button of the mouse to build a border with points, and the right button to finish.
##The points enclosed by the border will be highlighted and returned as a SpatialPoints object.
reg <- chooseRegion()
summary(reg)
}

Run the code above in your browser using DataLab