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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jan 13 17:02:37 CET 2009


Author: rhijmans
Date: 2009-01-13 17:02:37 +0100 (Tue, 13 Jan 2009)
New Revision: 134

Added:
   pkg/raster/R/replacement.R
Modified:
   pkg/raster/R/conversion.R
   pkg/raster/R/group.generic.functions.R
   pkg/raster/R/set.R
   pkg/raster/man/classes.Rd
   pkg/raster/man/export.Rd
   pkg/raster/man/properties.Rd
Log:
replacement functions

Modified: pkg/raster/R/conversion.R
===================================================================
--- pkg/raster/R/conversion.R	2009-01-13 12:19:52 UTC (rev 133)
+++ pkg/raster/R/conversion.R	2009-01-13 16:02:37 UTC (rev 134)
@@ -26,6 +26,23 @@
 	setGeneric("asRasterLayer", function(object,index)
 		standardGeneric("asRasterLayer"))
 }	
+setMethod('asRasterLayer', signature(object='missing',index='missing'), 
+	function(object){
+		return(newRaster())
+	}
+)
+setMethod('asRasterLayer', signature(object='character',index='missing'), 
+	function(object){
+		r <- newRaster()
+		if (object == 'runif') {
+			r <- setValues(r, runif(ncells(r)))
+		} else if (object == 'seq') {
+			r <- setValues(r, 1:ncells(r))
+		}
+		return(r)
+	}
+)
+
 setMethod('asRasterLayer', signature(object='Raster',index='missing'), 
 	function(object){
 		return(asRasterLayer(object, 1))

Modified: pkg/raster/R/group.generic.functions.R
===================================================================
--- pkg/raster/R/group.generic.functions.R	2009-01-13 12:19:52 UTC (rev 133)
+++ pkg/raster/R/group.generic.functions.R	2009-01-13 16:02:37 UTC (rev 134)
@@ -26,7 +26,9 @@
 		if (!isTRUE(is.atomic(e2) & length(e2)==1)) {
 			stop('second argument should be a single number')
 		}
-		return(setRaster(e1, values=callGeneric(.getRasterValues(e1), rep(e2, ncells(e1)) ) ) )
+		rs <- setRaster(e1, values=callGeneric(.getRasterValues(e1), rep(e2, ncells(e1)) ) )
+		rs <- setDatatype(rs, datatype='integer', datasize=2)
+		return(rs)
 	}
 )	
 
@@ -35,7 +37,9 @@
 		if (!isTRUE(is.atomic(e2) & length(e2)==1)) {
 			stop('first argument should be a single number')
 		}
-		return(setRaster(e2, values=callGeneric(.getRasterValues(e2), rep(e1, ncells(e2)) ) ) )
+		rs <- setRaster(e2, values=callGeneric(.getRasterValues(e2), rep(e1, ncells(e2)) ) ) 
+		rs <- setDatatype(rs, datatype='integer', datasize=2)
+		return(rs)
 	}
 )	
 
@@ -45,7 +49,9 @@
 		if (!cond) {
 			stop("Cannot compare RasterLayers that have different BasicRaster attributes. See compare()")
 		}	
-		return(setRaster(e1, values=callGeneric(.getRasterValues(e1), .getRasterValues(e2) ) ) )
+		rs <- setRaster(e1, values=callGeneric(.getRasterValues(e1), .getRasterValues(e2) ) ) 
+		rs <- setDatatype(rs, datatype='integer', datasize=2)
+		return(rs)
 	}
 )	
 

