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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 15 10:41:34 CET 2009


Author: rhijmans
Date: 2009-01-15 10:41:33 +0100 (Thu, 15 Jan 2009)
New Revision: 138

Modified:
   pkg/raster/R/replacement.R
   pkg/raster/R/set.R
   pkg/raster/man/classes.Rd
Log:


Modified: pkg/raster/R/replacement.R
===================================================================
--- pkg/raster/R/replacement.R	2009-01-15 06:23:11 UTC (rev 137)
+++ pkg/raster/R/replacement.R	2009-01-15 09:41:33 UTC (rev 138)
@@ -17,10 +17,43 @@
 	return( setRowCol(x, nrows=value) )
 }	
 
-setReplaceMethod("[", c("RasterLayer", "ANY", "missing", "ANY"), 
+
+setMethod("[", "RasterLayer",
+	function(x,i,j,...,drop=FALSE) {
+		if  (!missing(j)) {	stop("incorrect number of dimensions") }
+		if (dataContent(x) == 'nodata') {
+			if (ncells(x) < 1000000) {
+				if (dataSource(x) == 'disk') {
+					x <- readAll(x)
+				} else {
+					stop('no data associated with this RasterLayer object')
+				}
+			} else {
+				stop('Large raster, no data in memory, use readAll() first')
+			}	
+		}
+		return(values(x)[i]) 
+	}
+)
+
+
+setReplaceMethod("[", "RasterLayer",  
 	function(x, i, j, value) {
-# if ...
+		if  (!missing(j)) {	stop("incorrect number of dimensions") }
+		if (dataContent(x) == 'nodata') {
+			if (ncells(x) < 1000000) {
+				if (dataSource(x) == 'disk') {
+					x <- readAll(x)
+				} else {
+					stop('no data associated with this RasterLayer object')
+				}
+			} else {
+				stop('Large raster, no data in memory, use readAll() first')
+			}	
+		}
 		x at data@values[i] <- value
+		x <- setFilename(x, "")
+		x at data@source <- 'ram'
 		return(x)
 	}
 )
@@ -38,18 +71,6 @@
 )
 
 
-setMethod("[", "RasterLayer",
-	function(x,i,j,layer,...,drop=FALSE) {
-		if  (!missing(layer)) {	stop("incorrect number of dimensions") }
-		if  (missing(j)) {	return(values(x)[i]) 
-		} else {
-			v <- valuesRow(x,j)
-			return(v[i])
-		}
-	}
-)
-
-
 setMethod("[[", c("RasterLayer", "ANY", "missing"), 
 	function(x, i, j, ...) {
 		return(values(x)[i])

Modified: pkg/raster/R/set.R
===================================================================
--- pkg/raster/R/set.R	2009-01-15 06:23:11 UTC (rev 137)
+++ pkg/raster/R/set.R	2009-01-15 09:41:33 UTC (rev 138)
@@ -27,12 +27,9 @@
 		stop("it is not allowed to set the filename of the output RasterLayer to that of the input RasterLayer")
 	}
 
-	raster <- clearValues(object)
-	raster at data@min <- NA
-	raster at data@max <- NA
-
+	raster <- newRaster(xmn = xmin(object), xmx = xmax(object), ymn = ymin(object), ymx = ymax(object), nrows=nrow(object), ncols=ncol(object), projstring=projection(object))
 	raster <- setFilename(raster, filename)
-	raster <- setDatatype(raster, 'numeric')
+	
 	if ( length(values) != 1 | ( length(values) == 1 & ncells(raster) == 1) ) {
 		raster <- setValues(raster, values)
 	}

Modified: pkg/raster/man/classes.Rd
===================================================================
--- pkg/raster/man/classes.Rd	2009-01-15 06:23:11 UTC (rev 137)
+++ pkg/raster/man/classes.Rd	2009-01-15 09:41:33 UTC (rev 138)
@@ -20,8 +20,8 @@
 \alias{summary,RasterLayer-method}
 \alias{summary,RasterStackBrick-method}
 \alias{[,RasterLayer-method}
+\alias{[<-,RasterLayer-method}
 \alias{[,RasterStack-method}
-\alias{[<-,RasterLayer,ANY,missing-method}
 \alias{[[,RasterLayer,ANY,missing-method}
 \alias{[[<-,RasterLayer,ANY,missing-method}
 



More information about the Raster-commits mailing list