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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Feb 22 14:28:18 CET 2009


Author: rhijmans
Date: 2009-02-22 14:28:17 +0100 (Sun, 22 Feb 2009)
New Revision: 292

Added:
   pkg/raster/R/canProcessInMemory.R
Modified:
   pkg/raster/R/group.generic.functions.R
Log:


Added: pkg/raster/R/canProcessInMemory.R
===================================================================
--- pkg/raster/R/canProcessInMemory.R	                        (rev 0)
+++ pkg/raster/R/canProcessInMemory.R	2009-02-22 13:28:17 UTC (rev 292)
@@ -0,0 +1,25 @@
+# Authors: Robert J. Hijmans, r.hijmans at gmail.com 
+# International Rice Research Institute
+# Date :  January 2009
+# Version 0.8
+# Licence GPL v3
+
+
+.CanProcessInMemory <- function(raster, n=2) {
+	if (ncell(raster) > 2147483647) {
+		return(FALSE) 
+	}
+	cells <- round(1.05 * ncell(raster))
+	gc()
+	w <- options('warn')
+	options('warn'=-1) 
+	r <- try( matrix(NA, ncol=n, nrow=cells), silent=TRUE )
+	options('warn'=w[[1]]) 
+	if (class(r) == "try-error") {
+#	if (memneed > memory.size(max = T)) {
+		return( FALSE )
+	} else {
+		return( TRUE ) 
+	}
+}
+

Modified: pkg/raster/R/group.generic.functions.R
===================================================================
--- pkg/raster/R/group.generic.functions.R	2009-02-22 06:13:17 UTC (rev 291)
+++ pkg/raster/R/group.generic.functions.R	2009-02-22 13:28:17 UTC (rev 292)
@@ -5,16 +5,7 @@
 # Licence GPL v3
 
 
-.CanProcessInMemory <- function(raster, n=2, datasize=16) {
-	memneed <- 1.1 * n * ncell(raster) * datasize / 1048576
-	if (memneed > memory.size(max = T)) {
-		return( FALSE )
-	} else { 
-		return( TRUE ) 
-	}
-}
 
-
 .getRasterValues <- function(x) {
 # need to take care of 'spase'
 	if (dataContent(x) != 'all') {



More information about the Raster-commits mailing list