raster (version 1.1.7)

cellFrom: Get cell, row, or column number

Description

Get cell number(s) of a Raster* object from row and/or column numbers. 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.

Usage

cellFromRowCol(object, rownr, colnr)
cellFromRowColCombine(object, rownr, colnr)
cellFromRow(object, rownr)
cellFromCol(object, colnr)
colFromX(object, x)
rowFromY(object, y)
cellFromXY(object, xy)

Arguments

object
Raster* object (or a SpatialPixels* or SpatialGrid* object)
colnr
column number; or vector of column numbers
rownr
row number; or vector of row numbers
x
x coordinate(s)
y
y coordinate(s)
xy
matrix of x and y coordinates, or a SpatialPoints or SpatialPointsDataFrame object

Value

  • row, column or cell number(s)

Details

In cellFromRowCol, rownr and colnr should have the same length. This is not the case for cellFromRowColCombine. This function returns the cell numbers obtained by the combination of row and column numbers.

Examples

Run this code
r <- raster(ncols=10, nrows=10)
cellFromRowCol(r, 5, 5)
cellFromRowCol(r, 1:2, 1:2)
cellFromRowColCombine(r, 1:3, 1:2)
cellFromCol(r, 1)
cellFromRow(r, 1)
colFromX(r, 0.5)
rowFromY(r, 0.5)
cellFromXY(r, c(0.5, 0.5))

Run the code above in your browser using DataCamp Workspace