Added: pkg/raster/R/replacement.R
===================================================================
--- pkg/raster/R/replacement.R	                        (rev 0)
+++ pkg/raster/R/replacement.R	2009-01-13 16:02:37 UTC (rev 134)
@@ -0,0 +1,51 @@
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date :  June 2008
+# Version 0,8
+# Licence GPL v3
+
+
+'projection<-' <- function(x, value) {
+	return( setProjection(x, value) )
+}
+
+'ncol<-' <- function(x, value) {
+	return( setRowCol(x, ncols=value) )
+}	
+
+'nrow<-' <- function(x, value) {
+	return( setRowCol(x, nrows=value) )
+}	
+
+setReplaceMethod("[", c("RasterLayer", "ANY", "missing", "ANY"), 
+	function(x, i, j, value) {
+# if ...
+		x at data@values[i] <- value
+		return(x)
+	}
+)
+
+setMethod("[", "RasterLayer",
+	function(x,i,j,...,drop=FALSE) {
+# if ...
+		return(values(x)[i])
+	}
+)
+
+
+setMethod("[[", c("RasterLayer", "ANY", "missing"), 
+	function(x, i, j, ...) {
+# if ...
+		return(values(x)[i])
+	}
+)
+ 
+
+ setReplaceMethod("[[", c("RasterLayer", "ANY", "missing", "ANY"), 
+	function(x, i, j, value) {
+# if ...
+		x at data@values[i] <- value
+		return(x)
+	}	
+)
+

Modified: pkg/raster/R/set.R
===================================================================
--- pkg/raster/R/set.R	2009-01-13 12:19:52 UTC (rev 133)
+++ pkg/raster/R/set.R	2009-01-13 16:02:37 UTC (rev 134)
@@ -179,6 +179,13 @@
 		} else {
 			stop("invalid datasize for this datatype") 
 		}
+#	} else if ( datatype == 'logical' ) {
+#		raster at file@datatype <- datatype 
+#		raster at data@min <- round(minValue(raster))
+#		raster at data@max <- round(maxValue(raster))
+#		raster at file@datasize <- as.integer(2)
+#		raster at file@nodatavalue <- -32768
+#		raster at file@datanotation <- "LOGICAL"
 	} else {
 		stop("unknown datatype")
 	} 

Modified: pkg/raster/man/classes.Rd
===================================================================
--- pkg/raster/man/classes.Rd	2009-01-13 12:19:52 UTC (rev 133)
+++ pkg/raster/man/classes.Rd	2009-01-13 16:02:37 UTC (rev 134)
@@ -1,6 +1,7 @@
 \name{RasterLayer-class}
 \docType{class}
 
+
 \alias{BoundingBox-class}
 \alias{BasicRaster-class}
 \alias{Raster-class}
@@ -19,6 +20,9 @@
 \alias{summary,RasterLayer-method}
 \alias{summary,RasterStackBrick-method}
 \alias{[,RasterLayer-method}
+\alias{[<-,RasterLayer,ANY,missing-method}
+\alias{[[,RasterLayer,ANY,missing-method}
+\alias{[[<-,RasterLayer,ANY,missing-method}
 
 \title{Classes for handling raster data }
 \description{ \code{RasterLayer}, \code{RasterStack}, and \code{RasterBrick} (Raster* in short) are all classes for handling spatial raster (grid) data.

Modified: pkg/raster/man/export.Rd
===================================================================
--- pkg/raster/man/export.Rd	2009-01-13 12:19:52 UTC (rev 133)
+++ pkg/raster/man/export.Rd	2009-01-13 16:02:37 UTC (rev 134)
@@ -1,4 +1,6 @@
 \name{Coercion}
+\alias{asRasterLayer,missing,missing-method}
+\alias{asRasterLayer,character,missing-method}
 \alias{asRasterLayer,Raster,missing-method}
 \alias{asRasterLayer,RasterLayer,numeric-method}
 \alias{asRasterLayer,RasterStackBrick,numeric-method}

Modified: pkg/raster/man/properties.Rd
===================================================================
--- pkg/raster/man/properties.Rd	2009-01-13 12:19:52 UTC (rev 133)
+++ pkg/raster/man/properties.Rd	2009-01-13 16:02:37 UTC (rev 134)
@@ -2,6 +2,8 @@
 \alias{filename}
 \alias{ncol}
 \alias{nrow}
+\alias{ncol<-}
+\alias{nrow<-}
 \alias{nrow,BasicRaster-method}
 \alias{ncol,BasicRaster-method}
 \alias{ncells}
@@ -13,6 +15,7 @@
 \alias{ymin}
 \alias{ymax}
 \alias{projection}
+\alias{projection<-}
 \alias{origin}
 \alias{nlayers}
 \alias{layers}



More information about the Raster-commits mailing list