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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Apr 18 17:48:19 CEST 2009


Author: rhijmans
Date: 2009-04-18 17:48:19 +0200 (Sat, 18 Apr 2009)
New Revision: 416

Modified:
   pkg/raster/R/aggregate.R
Log:


Modified: pkg/raster/R/aggregate.R
===================================================================
--- pkg/raster/R/aggregate.R	2009-04-18 14:23:40 UTC (rev 415)
+++ pkg/raster/R/aggregate.R	2009-04-18 15:48:19 UTC (rev 416)
@@ -45,15 +45,13 @@
 	outRaster <- setRowCol(outRaster, nrows=rsteps, ncols=csteps) 
 	
 	
-	if (na.rm) {
 		# this avoid warning messages 
-		narmfun <- function(x) { 
-			x <- na.omit(x)
-			if (length(x) == 0) { 
-				return(NA)
-			} else { 
-				return( fun(x) )
-			}
+	narmfun <- function(x) { 
+		x <- na.omit(x)
+		if (length(x) == 0) { 
+			return(NA)
+		} else { 
+			return( fun(x) )
 		}
 	}
 	
@@ -82,19 +80,19 @@
 		cols <- rep(rep(1:csteps,each=xfact)[1:ncol(x)], times=yfact)
 		rows <- rep(1, each=(ncol(x) * yfact))
 		v <- vector(length=0)
+		
+		nrows = yfact
+		cells <- cellFromRowCol(x, rows, cols)
 		for (r in 1:rsteps) {
 			startrow <- 1 + (r - 1) * yfact
 			if ( r==rsteps) {
 				endrow <- min(nrow(x), startrow + yfact - 1)
 				nrows <- endrow - startrow + 1
-				theserows <- (startrow * rows)[1:(ncol(x)*nrows)]
+				rows <- rows[1:(ncol(x)*nrows)]
 				cols <- cols[1:(ncol(x)*nrows)]
-			} else {
-				nrows = yfact
-				theserows <- startrow * rows
-			}	
+				cells <- cellFromRowCol(x, rows, cols)
+			} 
 			x <- readRows(x, startrow = startrow, nrows = nrows)
-			cells <- cellFromRowCol(x, theserows, cols)
 			
 			if (na.rm) { 
 				vals <- tapply(values(x), cells, narmfun ) 



More information about the Raster-commits mailing list