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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Feb 11 17:42:26 CET 2009


Author: rhijmans
Date: 2009-02-11 17:42:26 +0100 (Wed, 11 Feb 2009)
New Revision: 275

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


Modified: pkg/raster/R/mCalc.R
===================================================================
--- pkg/raster/R/mCalc.R	2009-02-11 16:02:56 UTC (rev 274)
+++ pkg/raster/R/mCalc.R	2009-02-11 16:42:26 UTC (rev 275)
@@ -10,25 +10,24 @@
 		stop("function 'fun' returns more than one value") 
 	}
 	filename <- trim(filename)
-	outraster <- setRaster(object, filename)
-	outraster <- setDatatype(outraster, datatype) 
-	v <- vector()
-	for (r in 1:nrow(object)) {
-		object <- readRow(object, r)
-		vals <- apply(values(object), 1, fun)
+	outraster <- setRaster(object at layers[[1]], filename)
+	outraster <- setDatatype(outraster, datatype)
+	if (dataContent(object) == "all") {
+		outraster <- setValues(outraster, apply(values(object), 1, fun)) 
 		if (filename != "") {
+			outRaster <- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
+		}
+	} else {
+		for (r in 1:nrow(object)) {
+			object <- readRow(object, r)
+			vals <- apply(values(object), 1, fun)
 			outraster <- setValues(outraster, vals, r) 
-			outraster <- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
-		} else {
-			v <- c(v, vals)
+			outraster <- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
+			if (r %in% track) {
+				cat('row', r)
+			}
 		}
-		if (r %in% track) {
-			cat('row', r)
-		}
-	}	
-	if (filename == "") {
-		outraster <- setValues(outraster, v) 
-	}
+	}		
 	return(outraster)
 }
 

Modified: pkg/raster/R/read.raster.R
===================================================================
--- pkg/raster/R/read.raster.R	2009-02-11 16:02:56 UTC (rev 274)
+++ pkg/raster/R/read.raster.R	2009-02-11 16:42:26 UTC (rev 275)
@@ -203,7 +203,7 @@
 
 .stackRead <- function(rstack, rownumber, startcol=1, ncolumns=(ncol(rstack)-startcol+1)) {
 	for (i in seq(nlayers(rstack))) {
-		raster <- readPartOfRow(rstack at layers[[i]], rownumber, startcol, ncolumns)
+		raster <- .rasterRead(rstack at layers[[i]], rownumber, startcol, ncolumns)
 		if ( i == 1 )  {
 			rstack at data@values <- matrix(nrow=length(values(raster)), ncol=nlayers(rstack)) 
 			rstack at data@content <- dataContent(raster)



More information about the Raster-commits mailing list