Learn R Programming

satin (version 1.1.0)

crop: Cut a satin object

Description

Select and cut a polygon shaped area of interest from a satin object.

Usage

crop(X, polygon = NULL, return.poly = FALSE)

Value

A cutted satin object.

When return.poly = TRUE, a list with two components:

aoi

cutted satin object.

polygon

polygon coordinates defining the aoi.

Arguments

X

a satin object as returned by read.nasaoc, read.ghrsst, read.osunpp, or read.cmems.

polygon

a polygon defining the area of interest (aoi) to be cutted.

return.poly

if TRUE, crop returns a list with the cutted satin object and the polygon drawn (a data frame).

Author

Héctor Villalobos

Details

If provided, the polygon defining the aoi must have two columns with x and y coordinates. The function verifies that the last point is exactly the same as the first one. When not specified, the user can draw a polygon by clicking on a previously displayed image. Note that for drawing the polygon in this manner, the plot of the satin object has to be created using colbar = FALSE. The result is a satin object where the pixels outside the aoi are set to NA. In order to cut Copernicus data returned from read.cmems, the appropriate indexing should be previously done.

See Also

getpoly

Examples

Run this code
# load and display sample data
data(dsst)
plot(dsst)
  
# define polygon, cut the image and display the aoi
polyg <- data.frame(x = c(-110, -105, -113, -116, -110), y = c(23, 23, 32, 32, 23))
dsst.clip <- crop(dsst, polygon = polyg)
plot(dsst.clip)

if(interactive()){ 
# the same, but polygon is defined by clicking on the image
plot(dsst, colbar = FALSE)
dsst.clip2 <- crop(dsst, return.poly = TRUE) # *** draw the aoi polygon ***
dsst.clip2$polygon # show polygon coordinates
plot(dsst.clip2$aoi) # plot the selected aoi
}

Run the code above in your browser using DataLab