[Raster-commits] r395 - in pkg/raster: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Apr 6 10:14:09 CEST 2009
Author: rhijmans
Date: 2009-04-06 10:14:06 +0200 (Mon, 06 Apr 2009)
New Revision: 395
Added:
pkg/raster/R/layerNames.R
pkg/raster/man/bands.Rd
pkg/raster/man/layer.Rd
pkg/raster/man/resolution.Rd
Modified:
pkg/raster/DESCRIPTION
pkg/raster/R/distance.R
pkg/raster/R/layers.R
pkg/raster/R/ncell.R
pkg/raster/man/aggregate.Rd
pkg/raster/man/calc.Rd
pkg/raster/man/cellsFromBbox.Rd
pkg/raster/man/coerce.Rd
pkg/raster/man/dimensions.Rd
pkg/raster/man/distance.Rd
pkg/raster/man/extent.Rd
pkg/raster/man/getRowColCell.Rd
pkg/raster/man/pointdistance.Rd
pkg/raster/man/replacement.Rd
pkg/raster/man/round.Rd
pkg/raster/man/writeadvanced.Rd
pkg/raster/man/zonal.Rd
Log:
Modified: pkg/raster/DESCRIPTION
===================================================================
--- pkg/raster/DESCRIPTION 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/DESCRIPTION 2009-04-06 08:14:06 UTC (rev 395)
@@ -1,8 +1,8 @@
Package: raster
Type: Package
Title: Raster data handling for geographic data analysis and modeling
-Version: 0.8.9-10
-Date: 27-March-2009
+Version: 0.8.9-11
+Date: 6-April-2009
Depends: methods, sp, rgdal (>= 0.5-33), R (>= 2.8.0)
Author: Robert J. Hijmans & Jacob van Etten
Maintainer: Robert J. Hijmans <r.hijmans at gmail.com>
Modified: pkg/raster/R/distance.R
===================================================================
--- pkg/raster/R/distance.R 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/R/distance.R 2009-04-06 08:14:06 UTC (rev 395)
@@ -8,12 +8,13 @@
#setMethod("distance", signature(object = "RasterLayer"), def =
-distance <- function(object, filename="", filetype='raster', overwrite=FALSE, datatype='FLT4S') {
+distance <- function(object, filename="", filetype='raster', overwrite=FALSE, datatype='FLT4S', track=-1) {
n <- ncell(object)
-# if (dataSource = 'disk' & dataContent(object)=='all' & canProcessInMemory(object, 6)) {
-# object <- readAll(object)
-# }
+ if (dataSource(object) == 'disk' & dataContent(object) != 'all' & canProcessInMemory(object, 6)) {
+ object <- readAll(object)
+ }
+
if(dataContent(object)=='all' & canProcessInMemory(object, 5)){
outRaster <- raster(object, filename=filename)
@@ -26,7 +27,7 @@
adj <- adjacency(object,fromCells=fromCells,toCells=toCells,directions=8)
coord <- cbind(xyFromCell(object,adj[,1]),xyFromCell(object,adj[,2]))
distance <- apply(coord,1,function(x){pointDistance(x[1:2],x[3:4], type='GreatCircle')})
- #What follows is the same as for non-projected (below)
+ #What follows is the same as for projected data ( further below)
transitionValues <- accDist[adj[,1]] + distance
transitionValues <- tapply(transitionValues,adj[,2],min)
transitionValues <- transitionValues[transitionValues < Inf]
Added: pkg/raster/R/layerNames.R
===================================================================
--- pkg/raster/R/layerNames.R (rev 0)
+++ pkg/raster/R/layerNames.R 2009-04-06 08:14:06 UTC (rev 395)
@@ -0,0 +1,31 @@
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date: October 2008
+# Version 0.8
+# Licence GPL v3
+
+
+layerNames <- function(object) {
+ if (class(object) == "RasterLayer") {
+ return(object at file@shortname)
+ } else if (class(object) == "RasterStack") {
+ return(object at data@colnames)
+ }
+}
+
+
+'layerNames<-' <- function(object, value) {
+ if (length(value) != nlayers(object)) {
+ stop('value has wrong length')
+ }
+ if (class(object) == "RasterLayer") {
+ object at file@shortname <- value
+ return(object)
+ } else if (class(object) == "RasterStack") {
+ object at data@colnames <- value
+ if (length(unique(object at data@colnames)) != nlayers(object)) {
+ stop('layer names must be unique')
+ }
+ return(object)
+ }
+}
Modified: pkg/raster/R/layers.R
===================================================================
--- pkg/raster/R/layers.R 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/R/layers.R 2009-04-06 08:14:06 UTC (rev 395)
@@ -1,7 +1,7 @@
# Author: Robert J. Hijmans, r.hijmans at gmail.com
# International Rice Research Institute
# Date : October 2008
-# Version 0,7
+# Version 0.8
# Licence GPL v3
@@ -38,15 +38,3 @@
}
)
-
-layerNames <- function(object) {
- if (class(object) == "RasterLayer") {
- return(filename(object))
- } else if (class(object) == "RasterStack") {
- l <- vector('character')
- for (i in 1:nlayers(object)) {
- l <- c(l, filename(asRasterLayer(object, i)))
- }
- return(l)
- }
-}
Modified: pkg/raster/R/ncell.R
===================================================================
--- pkg/raster/R/ncell.R 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/R/ncell.R 2009-04-06 08:14:06 UTC (rev 395)
@@ -1,4 +1,10 @@
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date : April 2009
+# Version 0.8
+# Licence GPL v3
+
if (!isGeneric("ncell")) {
setGeneric("ncell", function(x)
standardGeneric("ncell"))
@@ -7,8 +13,19 @@
setMethod('ncell', signature(x='ANY'),
function(x) {
d <- dim(x)
+ if (is.null(d)) {
+ return(length(x))
+ }
# return numeric to avoid integer overflow
- return(as.numeric(d[1]) * d[2])
+ t <- as.numeric(d[1]) * d[2]
+ if (length(d) == 2) {
+ return(t)
+ } else {
+ for (i in 3:length(d)) {
+ t <- t * d[i]
+ }
+ return(t)
+ }
}
)
Modified: pkg/raster/man/aggregate.Rd
===================================================================
--- pkg/raster/man/aggregate.Rd 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/man/aggregate.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -5,7 +5,7 @@
\alias{aggregate}
\alias{aggregate,RasterLayer-method}
-\title{aggregate}
+\title{Aggregate}
\description{
Aggregate a RasterLayer to create a new RasterLayer with a lower resolution (larger cells).
Added: pkg/raster/man/bands.Rd
===================================================================
--- pkg/raster/man/bands.Rd (rev 0)
+++ pkg/raster/man/bands.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -0,0 +1,36 @@
+\name{bands}
+
+\alias{band}
+\alias{nbands}
+
+\title{Bands}
+
+\description{
+A 'band' is term frequently used in remote sensing to refer to a variable (layer) in a multi-variable raster file or dataset. In remote sensing
+these bands could be stored in seperate files. Here a band refers to a single layer for a possibly multi-layer file. Most RasterLayer objects
+will refer to files with a single band. \code{nbands} returns the number of bands of the file a RasterLayer points to (and 1 if it does not
+point at any file), and \code{band} returns the specific band the RasterLayer refers to (1 if the RasterLayer points at single layer file or does not
+point at any file).
+}
+
+\usage{
+band(object)
+nbands(object)
+}
+
+\arguments{
+ \item{object}{RasterLayer object}
+}
+
+\value{
+a numeric value >= 1
+}
+
+\author{Robert J. Hijmans }
+\examples{
+r <- raster()
+nbands(r)
+band(r)
+}
+
+\keyword{spatial}
Modified: pkg/raster/man/calc.Rd
===================================================================
--- pkg/raster/man/calc.Rd 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/man/calc.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -7,7 +7,7 @@
\alias{calc,RasterStack,function-method}
\alias{calc,RasterStack,list-method}
-\title{ calculate }
+\title{Calculate}
\description{
Calculate values for a new RasterLayer, from a single RasterLayer or from a RasterStack
Modified: pkg/raster/man/cellsFromBbox.Rd
===================================================================
--- pkg/raster/man/cellsFromBbox.Rd 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/man/cellsFromBbox.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -18,7 +18,7 @@
\item{bndbox}{An object of class BoundingBox (which you can create with newBbox() )}
\item{expand}{Logical. If \code{TRUE}, \code{NA} is returned for (virtual) cells implied by \code{bndbox},
that are outside the RasterLayer (\code{object}). If \code{FALSE}, only cell numbers for the area where \code{object} and \code{bndbox}
- overlap are returned (see \link[raster]{intersectBbox} }
+ overlap are returned (see \link[raster]{intersectBbox}) }
}
\value{
Modified: pkg/raster/man/coerce.Rd
===================================================================
--- pkg/raster/man/coerce.Rd 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/man/coerce.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -9,9 +9,14 @@
\description{
Functions to coerce a SpatialGridDataFrame, SpatialPixelsDataFrame, and RasterStack objects to a RasterLayer object.
-You can use \code{as( , )} for this type of coercion (see examples), and for many other coercions between sp and raster objects,
-but asRasterLayer allows for indicating which variable should be passed to the RasterLayer object.
-RasterLayer objects only have a single variable, whereas a RasterStack and the Spatial* objects can have multiple variables.
+You can use
+
+\code{as( , )}
+
+for this type of coercion (see examples), and other coercions between sp and raster objects,
+but \code{asRasterLayer} allows for indicating which variable should be passed to the \code{RasterLayer} object.
+While \code{RasterLayer} objects only have a single variable, a \code{RasterStack} and the \code{Spatial * DataFrame}
+ objects can have multiple variables.
}
\usage{
Modified: pkg/raster/man/dimensions.Rd
===================================================================
--- pkg/raster/man/dimensions.Rd 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/man/dimensions.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -7,68 +7,37 @@
\alias{dim,BasicRaster-method}
\alias{ncell}
\alias{ncell,ANY-method}
-\alias{length,Raster-method}
-\alias{xres}
-\alias{yres}
-\alias{resolution}
-\alias{nlayers}
-\alias{nlayers,BasicRaster-method}
-\alias{nlayers,Raster-method}
-\alias{nlayers,RasterStack-method}
-\alias{nlayers,Spatial-method}
-\alias{layerNames}
-\alias{band}
-\alias{nbands}
-
+
\title{Dimensions}
\description{
- Get dimension properties of a Raster* object
+ Get the number of rows, columns, or cells of a Raster* object
}
\usage{
ncol(x)
nrow(x)
ncell(x)
-xres(object)
-yres(object)
-resolution(object)
-nlayers(object)
-layerNames(object)
-band(object)
-nbands(object)
}
\arguments{
- \item{object}{Raster* object}
- \item{x}{Raster* object}
+ \item{x}{a Raster* object}
}
-\note{
- Some of these functions simply take the values from the data slots in the Raster* object.
- It is advisable to use these and other 'getter' functions rather than dirctly accessing the slots of an object.
- This will ensure that code will not break in the future, even if the underlying class definitions change.
-}
-
\value{
- in most cases a single numeric
-
+ in most cases a single numeric value
}
+\seealso{ \code{\link[raster]{extent}}, \code{\link[raster]{resolution}} }
+
+
\author{Robert J. Hijmans }
\examples{
-#using a new default raster (1 degree global)
r <- raster()
ncell(r)
ncol(r)
nrow(r)
-ncell(r)
-xres(r)
-yres(r)
-resolution(r)
-origin(r)
-nbands(r)
-band(r)
}
\keyword{spatial}
+
Modified: pkg/raster/man/distance.Rd
===================================================================
--- pkg/raster/man/distance.Rd 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/man/distance.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -5,23 +5,35 @@
\alias{distance,RasterLayer-method}
-\title{distance}
+\title{Distance}
\description{
- The function calculates the distance to cells of a RasterLayer that are \code{<= 0}.
+ The function calculates the distance to cells of a RasterLayer that are \code{NA}.
- The distance is in meters if the RasterLayer is in a geographic (latlon) projection and in map units when not projected.
+ The distance is in meters if the RasterLayer is not projected (\code{+proj=longlat})
+ and in map units (typically meters) when it is projected.
Distances are calculated by summing local distances between cells, which are connected with their neighbours in 8 directions.
-
- For more options (directions, cost-distance) see the gdistance package.
}
-\section{Methods}{
-\describe{
+\usage{
+distance(object, filename = "", filetype = "raster", overwrite = FALSE, datatype = "FLT4S", track=-1)
+}
-\item{raster = "RasterLayer"}{ ~~describe this method here }
-}}
+\arguments{
+\item{object}{a RasterLayer object}
+\item{filename}{character. output filename}
+\item{overwrite}{logical. If \code{TRUE}, "filename" will be overwritten if it exists}
+\item{filetype}{character. output file type. Either 'raster', 'ascii' or a supported GDAL 'driver' name see \code{\link[raster]{rasterFormats}}}
+\item{datatype}{character. output data type; see \code{\link[raster]{setDatatype}}}
+\item{track}{vector of row numbers for which the function will report that they have been processed}
+}
+
+
+
+\seealso{ For more options (directions, cost-distance) see the \code{ \link[gdistance]{gdistance}} package }
+
+
\examples{
r1 <- raster(ncol=36,nrow=18)
r1[] <- 0
Modified: pkg/raster/man/extent.Rd
===================================================================
--- pkg/raster/man/extent.Rd 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/man/extent.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -36,6 +36,9 @@
a single number or (for \code{origin}, a vector of two numbers.
}
+\seealso{ \code{\link[raster]{dimensions}} }
+
+
\author{Robert J. Hijmans }
\examples{
Modified: pkg/raster/man/getRowColCell.Rd
===================================================================
--- pkg/raster/man/getRowColCell.Rd 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/man/getRowColCell.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -46,13 +46,12 @@
\author{Robert J. Hijmans }
\examples{
-#using a new default raster (1 degree global)
-r <- raster()
-colFromCell(r, 10000)
-rowFromCell(r, 10000)
+r <- raster(ncols=10, nrows=10)
+colFromCell(r, c(5,15))
+rowFromCell(r, c(5,15))
cellFromRowCol(r, 5, 5)
-cellFromRowCol(r, 4:5, 4:5)
-cellFromRowColCombine(r, 4:5, 4:5)
+cellFromRowCol(r, 1:2, 1:2)
+cellFromRowColCombine(r, 1:3, 1:2)
cellFromCol(r, 1)
cellFromRow(r, 1)
Added: pkg/raster/man/layer.Rd
===================================================================
--- pkg/raster/man/layer.Rd (rev 0)
+++ pkg/raster/man/layer.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -0,0 +1,48 @@
+\name{dimensions}
+
+\alias{nlayers}
+\alias{nlayers,BasicRaster-method}
+\alias{nlayers,Raster-method}
+\alias{nlayers,RasterStack-method}
+\alias{nlayers,Spatial-method}
+\alias{layerNames}
+\alias{layerNames<-}
+
+\title{Layers}
+
+\description{
+Get layer properties of a RasterStack object
+}
+
+\usage{
+nlayers(object)
+layerNames(object)
+layerNames(object) <- value
+}
+
+\arguments{
+ \item{object}{Raster* object}
+ \item{value}{a vector of character}
+}
+
+\value{
+nlayers: A single numeric value >= 1
+layerNames: a vector of character
+}
+
+\seealso{ \code{\link[raster]{bands}} }
+
+
+\author{Robert J. Hijmans }
+\examples{
+#using a new default raster (1 degree global)
+r <- raster(ncols=10, nrows=10)
+r[] <- 1:ncell(r)
+s <- stack(r, r, r)
+nlayers(s)
+layerNames(s)
+layerNames(s) <- c('a', 'b', 'c')
+layerNames(s)[2] <- c('bb')
+}
+
+\keyword{spatial}
Modified: pkg/raster/man/pointdistance.Rd
===================================================================
--- pkg/raster/man/pointdistance.Rd 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/man/pointdistance.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -2,7 +2,7 @@
\alias{pointDistance}
-\title{distance between points}
+\title{Distance between points}
\description{
Calculate the geographic distance between two points on a sphere (\code{type='GreatCircle'}) or on a plane (\code{type='Euclidean'}).
@@ -21,7 +21,7 @@
}
\details{
A sphere is an approximation for the earth (a spheroid) and type='Greatcircle' can thus be used with geographic
- coordinates (latitude & longitude). There are probably more sophisticated functions available in other packages.
+ coordinates (latitude & longitude).
You can use type='Euclidean' for coordinates of a map projection such as UTM (but note that in some projections distance is distorted).
}
Modified: pkg/raster/man/replacement.Rd
===================================================================
--- pkg/raster/man/replacement.Rd 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/man/replacement.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -10,33 +10,52 @@
\alias{[<-,RasterLayer-method}
\alias{[<-,RasterLayer,ANY,missing-method}
-\title{ Replace methods }
+\title{Replace methods}
\description{
- \code{[} is sometimes equivalent to setValues()
+ \code{object[x]} can be used to access or set values of a RasterLayer object, using cell numbers as index.
+ \code{object[[x]]} can be used to access values of a RasterLayer object, using row and column numbers as index.
}
+
\section{Methods}{
\describe{
- if r is a RasterLayer, r[] is valid with a single index (cell number)
- e.g.: r[1], r[6:15]
- r[[]] is valid with two indices
- e.g.: r[[1,1]], r[[1,]]
+\code{object[x]}
+
+\code{object[x] <- value}
+
+\code{object[[r,c]]}
+
+Arguments
+\tabular{rll}{
+\tab \code{object} \tab a RasterLayer object \cr
+\tab \code{x} \tab cell number(s) \cr
+\tab \code{r} \tab row number(s) \cr
+\tab \code{c} \tab column number(s) \cr
+\tab \code{value} \tab value(s) \cr
+}
+
}}
\examples{
r <- raster(ncol=10, nrow=5)
r[] <- 1:ncell(r) * 2
+values(r)
r[1]
-
r[1:10]
r[3:8] <- NA
r[1:10]
-#r[[,1]]
-#r[[1,]]
-
+values(r, format='matrix')
+#equivalent to
+r[[1,1]]
+r[[1:2,1:2]]
+#first column
+r[[,1]]
+# first row
+r[[1,]]
+r[[]]
}
\keyword{methods}
Added: pkg/raster/man/resolution.Rd
===================================================================
--- pkg/raster/man/resolution.Rd (rev 0)
+++ pkg/raster/man/resolution.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -0,0 +1,39 @@
+\name{resolution}
+
+\alias{xres}
+\alias{yres}
+\alias{resolution}
+
+\title{Resolution}
+
+\description{
+ Get resolution properties of a Raster* object
+}
+
+\usage{
+xres(object)
+yres(object)
+resolution(object)
+}
+
+\arguments{
+ \item{object}{Raster* object}
+}
+
+
+\value{
+A single numeric value or two numeric values.
+}
+
+\seealso{ \code{\link[raster]{extent}}, \code{\link[raster]{dimensions}} }
+
+
+\author{Robert J. Hijmans }
+\examples{
+r <- raster(ncol=18, nrow=18)
+xres(r)
+yres(r)
+resolution(r)
+}
+
+\keyword{spatial}
Modified: pkg/raster/man/round.Rd
===================================================================
--- pkg/raster/man/round.Rd 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/man/round.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -12,13 +12,13 @@
\description{
These functions take a single RasterLayer argument \code{x} and change its values to integers.
-ceiling returns a RasterLayer with the smallest integers not less than the corresponding values of x.
+\code{ceiling} returns a RasterLayer with the smallest integers not less than the corresponding values of x.
-floor returns a RasterLayer with the largest integers not greater than the corresponding values of x.
+\code{floor} returns a RasterLayer with the largest integers not greater than the corresponding values of x.
-trunc returns a RasterLayer with the integers formed by truncating the values in x toward 0.
+\code{trunc} returns a RasterLayer with the integers formed by truncating the values in x toward 0.
-round returns a RasterLayer with values rounded to the specified number of digits (decimal places; default 0).
+\code{round} returns a RasterLayer with values rounded to the specified number of digits (decimal places; default 0).
}
Modified: pkg/raster/man/writeadvanced.Rd
===================================================================
--- pkg/raster/man/writeadvanced.Rd 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/man/writeadvanced.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -9,14 +9,16 @@
\description{
low level functions for programmers
-canProcessInMemory is typically used within functions. It returns a logical value, indicating whether the values can be computed in memory.
+\code{canProcessInMemory} is typically used within functions.
In the raster package this function is used to determine wether values should be written to disk (in a temporary file) or not when there was
no filename supplied to the function.
-closeHandle removes the handle to the file on disk that was established by raster(x) (where x is a filename).
+closeConnection removes the handle to the file on disk that was established by raster(x) (where x is a filename).
After the handle is closed, you can no longer read data from the file through the RasterLayer object.
You probably do not need to do this; unless you get problems with files that cannot be overwritten (rm()
does not immediately remove the handle; it seems).
+
+resetConnection will restore the file connection if it has been lost (e.g. after saving a RasterLayer object to disk).
}
\usage{
Modified: pkg/raster/man/zonal.Rd
===================================================================
--- pkg/raster/man/zonal.Rd 2009-04-06 04:10:27 UTC (rev 394)
+++ pkg/raster/man/zonal.Rd 2009-04-06 08:14:06 UTC (rev 395)
@@ -5,7 +5,7 @@
\title{Zonal statistics}
\description{
-Compute zonal statistics. I.e. the values of the cells of a RasterLayer based on the values of the "zones" RasterLayer.
+Compute zonal statistics. That is, cross-tabulate the values of a RasterLayer based on a "zones" RasterLayer.
}
\usage{
@@ -32,7 +32,7 @@
\examples{
r <- raster(ncols=10, nrows=10)
-r[] <- runif(ncell(r))
+r[] <- runif(ncell(r)) * 1:ncell(r)
z <- r
z[] <- rep(1:5, each=20)
zonal(r, z, 'mean')
More information about the Raster-commits
mailing list