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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Apr 13 07:53:18 CEST 2009


Author: rhijmans
Date: 2009-04-13 07:53:17 +0200 (Mon, 13 Apr 2009)
New Revision: 403

Modified:
   pkg/raster/R/calc.R
   pkg/raster/R/disaggregate.R
   pkg/raster/R/plot.R
   pkg/raster/R/raster.R
   pkg/raster/R/setFilename.R
   pkg/raster/man/plot.Rd
Log:


Modified: pkg/raster/R/calc.R
===================================================================
--- pkg/raster/R/calc.R	2009-04-12 16:03:59 UTC (rev 402)
+++ pkg/raster/R/calc.R	2009-04-13 05:53:17 UTC (rev 403)
@@ -16,7 +16,6 @@
 		stop("function 'fun' returns more than one value") 
 	}
 	
-	filename <- trim(filename)
 	outraster <- raster(x, filename)
 	dataType(outraster) <- datatype
 	

Modified: pkg/raster/R/disaggregate.R
===================================================================
--- pkg/raster/R/disaggregate.R	2009-04-12 16:03:59 UTC (rev 402)
+++ pkg/raster/R/disaggregate.R	2009-04-13 05:53:17 UTC (rev 403)
@@ -35,6 +35,12 @@
 		}
 		
 	} else if ( dataSource(raster) == 'disk') { 
+		if (!canProcessInMemory(raster, 3) && filename == '') {
+			filename <- tempfile()
+			filename(outraster) <- filename
+			if (options('verbose')[[1]]) { cat('writing raster to:', filename(raster))	}						
+		}
+	
 		starttime <- proc.time()
 		
 		v <- vector(length=0)

Modified: pkg/raster/R/plot.R
===================================================================
--- pkg/raster/R/plot.R	2009-04-12 16:03:59 UTC (rev 402)
+++ pkg/raster/R/plot.R	2009-04-13 05:53:17 UTC (rev 403)
@@ -5,18 +5,44 @@
 # Licence GPL v3
 
 
-
-setMethod("plot", signature(x='Raster', y='missing'), 
+setMethod("plot", signature(x='RasterStack', y='ANY'), 
 	function(x, y, ...)  {
-		.plotraster(x, index=1, col=rev(terrain.colors(25)), subsample=TRUE, maxdim=500, addbox=TRUE, axes = TRUE, xlab="", ylab="", ...) 
+		if (missing(y)) {
+			nl <- nlayers(x)
+			if (nl > 25) {
+				warning('only first 25 layers are mapped')
+				nl <- 25
+			}
+			nc <- ceiling(sqrt(nl))
+			nr <- ceiling(nl / nc)
+			par(mfrow=c(nr, nc))
+			for (i in 1:nl) {
+				.plotraster(x, index=i, col=rev(terrain.colors(25)), subsample=TRUE, maxdim=500, addbox=TRUE, axes = TRUE, xlab="", ylab="", ...) 
+			}
+		} else if (is.numeric(y)) {
+			y <- unique(as.integer(round(y)))
+			if (length(y) > 1) {
+				nl <- length(y)
+				nc <- ceiling(sqrt(nl))
+				nr <- ceiling(nl / nc)
+				par(mfrow=c(nr, nc))
+				par(mfrow=c(nr, nc))
+				for (i in 1:length(y)) {
+					.plotraster(x, index=y[i], col=rev(terrain.colors(25)), subsample=TRUE, maxdim=500, addbox=TRUE, axes = TRUE, xlab="", ylab="", ...) 
+				}
+			} else {
+				.plotraster(x, index=y, col=rev(terrain.colors(25)), subsample=TRUE, maxdim=500, addbox=TRUE, axes = TRUE, xlab="", ylab="", ...) 
+			}		
+		}
 	}
 )	
 
-setMethod("plot", signature(x='Raster', y='numeric'), 
-	function(x, y=1, ...)  {
-		.plotraster(x, index=y, col=rev(terrain.colors(25)), subsample=TRUE, maxdim=500, addbox=TRUE, axes = TRUE, xlab="", ylab="", ...) 
+
+setMethod("plot", signature(x='RasterLayer', y='missing'), 
+	function(x, ...)  {
+		.plotraster(x, col=rev(terrain.colors(25)), subsample=TRUE, maxdim=500, addbox=TRUE, axes = TRUE, xlab="", ylab="", ...) 
 	}
-)		
+)	
 
 
 setMethod("plot", signature(x='RasterLayer', y='RasterLayer'), 

Modified: pkg/raster/R/raster.R
===================================================================
--- pkg/raster/R/raster.R	2009-04-12 16:03:59 UTC (rev 402)
+++ pkg/raster/R/raster.R	2009-04-13 05:53:17 UTC (rev 403)
@@ -42,14 +42,13 @@
 			x <- asRasterLayer(x, 1) 
 		}
 
-		filename <- trim(filename)
-		if (filename != "" & filename == x at file@name) {
-			stop("it is not allowed to set the filename of the output RasterLayer to that of the input RasterLayer")
-		}
-
 		r <- raster(xmn=xmin(x), xmx=xmax(x), ymn=ymin(x), ymx=ymax(x), nrows=nrow(x), ncols=ncol(x), projs=projection(x))
 		filename(r) <- filename
-	
+
+		if (r at file@name != "" & r at file@name == x at file@name) {
+			stop("it is not allowed to set the filename of the output RasterLayer to that of the input RasterLayer")
+		}
+		
 		if (!is.null(values)) {
 			r <- setValues(r, values)
 		}

Modified: pkg/raster/R/setFilename.R
===================================================================
--- pkg/raster/R/setFilename.R	2009-04-12 16:03:59 UTC (rev 402)
+++ pkg/raster/R/setFilename.R	2009-04-13 05:53:17 UTC (rev 403)
@@ -14,10 +14,11 @@
 
 'filename<-' <- function(x, value) {
 	filename <- trim(value)
-	if (is.na(filename) || is.null(filename)) {
+	if (is.na(filename) | is.null(filename) | !is.character(value)) {
 		filename <- ""
 	}
 	filename <- path.expand(filename)
+# could also throw in normalizePath(utils) 
 	if (class(x)=='RasterStack') {
 		ext(filename) <- ".stk"
 		x at filename <- filename

Modified: pkg/raster/man/plot.Rd
===================================================================
--- pkg/raster/man/plot.Rd	2009-04-12 16:03:59 UTC (rev 402)
+++ pkg/raster/man/plot.Rd	2009-04-13 05:53:17 UTC (rev 403)
@@ -2,8 +2,8 @@
 
 \docType{methods}
 
-\alias{plot,Raster,missing-method}
-\alias{plot,Raster,numeric-method}
+\alias{plot,RasterLayer,missing-method}
+\alias{plot,RasterStack,ANY-method}
 \alias{plot,RasterLayer,RasterLayer-method}
 
 \title{Plot a Raster* object}
@@ -15,13 +15,12 @@
 
 \section{Methods}{
 \describe{
-\bold{x=RasterLayer, y=numeric or missing}
+\bold{x=RasterLayer}
 
-\code{plot(x, y=1, col=rev(terrain.colors(25)), subsample=TRUE, maxdim=500, addbox=TRUE, axes = TRUE, xlab="", ylab="", ...)}
+\code{plot(x, col=rev(terrain.colors(25)), subsample=TRUE, maxdim=500, addbox=TRUE, axes = TRUE, xlab="", ylab="", ...)}
 
 \tabular{rll}{
 \tab \code{x} \tab a RasterLayer object \cr
-\tab \code{y} \tab The index of a raster in a RasterStack  1 <= index <= nlayers(rstack); Ignored for RasterLayer objects \cr
 \tab \code{col}  \tab  A color palette, i.e. a vector of n contiguous colors such as \code{rainbow}, \code{heat.colors}, and \code{topo.colors}, on one or your own making \cr
 \tab \code{subsample}  \tab  Logical. If \code{TRUE}, the image is resampled using maxdim \cr
 \tab \code{maxdim}  \tab  Maximum requested number of pixels in the map display (either vertical or horizontal)  \cr
@@ -33,6 +32,26 @@
 }
 
 
+
+\bold{x=RasterStack, y=numeric or missing}
+
+\code{plot(x, col=rev(terrain.colors(25)), subsample=TRUE, maxdim=500, addbox=TRUE, axes = TRUE, xlab="", ylab="", ...)}
+
+\tabular{rll}{
+\tab \code{x} \tab a RasterLayer object \cr
+\tab \code{y} \tab The index of a RasterLayer in a RasterStack to be plotted. Either a single number between 1 and nlayers(rstack), a vector of numbers, or missing. If y is missing, all RasterLayers in the RasterStack will be plotted.\cr
+\tab \code{col}  \tab  A color palette, i.e. a vector of n contiguous colors such as \code{rainbow}, \code{heat.colors}, and \code{topo.colors}, on one or your own making \cr
+\tab \code{subsample}  \tab  Logical. If \code{TRUE}, the image is resampled using maxdim \cr
+\tab \code{maxdim}  \tab  Maximum requested number of pixels in the map display (either vertical or horizontal)  \cr
+\tab \code{addbox}  \tab  Logical. If \code{TRUE} a box is drawn around the map \cr
+\tab \code{axes}  \tab  see \code{?image} \cr
+\tab \code{xlab}  \tab  see \code{?image} \cr
+\tab \code{ylab}  \tab  see \code{?image} \cr
+\tab \code{...}  \tab  Any argument that can be passed to \code{\link[fields]{image.plot}} and to \code{\link[graphics]{plot}}  \cr
+}
+
+
+
 \bold{x=RasterLayer, y=RasterLayer}
 Produces a scatter plot of the values of x against those of y. 
 \code{plot(x, y, maxdim=10000, cex=0.1, ...) }
@@ -48,13 +67,13 @@
 
 
 \details{
-  If \code{subsample=FALSE}, then \code{maxdim} is ingored. Subsampled maps are made by skipping rows and columns. This is always 
-  done in a regular pattern (e.g. skip every second row). For this reason, the actual number of pixels when \code{subsample = TRUE}
-  is generally not exactely the same as \code{maxdim}. If \code{maxdim} is close to the largest dimension of the raster data matrix 
-  it does not affect it. It needs to be 0.75 times the largest raster dimension to have an effect, in which case the number of pixels
-  will be 0.5 times the largest dimension times the smallest dimension.  
+If \code{subsample=FALSE}, then \code{maxdim} is ingored. Subsampled maps are made by skipping rows and columns. This is always 
+done in a regular pattern (e.g. skip every second row). For this reason, the actual number of pixels when \code{subsample = TRUE}
+is generally not exactely the same as \code{maxdim}. If \code{maxdim} is close to the largest dimension of the raster data matrix 
+it does not affect it. It needs to be 0.75 times the largest raster dimension to have an effect, in which case the number of pixels
+will be 0.5 times the largest dimension times the smallest dimension.  
   
-  Most of the code for this function was taken from image.plot (fields package)
+Most of the code for this function was taken from image.plot (fields package)
 }
 
 



More information about the Raster-commits mailing list