rasterFromCells: Subset a raster by cell numbers

Description Usage Arguments Details Value See Also Examples

View source: R/rasterFromCells.R

Description

This function returns a new raster based on an existing raster and cell numbers for that raster. The new raster is cropped to the cell numbers provided, and, if values=TRUE has values that are the cell numbers of the original raster.

Usage

1

Arguments

x

Raster* object (or a SpatialPixels* or SpatialGrid* object)

cells

vector of cell numbers

values

Logical. If TRUE, the new RasterLayer has cell values that correspond to the cell numbers of x

Details

Cell numbers start at 1 in the upper left corner, and increase from left to right, and then from top to bottom. The last cell number equals the number of cells of the Raster* object.

Value

RasterLayer

See Also

rowFromCell

Examples

1
2
3
4
r <- raster(ncols=100, nrows=100)
cells <- c(3:5, 210)
r <- rasterFromCells(r, cells)
cbind(1:ncell(r), getValues(r))

Example output

Loading required package: sp
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
      [,1] [,2]
 [1,]    1    3
 [2,]    2    4
 [3,]    3    5
 [4,]    4    6
 [5,]    5    7
 [6,]    6    8
 [7,]    7    9
 [8,]    8   10
 [9,]    9  103
[10,]   10  104
[11,]   11  105
[12,]   12  106
[13,]   13  107
[14,]   14  108
[15,]   15  109
[16,]   16  110
[17,]   17  203
[18,]   18  204
[19,]   19  205
[20,]   20  206
[21,]   21  207
[22,]   22  208
[23,]   23  209
[24,]   24  210

raster documentation built on Jan. 5, 2021, 3:01 a.m.