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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Mar 13 03:41:30 CET 2009


Author: rhijmans
Date: 2009-03-13 03:41:28 +0100 (Fri, 13 Mar 2009)
New Revision: 345

Added:
   pkg/raster/R/hist.R
Modified:
   pkg/raster/R/plot.R
Log:


Added: pkg/raster/R/hist.R
===================================================================
--- pkg/raster/R/hist.R	                        (rev 0)
+++ pkg/raster/R/hist.R	2009-03-13 02:41:28 UTC (rev 345)
@@ -0,0 +1,37 @@
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date :  June 2008
+# Version 0.8
+# Licence GPL v3
+
+setMethod('hist', signature(x='RasterStack'), 
+	function(x, layer=1, maxsamp=10000, ...) {
+		x <- asRasterLayer(x, layer)
+		callNextMethod(x, maxsamp=10000, ...)
+	}
+)
+
+setMethod('hist', signature(x='Raster'), 
+	function(x, maxsamp=10000, ...){
+		if (dataContent(x) != 'all') {
+			if (dataSource(x) == 'disk') {
+		# TO DO: make a function that does this by block and combines  all data into a single histogram
+
+				if (ncell(x) <= maxsamp) {
+					values <- na.omit(values(readAll(x)))
+				} else {
+					values <- sampleRandom(x, maxsamp)
+					msg <- paste(round(100 * maxsamp / ncell(x)), "% of the raster cells were used", sep="")
+					if (maxsamp > length(values)) {
+						msg <- paste(msg, " (of which ", 100 - round(100 * length(values) / maxsamp ), "% were NA)", sep="")
+					}
+					msg <- paste(msg, ". ",length(values)," values used.", sep="")
+					warning(msg)
+				}	
+			} else { stop('cannot make a histogram; need data on disk or in memory')}
+		} else {
+			values <- values(x)
+		}			
+		hist(values, ...)
+	}	
+)

Modified: pkg/raster/R/plot.R
===================================================================
--- pkg/raster/R/plot.R	2009-03-12 06:24:27 UTC (rev 344)
+++ pkg/raster/R/plot.R	2009-03-13 02:41:28 UTC (rev 345)
@@ -58,29 +58,3 @@
 )
 	
 
-setMethod('hist', signature(x='Raster'), 
-	function(x, layer=1, maxsamp=10000, ...){
-		if (dataContent(x) != 'all') {
-			if (dataSource(x) == 'disk') {
-		# TO DO: make a function that does this by block and combines  all data into a single histogram
-
-				x <- asRasterLayer(x, layer)
-				if (ncell(x) <= maxsamp) {
-					values <- na.omit(values(readAll(x)))
-				} else {
-					values <- sampleRandom(x, maxsamp)
-					msg <- paste(round(100 * maxsamp / ncell(x)), "% of the raster cells were used", sep="")
-					if (maxsamp > length(values)) {
-						msg <- paste(msg, " (of which ", 100 - round(100 * length(values) / maxsamp ), "% were NA)", sep="")
-					}
-					msg <- paste(msg, ". ",length(values)," values used.", sep="")
-					warning(msg)
-				}	
-			} else { stop('cannot make a histogram; need data on disk or in memory')}
-		} else {
-			values <- values(x)
-		}			
-		hist(values, ...)
-	}	
-)
-



More information about the Raster-commits mailing list