[Raster-commits] r277 - pkg/raster/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Feb 12 05:46:16 CET 2009


Author: rhijmans
Date: 2009-02-12 05:46:16 +0100 (Thu, 12 Feb 2009)
New Revision: 277

Modified:
   pkg/raster/R/calc.R
   pkg/raster/R/mCalc.R
Log:


Modified: pkg/raster/R/calc.R
===================================================================
--- pkg/raster/R/calc.R	2009-02-12 04:01:43 UTC (rev 276)
+++ pkg/raster/R/calc.R	2009-02-12 04:46:16 UTC (rev 277)
@@ -35,6 +35,10 @@
 			outraster <- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
 		}
 	} else if (dataSource(x) == 'disk') {
+		if (!.CanProcessInMemory(x, 1) & filename == '') {
+			filename=tempfile()
+			outraster <- setFilename(outraster, filename )
+		}
 		v <- vector(length=0)
 		starttime <- proc.time()
 		for (r in 1:nrow(x)) {
@@ -54,7 +58,9 @@
 			}
 			
 		}
-		if (filename(outraster) == "") { outraster <- setValues(outraster, v) }
+		if (filename(outraster) == "") { 
+			outraster <- setValues(outraster, v) 
+		}
 	}
 	return(outraster)
 }

Modified: pkg/raster/R/mCalc.R
===================================================================
--- pkg/raster/R/mCalc.R	2009-02-12 04:01:43 UTC (rev 276)
+++ pkg/raster/R/mCalc.R	2009-02-12 04:46:16 UTC (rev 277)
@@ -24,11 +24,19 @@
 		}
 	} else {
 		starttime <- proc.time()
+		if (!.CanProcessInMemory(x, 1) & filename == '') {
+			filename=tempfile()
+			outraster <- setFilename(outraster, filename )
+		}
+		v <- vector(length=0)
 		for (r in 1:nrow(x)) {
 			x <- readRow(x, r)
-			vals <- apply(values(x), 1, fun)
-			outraster <- setValues(outraster, vals, r) 
-			outraster <- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
+			if (filename(outraster)=="") {
+				v <- c(v, apply(values(x), 1, fun))
+			} else {
+				outraster <- setValues(outraster, apply(values(x), 1, fun), r) 
+				outraster <- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
+			}
 			if (r %in% track) {
 				elapsed <- (proc.time() - starttime)[3]
 				tpr <- elapsed /r
@@ -36,6 +44,9 @@
 				cat('row', r, '-', ttg, 'minutes to go\n')
 			}
 		}
+		if (filename(outraster) == "") { 
+			outraster <- setValues(outraster, v) 
+		}
 	}		
 	return(outraster)
 }



More information about the Raster-commits mailing list