File: xyFromCell.Rd

package info (click to toggle)
r-cran-raster 3.6-31-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,300 kB
  • sloc: cpp: 2,367; ansic: 1,572; sh: 13; makefile: 2
file content (84 lines) | stat: -rw-r--r-- 2,507 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
\name{xyFromCell}

\alias{xFromCol}
\alias{xFromCol,Raster,numeric-method}
\alias{xFromCol,Raster,missing-method}
\alias{yFromRow}
\alias{yFromRow,Raster,numeric-method}
\alias{yFromRow,Raster,missing-method}
\alias{xFromCell}
\alias{xFromCell,Raster,numeric-method}
\alias{yFromCell}
\alias{yFromCell,Raster,numeric-method}
\alias{xyFromCell}
\alias{xyFromCell,BasicRaster-method}
\alias{xyFromCell,BasicRaster,ANY-method}
\alias{xyFromCell,Raster-method}
\alias{xyFromCell,Raster-method}
\alias{coordinates}
\alias{coordinates,Raster-method}
\alias{coordinates,Extent-method}


\title{Coordinates from a row, column or cell number}

\description{
These functions get coordinates of the center of raster cells for a row, column, or cell number of a Raster* object.
}

\usage{
\S4method{xFromCol}{Raster,numeric}(object, col)
\S4method{yFromRow}{Raster,numeric}(object, row)
\S4method{xFromCell}{Raster,numeric}(object, cell)
\S4method{yFromCell}{Raster,numeric}(object, cell)
\S4method{xyFromCell}{BasicRaster,ANY}(object, cell, spatial=FALSE, ...)
\S4method{coordinates}{Raster}(obj, ...)
\S4method{coordinates}{Extent}(obj, ...)
}


\arguments{
  \item{object}{Raster* object (or a SpatialPixels* or SpatialGrid* object)}
  \item{col}{column number; or vector of column numbers. If missing, the x coordinates for all columns are returned}
  \item{row}{row number; or vector of row numbers. If missing, the y coordinates for all rows are returned}
  \item{cell}{cell number(s)}
  \item{spatial}{If \code{spatial=TRUE}, \code{xyFromCell} returns a SpatialPoints object instead of a matrix}
  \item{...}{additional arguments. None implemented}
  \item{obj}{Raster object}
}
  
\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{
xFromCol, yFromCol, xFromCell, yFromCell: vector of x or y coordinates 

xyFromCell: matrix(x,y) with coordinate pairs 

coordinates: xy coordinates for all cells
}


\seealso{
\code{\link{cellFromXY}}
}

\examples{
#using a new default raster (1 degree global)
r <- raster()
xFromCol(r, c(1, 120, 180))
yFromRow(r, 90)
xyFromCell(r, 10000)
xyFromCell(r, c(0, 1, 32581, ncell(r), ncell(r)+1))

#using a file from disk
r <- raster(system.file("external/test.grd", package="raster"))
r
cellFromXY(r, c(180000, 330000))
#xy for corners of a raster:
xyFromCell(r, c(1, ncol(r), ncell(r)-ncol(r)+1, ncell(r)))
}

\keyword{spatial}