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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Feb 25 09:15:28 CET 2009


Author: rhijmans
Date: 2009-02-25 09:15:27 +0100 (Wed, 25 Feb 2009)
New Revision: 297

Modified:
   pkg/raster/R/copyRaster.R
   pkg/raster/R/group.generic.functions.R
   pkg/raster/R/overlay.R
   pkg/raster/man/overlay-methods.Rd
Log:


Modified: pkg/raster/R/copyRaster.R
===================================================================
--- pkg/raster/R/copyRaster.R	2009-02-24 05:56:02 UTC (rev 296)
+++ pkg/raster/R/copyRaster.R	2009-02-25 08:15:27 UTC (rev 297)
@@ -5,6 +5,18 @@
 # Licence GPL v3
 
 
+saveAs <- function(raster, filename, filetype='raster', datatype='FLT4S', overwrite=FALSE) {
+	newr <- setRaster(raster, filename)
+	newr <- setDatatype(newr, datatype)
+	for (r in 1:nrow(newr)) {
+		raster <- readRow(raster, r)
+		newr <- setValues(newr, values(raster))
+		newr <- writeRaster(newr, filetype=filetype, overwrite=overwrite)
+	}
+	return(newr)
+}
+
+
 moveRasterFile <- function(raster, filename, overwrite=FALSE) {
 	r <- copyRasterFile(raster, filename, overwrite)
 	f <- trim(filename(raster))

Modified: pkg/raster/R/group.generic.functions.R
===================================================================
--- pkg/raster/R/group.generic.functions.R	2009-02-24 05:56:02 UTC (rev 296)
+++ pkg/raster/R/group.generic.functions.R	2009-02-25 08:15:27 UTC (rev 297)
@@ -70,12 +70,12 @@
 setMethod("Arith", signature(e1='RasterLayer', e2='RasterLayer'),
     function(e1, e2){ 
 		if ( compare(c(e1, e2)) ) {
-			if (.CanProcessInMemory(e1, 2)) {
-				raster <- setRaster(e1, values=callGeneric(.getRasterValues(e1), .getRasterValues(e2)))
+			if (.CanProcessInMemory(e1, 3)) {
+				raster <- setRaster(e1, values=callGeneric( as.numeric(.getRasterValues(e1)), .getRasterValues(e2)))
 			} else {
 				raster <- setRaster(e1, filename=tempfile())
 				for (r in 1:nrow(e1)) {
-					raster <- setValues(raster, callGeneric( .getRowValues(e1, r), .getRowValues(e2, r) ), r)
+					raster <- setValues(raster, callGeneric( as.numeric(.getRowValues(e1, r)), .getRowValues(e2, r) ), r)
 					raster <- writeRaster(raster)
 				}
 			}	
@@ -88,11 +88,11 @@
 setMethod("Arith", signature(e1='RasterLayer', e2='numeric'),
     function(e1, e2){ 
 		if (.CanProcessInMemory(e1, 2)) {
-			return(setRaster(e1, values=callGeneric(.getRasterValues(e1), e2)))
+			return(setRaster(e1, values=callGeneric(as.numeric(.getRasterValues(e1)), e2) ) )
 		} else {
 			raster <- setRaster(e1, filename=tempfile())
 			for (r in 1:nrow(e1)) {
-				raster <- setValues(raster, callGeneric( .getRowValues(e1, r), e2) , r)
+				raster <- setValues(raster, callGeneric( as.numeric(.getRowValues(e1, r)), e2) , r) 
 				raster <- writeRaster(raster)
 			}
 			return(raster)
@@ -103,11 +103,11 @@
 setMethod("Arith", signature(e1='numeric', e2='RasterLayer'),
     function(e1, e2){ 
 		if (.CanProcessInMemory(e2, 2)) {
-			return(setRaster(e2, values=callGeneric(e1, .getRasterValues(e2))))
+			return(setRaster(e2, values=callGeneric(as.numeric(e1), .getRasterValues(e2))))
 		} else {
 			raster <- setRaster(e2, filename=tempfile())
 			for (r in 1:nrow(e2)) {
-				raster <- setValues(raster, callGeneric(e1, .getRowValues(e2, r)) , r)
+				raster <- setValues(raster, callGeneric(as.numeric(e1), .getRowValues(e2, r)) , r)
 				raster <- writeRaster(raster)
 			}
 			return(raster)

Modified: pkg/raster/R/overlay.R
===================================================================
--- pkg/raster/R/overlay.R	2009-02-24 05:56:02 UTC (rev 296)
+++ pkg/raster/R/overlay.R	2009-02-25 08:15:27 UTC (rev 297)
@@ -85,7 +85,7 @@
 				v[startcell:endcell] <- vals
 			} else {
 				outraster <- setValues(outraster, vals, r)
-				outraster <- writeRaster(outraster, overwrite=overwrite)
+				outraster <- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
 			}	
 			
 			if (r %in% track) {

Modified: pkg/raster/man/overlay-methods.Rd
===================================================================
--- pkg/raster/man/overlay-methods.Rd	2009-02-24 05:56:02 UTC (rev 296)
+++ pkg/raster/man/overlay-methods.Rd	2009-02-25 08:15:27 UTC (rev 297)
@@ -16,15 +16,14 @@
 
 \section{Methods}{
 
-\code{overlay(x, y, ..., fun, filename="", overwrite=FALSE, asInt=FALSE)}
+\code{overlay(x, y, ..., fun, filename="", overwrite=FALSE,  filetype='raster', datatype='FLT4S')}
 
-
   \item{x, y}{RasterLayer objects}
   \item{...}{  additional RasterLayer objects and
   \item{fun}{ the function to be appliepd. This should be a function that takes two numbers as an argument }
   \item{filename}{ filename for the output raster. A valid filename must be provided when the data of the input rasters are on disk }
   \item{overwrite}{logical. If \code{TRUE}, existing files will be overwritten}
-  \item{asInt}{logical. If \code{TRUE} the values will be rounded and stored as integer}
+  \item{filetype}{output file type. Either 'raster', 'ascii' or a supported GDAL 'driver' name see \code{\link[raster]{writeRaster}}}
 }
 }
 



More information about the Raster-commits mailing list