[Raster-commits] r274 - in pkg/raster: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Feb 11 17:02:56 CET 2009
Author: rhijmans
Date: 2009-02-11 17:02:56 +0100 (Wed, 11 Feb 2009)
New Revision: 274
Modified:
pkg/raster/R/calc.R
pkg/raster/R/mCalc.R
pkg/raster/man/mCalc.Rd
Log:
Modified: pkg/raster/R/calc.R
===================================================================
--- pkg/raster/R/calc.R 2009-02-11 14:30:57 UTC (rev 273)
+++ pkg/raster/R/calc.R 2009-02-11 16:02:56 UTC (rev 274)
@@ -5,6 +5,8 @@
# Licence GPL v3
+
+
calc <- function(raster, fun=sqrt, filename="", overwrite=FALSE, filetype='raster', datatype='FLT4S') {
if (length(fun(5)) > 1) {
stop("function 'fun' returns more than one value")
Modified: pkg/raster/R/mCalc.R
===================================================================
--- pkg/raster/R/mCalc.R 2009-02-11 14:30:57 UTC (rev 273)
+++ pkg/raster/R/mCalc.R 2009-02-11 16:02:56 UTC (rev 274)
@@ -5,26 +5,30 @@
# Licence GPL v3
-mCalc <- function(object, fun=sum, filename="", overwrite=FALSE, asInt=FALSE) {
+mCalc <- function(object, fun=sum, filename="", overwrite=FALSE, filetype='raster', datatype='FLT4S', track=-1) {
if (length(fun(seq(1:5))) > 1) {
stop("function 'fun' returns more than one value")
}
-
- outraster <- setRaster(object at layers[[1]], filename)
- if (filename(outraster)=="") {
- object <- readAll(object)
- outraster <- setValues(outraster, apply(values(object), 1, fun))
- } else {
- if (asInt) {
- outraster <- setDatatype(outraster, "INT4S")
- }
- for (r in 1:nrow(object)) {
- object <- readRow(object, r)
- vals <- apply(values(object), 1, fun)
+ filename <- trim(filename)
+ outraster <- setRaster(object, filename)
+ outraster <- setDatatype(outraster, datatype)
+ v <- vector()
+ for (r in 1:nrow(object)) {
+ object <- readRow(object, r)
+ vals <- apply(values(object), 1, fun)
+ if (filename != "") {
outraster <- setValues(outraster, vals, r)
- outraster <- writeRaster(outraster, overwrite=overwrite)
+ outraster <- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
+ } else {
+ v <- c(v, vals)
}
- }
+ if (r %in% track) {
+ cat('row', r)
+ }
+ }
+ if (filename == "") {
+ outraster <- setValues(outraster, v)
+ }
return(outraster)
}
Modified: pkg/raster/man/mCalc.Rd
===================================================================
--- pkg/raster/man/mCalc.Rd 2009-02-11 14:30:57 UTC (rev 273)
+++ pkg/raster/man/mCalc.Rd 2009-02-11 16:02:56 UTC (rev 274)
@@ -7,7 +7,7 @@
}
\usage{
-mCalc(object, fun=sum, filename="", overwrite=FALSE, asInt=FALSE)
+mCalc(object, fun=sum, filename="", overwrite=FALSE, filetype='raster', datatype='FLT4S', track=-1)
}
\arguments{
@@ -15,7 +15,9 @@
\item{fun}{ the function to be applied }
\item{filename}{ 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 }
\item{overwrite}{ logical to indicate whether an existing output file should be overwritten }
- \item{asInt}{ logical. If \code{TRUE}, output will be integer values }
+ \item{filetype}{output file type. Either 'raster', 'ascii' or a supported GDAL 'driver' name see \code{\link[raster]{writeRaster}}}
+ \item{datatype}{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. }
}
\details{
More information about the Raster-commits
mailing list