[Raster-commits] r462 - in pkg/raster: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed May 20 14:29:54 CEST 2009


Author: rhijmans
Date: 2009-05-20 14:29:54 +0200 (Wed, 20 May 2009)
New Revision: 462

Added:
   pkg/raster/R/predict.R
   pkg/raster/man/predict.Rd
Log:


Added: pkg/raster/R/predict.R
===================================================================
--- pkg/raster/R/predict.R	                        (rev 0)
+++ pkg/raster/R/predict.R	2009-05-20 12:29:54 UTC (rev 462)
@@ -0,0 +1,31 @@
+
+if (!isGeneric("predict")) {
+	setGeneric("predict", function(object, ...)
+		standardGeneric("predict"))
+}	
+
+setMethod('predict', signature(object='RasterStack'), 
+	function(object, model, filename="", datatype='INT4S', filetype = 'raster', overwrite=FALSE, track=-1, ...) {
+		predrast <- raster(object)
+		filename(predrast) <- filename
+		dataType(predrast) <- datatype
+		myIdVar <- 1:ncol(object)
+		predv <- 1:ncol(object)
+		for (r in 1:nrow(object)) {
+			object <- readRow(object, r)
+			rowvals <- na.omit( cbind(myIdVar, values(object, names=TRUE)) )
+			indices <- rowvals[,1]
+			predv[] <- NA
+			if (length(indices) > 0) {
+				pred <- predict(model, rowvals[,-1], ...)
+				predv[indices] <- pred
+			}
+			predrast <- setValues(predrast, predv, r)
+			predrast <- writeRaster(predrast, filetype=filetype, overwrite=overwrite)
+		}
+		return(predrast)
+	}
+)
+
+
+	
\ No newline at end of file

Added: pkg/raster/man/predict.Rd
===================================================================
--- pkg/raster/man/predict.Rd	                        (rev 0)
+++ pkg/raster/man/predict.Rd	2009-05-20 12:29:54 UTC (rev 462)
@@ -0,0 +1,54 @@
+\name{predict}
+
+\docType{methods}
+
+\alias{predict}
+\alias{predict,RasterStack-method}
+
+\title{Predict}
+
+\description{
+ Predict values for a fitted model object and a RasterStack as independent variables
+}
+
+\usage{
+predict(object, ...) 
+}
+
+
+\arguments{
+  \item{object}{a RasterStack object}
+  \item{...}{Additional arguments. See below, under Methods}  
+}
+
+\section{Methods}{
+\describe{
+ 
+\code{predict(object, ...,  model, filename='', overwrite=FALSE, filetype='raster', datatype='FLT4S')}
+  
+\tabular{rll}{  
+  \tab  \code{object} \tab a RasterStack object \cr
+  \tab  \code{model}  \tab A fitted model\cr
+  \tab  \code{filename}  \tab Output filename for a new raster; if NA the result is not written to a file but returned with the RasterLayer object, in the data slot \cr
+  \tab  \code{overwrite}  \tab Logical to indicate whether an existing output file should be overwritten \cr
+  \tab  \code{filetype}  \tab output file type. Either 'raster', 'ascii' or a supported GDAL 'driver' name see \code{\link[raster]{writeRaster}} \cr
+  \tab  \code{datatype}  \tab output data type; see \code{\link[raster]{dataType}} \cr
+  \tab  \code{track}  \tab vector of row numbers for which the function will report that they have been processed \cr
+}
+
+}}
+
+\details{
+}
+
+\value{
+a RasterLayer object
+}
+
+\author{ Robert J. Hijmans}
+
+\examples{
+}
+
+\keyword{methods}
+\keyword{spatial}



More information about the Raster-commits mailing list