[Raster-commits] r169 - in pkg/raster: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 22 06:36:17 CET 2009


Author: jacobvanetten
Date: 2009-01-22 06:36:16 +0100 (Thu, 22 Jan 2009)
New Revision: 169

Added:
   pkg/raster/man/makeBrick.Rd
Modified:
   pkg/raster/R/brick.create.R
Log:
makeBrick

Modified: pkg/raster/R/brick.create.R
===================================================================
--- pkg/raster/R/brick.create.R	2009-01-21 14:35:30 UTC (rev 168)
+++ pkg/raster/R/brick.create.R	2009-01-22 05:36:16 UTC (rev 169)
@@ -22,3 +22,31 @@
 brickFromFile <- function(filename, values=FALSE) {
 	stop("not implemented yet")
 }
+
+setGeneric("makeBrick", function(object, ...) standardGeneric("makeBrick"))
+
+setMethod('makeBrick', signature(object='RasterLayer'), function(object, ...)
+	{ 
+		RLlist <- list(...)
+		if (dataContent(object) != 'all'){stop("rasterBricks can only be created from RasterLayers with all data in memory")}
+		for (i in seq(along=object))
+		{
+			if (as(RLlist[[i]],"BasicRaster") != as(RLlist[[i]],"BasicRaster")){stop("RasterLayer objects are not equal in extent, resolution and/or projection")}
+			if (class(RLlist[[i]]) != "RasterLayer"){stop("function only implemented for objects of same class")}
+			if (dataContent(RLlist[[i]]) != 'all'){stop("rasterBricks can only be created when all RasterLayer data are in memory")}
+		}
+		datavalues <- matrix(nrow=ncell(object),ncol=1+length(RLlist))
+		datavalues[,1] <- values(object)
+		for (j in seq(along=object))
+		{
+			datavalues[,j+1] <- values(RLlist[[j]])		
+		}
+		brick <- new("RasterBrick", bbox = getBbox(object), crs=projection(object, asText = FALSE), ncols = ncol(object), nrows = nrow(object))
+		brick at data@values <- datavalues
+		brick at data@nlayers <- as.integer(1+length(RLlist))
+		brick at data@content <- "all"
+		return(brick)
+	}
+)
+
+#makeBrick should also be defined for signature Bbox, RasterStack, and even filename  could be considered.

Added: pkg/raster/man/makeBrick.Rd
===================================================================
--- pkg/raster/man/makeBrick.Rd	                        (rev 0)
+++ pkg/raster/man/makeBrick.Rd	2009-01-22 05:36:16 UTC (rev 169)
@@ -0,0 +1,16 @@
+\name{makeBrick}
+\docType{methods}
+\alias{makeBrick}
+\alias{makeBrick-methods}
+\alias{makeBrick,RasterLayer-method}
+\title{ Create a RasterBrick object}
+\description{
+ RasterBrick can be created from several objects.
+}
+\section{Methods}{
+\describe{
+
+\item{object = "RasterLayer"}{ make a RasterBrick from one or more RasterLayers }
+}}
+\keyword{methods}
+\keyword{spatial}



More information about the Raster-commits mailing list