raster (version 1.1.7)

cellsFromExtent: Cells from Extent

Description

This function returns the cell numbers for a Raster* object that are within a specfied extent (rectangular area), supply either an object of class Extent, or another Raster* object.

Usage

cellsFromExtent(object, extent, expand=FALSE)

Arguments

object
A Raster* object
extent
An object of class Extent (which you can create with newExtent(), or another Raster* object )
expand
Logical. If TRUE, NA is returned for (virtual) cells implied by bndbox, that are outside the RasterLayer (object). If FALSE, only cell numbers for the area where object

Value

  • a vector of cell numbers

See Also

extent, polygonFromExtent

Examples

Run this code
r <- raster()
bb <- extent(-5, 5, -5, 5)
cells <- cellsFromExtent(r, bb)
r <- crop(r, bb)
r[] <- cells

Run the code above in your browser using DataCamp Workspace