1\name{xyFromCell} 2 3\alias{xFromCol} 4\alias{xFromCol,Raster,numeric-method} 5\alias{xFromCol,Raster,missing-method} 6\alias{yFromRow} 7\alias{yFromRow,Raster,numeric-method} 8\alias{yFromRow,Raster,missing-method} 9\alias{xFromCell} 10\alias{xFromCell,Raster,numeric-method} 11\alias{yFromCell} 12\alias{yFromCell,Raster,numeric-method} 13\alias{xyFromCell} 14\alias{xyFromCell,BasicRaster-method} 15\alias{xyFromCell,BasicRaster,ANY-method} 16\alias{xyFromCell,Raster-method} 17\alias{xyFromCell,Raster-method} 18\alias{coordinates} 19\alias{coordinates,Raster-method} 20\alias{coordinates,Extent-method} 21 22 23\title{Coordinates from a row, column or cell number} 24 25\description{ 26These functions get coordinates of the center of raster cells for a row, column, or cell number of a Raster* object. 27} 28 29\usage{ 30\S4method{xFromCol}{Raster,numeric}(object, col) 31\S4method{yFromRow}{Raster,numeric}(object, row) 32\S4method{xFromCell}{Raster,numeric}(object, cell) 33\S4method{yFromCell}{Raster,numeric}(object, cell) 34\S4method{xyFromCell}{BasicRaster,ANY}(object, cell, spatial=FALSE, ...) 35\S4method{coordinates}{Raster}(obj, ...) 36\S4method{coordinates}{Extent}(obj, ...) 37} 38 39 40\arguments{ 41 \item{object}{Raster* object (or a SpatialPixels* or SpatialGrid* object)} 42 \item{col}{column number; or vector of column numbers. If missing, the x coordinates for all columns are returned} 43 \item{row}{row number; or vector of row numbers. If missing, the y coordinates for all rows are returned} 44 \item{cell}{cell number(s)} 45 \item{spatial}{If \code{spatial=TRUE}, \code{xyFromCell} returns a SpatialPoints object instead of a matrix} 46 \item{...}{additional arguments. None implemented} 47 \item{obj}{Raster object} 48} 49 50\details{ 51Cell numbers start at 1 in the upper left corner, and increase from left to right, and then from top to bottom. 52The last cell number equals the number of cells of the Raster* object. 53} 54 55\value{ 56xFromCol, yFromCol, xFromCell, yFromCell: vector of x or y coordinates 57 58xyFromCell: matrix(x,y) with coordinate pairs 59 60coordinates: xy coordinates for all cells 61} 62 63 64\seealso{ 65\code{\link{cellFromXY}} 66} 67 68\examples{ 69#using a new default raster (1 degree global) 70r <- raster() 71xFromCol(r, c(1, 120, 180)) 72yFromRow(r, 90) 73xyFromCell(r, 10000) 74xyFromCell(r, c(0, 1, 32581, ncell(r), ncell(r)+1)) 75 76#using a file from disk 77r <- raster(system.file("external/test.grd", package="raster")) 78r 79cellFromXY(r, c(180000, 330000)) 80#xy for corners of a raster: 81xyFromCell(r, c(1, ncol(r), ncell(r)-ncol(r)+1, ncell(r))) 82} 83 84\keyword{spatial} 85