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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jan 9 10:34:24 CET 2009


Author: rhijmans
Date: 2009-01-09 10:34:23 +0100 (Fri, 09 Jan 2009)
New Revision: 109

Modified:
   pkg/raster/R/raster.read.R
   pkg/raster/R/stack.read.R
Log:
bugs

Modified: pkg/raster/R/raster.read.R
===================================================================
--- pkg/raster/R/raster.read.R	2009-01-09 03:21:29 UTC (rev 108)
+++ pkg/raster/R/raster.read.R	2009-01-09 09:34:23 UTC (rev 109)
@@ -223,8 +223,12 @@
 			vals <- vector(length=length(uniquecells))
 			vals[] <- NA
 		}	
-		for (i in 1:length(vals[,1])) {
-			res[res[,1]==vals[i,1],2] <- vals[i,2] 
+		if (length((vals) == 1)) {
+			res[res[,1]==vals[1],2] <- vals[2] 
+		} else {
+			for (i in 1:length(vals[,1])) {
+				res[res[,1]==vals[i,1],2] <- vals[i,2] 
+			}	
 		}
 	}	
 	return(res[,2])

Modified: pkg/raster/R/stack.read.R
===================================================================
--- pkg/raster/R/stack.read.R	2009-01-09 03:21:29 UTC (rev 108)
+++ pkg/raster/R/stack.read.R	2009-01-09 09:34:23 UTC (rev 109)
@@ -29,14 +29,23 @@
 
 .stackReadCells <- function(rasterstack, cells) {
 	for (i in 1:nlayers(rasterstack)) {
-		v <- .readCellsRaster(rasterstack at rasters[[i]], cells)
+		v <- .rasterReadCells (rasterstack at rasters[[i]], cells)
 		if (i == 1) {
 			result <- v
 		} else {
-			result <- cbind(result, v[,2])
+			result <- cbind(result, v)
 #			colnames(result)[length(result[1,])] <- rstack at rasters[[i]]@file at shortname
 		}
 	}
+	if (!(is.null(dim(result)))) {
+		for (i in 1:nlayers(rasterstack)) {
+			label <- rasterstack at rasters[[i]]@file at shortname
+			if (nchar(label) == "") { 
+				label <- paste("raster_", i, sep="") 
+			}
+			colnames(result)[i] <- label
+		}
+	}	
 	return(result)
 }
 



More information about the Raster-commits mailing list