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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 15 16:37:09 CET 2009


Author: rhijmans
Date: 2009-01-15 16:37:09 +0100 (Thu, 15 Jan 2009)
New Revision: 139

Modified:
   pkg/raster/DESCRIPTION
   pkg/raster/NAMESPACE
   pkg/raster/R/Merge.R
   pkg/raster/R/Overlay.R
   pkg/raster/R/adjacency.R
   pkg/raster/R/aggregate.R
   pkg/raster/R/conversion.R
   pkg/raster/R/disaggregate.R
   pkg/raster/R/expand.R
   pkg/raster/R/export.R
   pkg/raster/R/get.R
   pkg/raster/R/group.generic.functions.R
   pkg/raster/R/init.R
   pkg/raster/R/plot.R
   pkg/raster/R/properties.R
   pkg/raster/R/raster.write.R
   pkg/raster/R/read.raster.R
   pkg/raster/R/replacement.R
   pkg/raster/R/set.R
   pkg/raster/R/set.values.R
   pkg/raster/R/show.R
   pkg/raster/R/standard.generic.functions.R
   pkg/raster/R/values.R
   pkg/raster/man/Arith-methods.Rd
   pkg/raster/man/classes.Rd
   pkg/raster/man/get.Rd
   pkg/raster/man/map.Rd
   pkg/raster/man/overlay.Rd
   pkg/raster/man/properties.Rd
Log:


Modified: pkg/raster/DESCRIPTION
===================================================================
--- pkg/raster/DESCRIPTION	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/DESCRIPTION	2009-01-15 15:37:09 UTC (rev 139)
@@ -2,7 +2,7 @@
 Type: Package
 Title: Raster data handling for geographic data analysis and modeling
 Version: 0.8.5
-Date: 14-Jan-2009
+Date: 15-Jan-2009
 Depends: methods, sp, rgdal (>= 0.5-33), R (>= 2.8.0)
 Author: Robert J. Hijmans & Jacob van Etten
 Maintainer: Robert J. Hijmans <r.hijmans at gmail.com> 

Modified: pkg/raster/NAMESPACE
===================================================================
--- pkg/raster/NAMESPACE	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/NAMESPACE	2009-01-15 15:37:09 UTC (rev 139)
@@ -1,6 +1,6 @@
 importFrom("methods", Arith, Compare, Logic, Math)
 importFrom("graphics", hist, plot)
-importFrom("sp", Spatial, SpatialPixels, SpatialPixelsDataFrame, SpatialGrid, SpatialGridDataFrame)
+importFrom("sp", Spatial, SpatialPixels, SpatialPixelsDataFrame, SpatialGrid, SpatialGridDataFrame, overlay)
 exportClasses(BoundingBox, BasicRaster, Raster, RasterLayer, RasterBrick, RasterStack)
 exportMethods(show, summary, plot, hist, ncol, nrow, dim)
 exportPattern("^[^\\.]")
\ No newline at end of file

Modified: pkg/raster/R/Merge.R
===================================================================
--- pkg/raster/R/Merge.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/Merge.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -50,7 +50,7 @@
 	rowcol <- matrix(0, ncol=3, nrow=length(rasters))
 	for (i in 1:length(rasters)) {
 		xy1 <- xyFromCell(rasters[[i]], 1) # first row/col on old raster[[i]]
-		xy2 <- xyFromCell(rasters[[i]], ncells(rasters[[i]]) ) #last row/col on old raster[[i]]
+		xy2 <- xyFromCell(rasters[[i]], ncell(rasters[[i]]) ) #last row/col on old raster[[i]]
 		rowcol[i,1] <- rowFromY(outraster, xy1[2]) #start row on new raster
 		rowcol[i,2] <- rowFromY(outraster, xy2[2]) #end row
 		rowcol[i,3] <- colFromX(outraster, xy1[1]) #start col

Modified: pkg/raster/R/Overlay.R
===================================================================
--- pkg/raster/R/Overlay.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/Overlay.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -5,7 +5,15 @@
 # Licence GPL v3
 
 
-Overlay <- function(raster1, raster2, fun=function(x,y){return(x+y)}, filename="", overwrite=FALSE) {
+
+setMethod('overlay', signature(x='RasterLayer', y='RasterLayer'), 
+	function(x, y, fun=function(x,y){return(x+y)}, filename="", overwrite=FALSE, ...){ 
+		return(.Overlay(x, y, fun, filename, overwrite) )
+	}
+)
+
+
+.Overlay <- function(raster1, raster2, fun=function(x,y){return(x+y)}, filename="", overwrite=FALSE) {
 	if (class(raster1) != 'RasterLayer' | class(raster2) != 'RasterLayer') {
 		stop('first two arguments should be objects of class "RasterLayer"')
 	}

Modified: pkg/raster/R/adjacency.R
===================================================================
--- pkg/raster/R/adjacency.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/adjacency.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -13,8 +13,8 @@
 
 #Costumized (internal) functions can be created for each number of directions and for upper, middle and lower rows to optimize the code for row-level processing. 32 directions can be created if higher precision is needed.
 #adjraster <- function(raster, directions, outerMeridianConnect) {
-#	adjacency(raster, !is.na(cbind(1:ncells(raster),values(raster)))[,1], 1:ncells(raster), directions, outerMeridianConnect)
-#	v <- vector(length=ncells(raster))
+#	adjacency(raster, !is.na(cbind(1:ncell(raster),values(raster)))[,1], 1:ncell(raster), directions, outerMeridianConnect)
+#	v <- vector(length=ncell(raster))
 #	v[adj[,2]] <- 2
 #	v[adj[,1]] <- 1
 #	rs <- setValues(rs, v)
@@ -24,7 +24,7 @@
 adjacency <- function(raster, fromCells, toCells, directions, outerMeridianConnect)
 {
 	nCols <- ncol(raster)
-	nCells <- ncells(raster)
+	nCells <- ncell(raster)
 	
 	left <- seq(nCols+1,(nCells-2*nCols+1),by=nCols) 
 	right <- seq(2*nCols,nCells-nCols,by=nCols)
@@ -244,7 +244,7 @@
 adjBishop <- function(raster, fromCells, toCells, outerMeridianConnect)
 {
 	nCols <- ncol(raster)
-	nCells <- ncells(raster)
+	nCells <- ncell(raster)
 	
 	left <- seq(nCols+1,(nCells-2*nCols+1),by=nCols) 
 	right <- seq(2*nCols,nCells-nCols,by=nCols)

Modified: pkg/raster/R/aggregate.R
===================================================================
--- pkg/raster/R/aggregate.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/aggregate.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -42,8 +42,8 @@
 	
 	if (dataContent(raster) == 'all') {	
 		cols <- rep(rep(1:csteps, each=xfact)[1:ncol(raster)], times=nrow(raster))
-		rows <- rep(1:rsteps, each=ncol(raster) * yfact)[1:ncells(raster)]
-		cells <- cellFromRowcol(raster, rows, cols)
+		rows <- rep(1:rsteps, each=ncol(raster) * yfact)[1:ncell(raster)]
+		cells <- cellFromRowCol(raster, rows, cols)
 		
 		if (rm.NA) { outraster <- setValues(outraster, as.vector(tapply(values(raster), cells, function(x){fun(na.omit(x))}))) 
 		} else {outraster <- setValues(outraster, as.vector(tapply(values(raster), cells, fun))) }
@@ -68,7 +68,7 @@
 				theserows <- startrow * rows
 			}	
 			raster <- readRows(raster, startrow = startrow, nrows = nrows)
-			cells <- cellFromRowcol(raster, theserows, cols)
+			cells <- cellFromRowCol(raster, theserows, cols)
 			
 			if (rm.NA) { vals <- tapply(values(raster), cells, function(x){fun(na.omit(x))} ) 
 			} else { vals <- tapply(values(raster), cells, fun) }

Modified: pkg/raster/R/conversion.R
===================================================================
--- pkg/raster/R/conversion.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/conversion.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -35,9 +35,9 @@
 	function(object){
 		r <- newRaster()
 		if (object == 'runif') {
-			r <- setValues(r, runif(ncells(r)))
+			r <- setValues(r, runif(ncell(r)))
 		} else if (object == 'seq') {
-			r <- setValues(r, 1:ncells(r))
+			r <- setValues(r, 1:ncell(r))
 		}
 		return(r)
 	}

Modified: pkg/raster/R/disaggregate.R
===================================================================
--- pkg/raster/R/disaggregate.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/disaggregate.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -27,7 +27,7 @@
 		
 		cols <- rep(rep(1:ncol(raster), each=xfact), times=nrow(raster)*yfact)
 		rows <- rep(1:nrow(raster), each=ncol(raster)*xfact*yfact)
-		cells <- cellFromRowcol(raster, rows, cols)
+		cells <- cellFromRowCol(raster, rows, cols)
 		outraster <- setValues(outraster, values(raster)[cells])
 		if (filename(outraster) != "") {writeRaster(outraster, overwrite=overwrite)}
 		

Modified: pkg/raster/R/expand.R
===================================================================
--- pkg/raster/R/expand.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/expand.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -31,7 +31,7 @@
 	
 	if (dataContent(raster) == 'all')  {
 
-		d <- vector(length=ncells(outraster))
+		d <- vector(length=ncell(outraster))
 		d[] <- NA
 		for (r in 1:nrow(raster)) {
 			vals <- valuesRow(raster, r) 

Modified: pkg/raster/R/export.R
===================================================================
--- pkg/raster/R/export.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/export.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -100,8 +100,8 @@
 		cat("NODATA_value", .nodatavalue(raster), "\n", file = thefile)
 		close(thefile) #close connection
 		
-    } else if ( dataIndices(raster)[2] > ncells(raster)) {
-		stop(paste('writing beyond end of file. last cell:', dataIndices(raster)[2], '>', ncells(raster)))
+    } else if ( dataIndices(raster)[2] > ncell(raster)) {
+		stop(paste('writing beyond end of file. last cell:', dataIndices(raster)[2], '>', ncell(raster)))
 	}
 
 	
@@ -116,7 +116,7 @@
 							sep = " ", eol = "\n", dec = ".", row.names = FALSE, col.names = FALSE)
     }
 	
-	if ( dataIndices(raster)[2] == ncells(raster)) {
+	if ( dataIndices(raster)[2] == ncell(raster)) {
 		return(rasterFromFile(filename))
 	} else {
 		return("writing in progress")

Modified: pkg/raster/R/get.R
===================================================================
--- pkg/raster/R/get.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/get.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -33,7 +33,7 @@
 rowFromCell <- function(object, cell) {
 	if (.isSPgrid(object)) { object <- asRasterLayer(object, FALSE) }
 	cell <- as.integer(round(cell))
-	cell[cell < 1 | cell > ncells(object)] <- NA
+	cell[cell < 1 | cell > ncell(object)] <- NA
 	rownr <- as.integer(trunc((cell-1)/ncol(object)) + 1)
     return(rownr)
 }
@@ -42,7 +42,7 @@
 colFromCell <- function(object, cell) {
 	if (.isSPgrid(object)) { object <- asRasterLayer(object, FALSE) }
 	cell <- as.integer(round(cell))
-	cell[cell < 1 | cell > ncells(object)] <- NA	
+	cell[cell < 1 | cell > ncell(object)] <- NA	
 	rownr <- as.integer(trunc((cell-1)/ncol(object)) + 1)
 	colnr <- as.integer(cell - ((rownr-1) * ncol(object)))
     return(colnr)
@@ -75,7 +75,7 @@
 }
 
 
-cellFromRowcol <- function(object, rownr, colnr) {
+cellFromRowCol <- function(object, rownr, colnr) {
 	if (.isSPgrid(object)) { object <- asRasterLayer(object, FALSE) }
 	rownr <- round(rownr)
 	colnr <- round(colnr)
@@ -143,7 +143,7 @@
 	if (.isSPgrid(object)) { object <- asRasterLayer(object, FALSE) }
 	cell <- round(cell)
 	validcell <- vector(length=length(cell))
-	validcell[cell > 0 & cell <= ncells(object)] <- TRUE
+	validcell[cell > 0 & cell <= ncell(object)] <- TRUE
 	return(validcell)
 }
 

Modified: pkg/raster/R/group.generic.functions.R
===================================================================
--- pkg/raster/R/group.generic.functions.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/group.generic.functions.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -26,7 +26,7 @@
 		if (!isTRUE(is.atomic(e2) & length(e2)==1)) {
 			stop('second argument should be a single number')
 		}
-		rs <- setRaster(e1, values=callGeneric(.getRasterValues(e1), rep(e2, ncells(e1)) ) )
+		rs <- setRaster(e1, values=callGeneric(.getRasterValues(e1), rep(e2, ncell(e1)) ) )
 		rs <- setDatatype(rs, datatype='integer', datasize=2)
 		return(rs)
 	}
@@ -37,7 +37,7 @@
 		if (!isTRUE(is.atomic(e2) & length(e2)==1)) {
 			stop('first argument should be a single number')
 		}
-		rs <- setRaster(e2, values=callGeneric(.getRasterValues(e2), rep(e1, ncells(e2)) ) ) 
+		rs <- setRaster(e2, values=callGeneric(.getRasterValues(e2), rep(e1, ncell(e2)) ) ) 
 		rs <- setDatatype(rs, datatype='integer', datasize=2)
 		return(rs)
 	}
@@ -82,8 +82,8 @@
 	if ( (class(y) == 'RasterLayer' | class(y) == 'RasterStack' | class(y) == 'RasterBrick') & compare(c(x, y)) ) {			
 		return(.getRasterValues(y))
 	} else if (is.atomic(y)) {
-		return(rep(y, ncells(x)))
-	} else if (length(y)==ncells(x)) {
+		return(rep(y, ncell(x)))
+	} else if (length(y)==ncell(x)) {
 		return(y)
 	} else {
 		stop(paste("I do not understand argument",i + 1)) 

Modified: pkg/raster/R/init.R
===================================================================
--- pkg/raster/R/init.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/init.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -11,7 +11,7 @@
 	if (ForceIntOutput) {setDatatype(outraster, 'integer') }
 
 	if ( dataContent(raster) == 'all' | dataSource(raster) == 'ram' ) {
-		n <- ncells(raster)
+		n <- ncell(raster)
 		outraster <- setValues(outraster, fun(n)) 
 		if (filename != "") {	
 			outraster <- writeRaster(outraster, overwrite=overwrite) 

Modified: pkg/raster/R/plot.R
===================================================================
--- pkg/raster/R/plot.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/plot.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -21,7 +21,7 @@
 setMethod("plot", signature(x='RasterLayer', y='RasterLayer'), 
 	function(x, y, maxdim=1000, cex=0.1, ...)  {
 		comp <- compare(c(x, y), bb=TRUE, rowcol=TRUE, prj=FALSE, tolerance=0.0001, stopiffalse=TRUE) 
-		nc <- ncells(x)
+		nc <- ncell(x)
 		x <- readSkip(x, maxdim=maxdim)
 		y <- readSkip(y, maxdim=maxdim)
 		if (length(x) < nc) {
@@ -39,11 +39,11 @@
 		# TO DO: make a function that does this by block and combines  all data into a single histogram
 
 				x <- asRasterLayer(x, layer)
-				if (ncells(x) <= maxsamp) {
+				if (ncell(x) <= maxsamp) {
 					values <- na.omit(values(readAll(x)))
 				} else {
 					values <- readRandom(x, maxsamp)
-					msg <- paste(round(100 * maxsamp / ncells(x)), "% of the raster cells were used", sep="")
+					msg <- paste(round(100 * maxsamp / ncell(x)), "% of the raster cells were used", sep="")
 					if (maxsamp > length(values)) {
 						msg <- paste(msg, " (of which ", 100 - round(100 * length(values) / maxsamp ), "% were NA)", sep="")
 					}

Modified: pkg/raster/R/properties.R
===================================================================
--- pkg/raster/R/properties.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/properties.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -38,9 +38,15 @@
 }
 
 ncells <- function(object) {
+	warning("'ncells' is obsolete. Use 'ncell' instead")
 	return(return( as.numeric(nrow(object)) * ncol(object )))
 }
 
+ncell <- function(object) {
+	return(return( as.numeric(nrow(object)) * ncol(object )))
+}
+
+
 xmin <- function(object) {
 	object <- getBbox(object)
 	return(as.numeric(object at xmin))

Modified: pkg/raster/R/raster.write.R
===================================================================
--- pkg/raster/R/raster.write.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/raster.write.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -116,7 +116,7 @@
 #	raster at data@values[is.na(raster at data@values)] <-  raster at file@nodatavalue
 	writeBin(as.vector(raster at data@values), raster at filecon, size = raster at file@datasize)
 	
-	if (dataIndices(raster)[2] == ncells(raster)) {
+	if (dataIndices(raster)[2] == ncell(raster)) {
 	# LAST  ROW
 		.writeRasterHdr(raster) 
 		close(raster at filecon)
@@ -125,8 +125,8 @@
 		raster at data@content <- 'nodata'
 		raster at data@values <- vector(length=0)
 	}		
-	if (dataIndices(raster)[2] > ncells(raster)) {
-		stop(paste('writing beyond end of file. last cell:', dataIndices(raster)[2], '>', ncells(raster)))
+	if (dataIndices(raster)[2] > ncell(raster)) {
+		stop(paste('writing beyond end of file. last cell:', dataIndices(raster)[2], '>', ncell(raster)))
 	}
 	return(raster)	
 }

Modified: pkg/raster/R/read.raster.R
===================================================================
--- pkg/raster/R/read.raster.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/read.raster.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -32,8 +32,8 @@
 			blockdata <- c(blockdata, values(raster))
 		}	
 	}	
-	startcell <- cellFromRowcol(raster, startrow, startcol)
-	endcell <- cellFromRowcol(raster, endrow, (startcol+ncolumns-1))
+	startcell <- cellFromRowCol(raster, startrow, startcol)
+	endcell <- cellFromRowCol(raster, endrow, (startcol+ncolumns-1))
 	raster <- setValuesBlock(raster, blockdata, startcell, endcell)
 	return(raster)
 }
@@ -69,7 +69,7 @@
 			seek(con, ((rownr-1) * ncol(raster) + (startcol-1)) * raster at file@datasize)
 			result <- readBin(con, what=dtype, n = ncolumns, size = raster at file@datasize, endian = raster at file@byteorder) }	
 		else {	
-			result <- readBin(con, what=dtype, n = ncells(raster), size = raster at file@datasize, endian = raster at file@byteorder) 
+			result <- readBin(con, what=dtype, n = ncell(raster), size = raster at file@datasize, endian = raster at file@byteorder) 
 		}
 		close(con)
 		result[is.nan(result)] <- NA
@@ -95,14 +95,14 @@
 	} 
 	raster at data@values <- as.vector(result)
 	if (rownr < 0) {
-		raster at data@indices <- c(1, ncells(raster))
+		raster at data@indices <- c(1, ncell(raster))
 		raster at data@content <- "all"
 		raster <- setMinMax(raster)
 	} else if (startcol==1 & ncolumns==(ncol(raster)-startcol+1)) {
-		raster at data@indices <- c(cellFromRowcol(raster, rownr, startcol), cellFromRowcol(raster, rownr, endcol))
+		raster at data@indices <- c(cellFromRowCol(raster, rownr, startcol), cellFromRowCol(raster, rownr, endcol))
 		raster at data@content <- "row"
 	} else {
-		raster at data@indices <- c(cellFromRowcol(raster, rownr, startcol), cellFromRowcol(raster, rownr, endcol))
+		raster at data@indices <- c(cellFromRowCol(raster, rownr, startcol), cellFromRowCol(raster, rownr, endcol))
 		raster at data@content <- "block"
 	}	
 	
@@ -123,9 +123,9 @@
 		}
 	} else {
 		if (dataSource(raster) == 'disk') {
-			if (ncells(raster) <= n) {
+			if (ncell(raster) <= n) {
 				raster <- readAll(raster)
-				values <- cbind(1:ncells(raster), values(raster))
+				values <- cbind(1:ncell(raster), values(raster))
 				if (na.rm) { values <- na.omit(values) }
 			} else {	
 				if (na.rm) {
@@ -133,7 +133,7 @@
 				} else {
 					N <- 2 * n 
 				}	
-				cells <- unique(as.integer(round(runif(N) * ncells(raster) + 0.5)))
+				cells <- unique(as.integer(round(runif(N) * ncell(raster) + 0.5)))
 				cells <- cells[cells > 0]
 				values <- cellValues(raster, cells)
 				if (na.rm) {
@@ -222,7 +222,7 @@
 #read data on the raster for cell numbers
 .rasterReadCells <- function(raster, cells) {
 	uniquecells <- na.omit(unique(cells[order(cells)]))
-	uniquecells <- uniquecells[(uniquecells > 0) & (uniquecells <= ncells(raster))]
+	uniquecells <- uniquecells[(uniquecells > 0) & (uniquecells <= ncell(raster))]
 	res <- cbind(cells, NA)
 	if (length(uniquecells) > 0) {
 		if (dataContent(raster) == 'all') {
@@ -234,10 +234,9 @@
 				vals <- .readCellsRaster(raster, uniquecells)
 			}	
 		} else { 
-			vals <- vector(length=length(uniquecells))
-			vals[] <- NA
+			vals <- cbind(uniquecells, NA)
 		}	
-		if (length(vals) == 1) {
+		if (length(vals) == 2) {
 			res[res[,1]==vals[1],2] <- vals[2] 
 		} else {
 			for (i in 1:length(vals[,1])) {

Modified: pkg/raster/R/replacement.R
===================================================================
--- pkg/raster/R/replacement.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/replacement.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -18,21 +18,25 @@
 }	
 
 
+.getColValues <- function(r, colnr) {
+	firstcol <- 1:nrow(r) * ncol(r) - ncol(r) 
+	cells <- colnr + firstcol 
+	return(values(r)[cells])
+}
+
 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')
-				}
+		if (!missing(j)) { stop("incorrect number of dimensions") }
+# consider row, sparse....		
+		if (dataContent(x) != 'all') {
+			if (dataSource(x) != 'disk') {
+				stop('no data associated with this RasterLayer object')
 			} else {
-				stop('Large raster, no data in memory, use readAll() first')
+				return(cellValues(x, i))
 			}	
-		}
-		return(values(x)[i]) 
+		} else {
+			return(values(x)[i]) 
+		}	
 	}
 )
 
@@ -40,8 +44,9 @@
 setReplaceMethod("[", "RasterLayer",  
 	function(x, i, j, value) {
 		if  (!missing(j)) {	stop("incorrect number of dimensions") }
-		if (dataContent(x) == 'nodata') {
-			if (ncells(x) < 1000000) {
+# what about data rows ?		
+		if (dataContent(x) != 'nodata') {
+			if (ncell(x) < 1000000) {
 				if (dataSource(x) == 'disk') {
 					x <- readAll(x)
 				} else {
@@ -52,37 +57,38 @@
 			}	
 		}
 		x at data@values[i] <- value
+		x at data@source <- 'ram'
 		x <- setFilename(x, "")
-		x at data@source <- 'ram'
 		return(x)
 	}
 )
 
 
-setMethod("[", "RasterStack",
-	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","ANY"),
+# i = row
+# j = col
+	function(x,i,j,...,drop=FALSE) {
+		if (dataContent(x) == 'nodata') {
+			if (ncell(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( matrix(values(x), nrow(x), ncol(x), byrow=T)[i,j] )
+	
+#		if (missing(i)) { rows <- 1:nrow(x) } else { rows <- i }
+#		if (missing(j)) { cols <- 1:ncol(x) } else { cols <- j }
+		# ugly R code
+#		cells <- cellFromRowcol(rep(rows[1], length(cols)), cols)
+#		for (a in 2:rows) { cells <- c(cells, cells + (a - 1) * ncol(x)) }
+#		vals <- values(x)[cells]
+#		return( matrix(vals, length(rows), lenght(cols), byrow=T) )
 	}
 )
 
 
-setMethod("[[", c("RasterLayer", "ANY", "missing"), 
-	function(x, i, j, ...) {
-		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-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/set.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -30,7 +30,7 @@
 	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)
 	
-	if ( length(values) != 1 | ( length(values) == 1 & ncells(raster) == 1) ) {
+	if ( length(values) != 1 | ( length(values) == 1 & ncell(raster) == 1) ) {
 		raster <- setValues(raster, values)
 	}
 	return(raster)

Modified: pkg/raster/R/set.values.R
===================================================================
--- pkg/raster/R/set.values.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/set.values.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -16,14 +16,14 @@
 	if (length(values) == 0) {	stop('length(values==0). If this is intended then use clearValues(raster)') }
 	if (!(is.numeric(values) | is.integer(values) | is.logical(values))) {stop('data must be values')}
 	rownr <- round(rownr)
-	if (length(values) == ncells(raster)) { 
+	if (length(values) == ncell(raster)) { 
 		if (rownr > 0) {
 			stop("if setting all values, rownr must be < 1")
 		}
 		raster at data@values <- values
 		raster at data@content <- 'all'
 		raster at data@source <- 'ram'
-		raster at data@indices <- c(1, ncells(raster))
+		raster at data@indices <- c(1, ncell(raster))
 		raster <- setMinMax(raster)
 		return(raster)	
 	} else if (length(values) == ncol(raster)) {
@@ -32,12 +32,12 @@
 		}
 		raster at data@values <- values
 		raster at data@content <- 'row' 
-		firstcell <- cellFromRowcol(raster, rownr=rownr, colnr=1)
-		lastcell <- cellFromRowcol(raster, rownr=rownr, colnr=ncol(raster))
+		firstcell <- cellFromRowCol(raster, rownr=rownr, colnr=1)
+		lastcell <- cellFromRowCol(raster, rownr=rownr, colnr=ncol(raster))
 		raster at data@indices <- c(firstcell, lastcell)
 		return(raster)
 	} else {
-		stop("length(values) is not equal to ncells(raster) or ncol(raster)") 
+		stop("length(values) is not equal to ncell(raster) or ncol(raster)") 
 	}
 }	
 	
@@ -60,7 +60,7 @@
 	if ( dataContent(raster) == 'sparse') {return(raster)
 	} else {
 		if ( dataContent(raster) == 'all') {
-			vals <- seq(1:ncells(raster))
+			vals <- seq(1:ncell(raster))
 			vals <- cbind(vals, values(raster))
 			vals <- as.vector(na.omit(vals))
 			raster <- setValuesSparse(raster, sparsevalues=vals[,2], cellnumbers=vals[,1])

Modified: pkg/raster/R/show.R
===================================================================
--- pkg/raster/R/show.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/show.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -22,7 +22,7 @@
 		cat('class       :' , class(object), '\n')
 		cat('nrow        :' , nrow(object), '\n')
 		cat('ncol        :' , ncol(object), '\n')
-		cat('ncells      :' , ncells(object), '\n')
+		cat('ncells      :' , ncell(object), '\n')
 		cat('projection  :' , projection(object, TRUE), '\n')
 		cat('xmin        :' , xmin(object), '\n')
 		cat('xmax        :' , xmax(object), '\n')
@@ -42,7 +42,7 @@
 		}	
 		cat('nrow        :' , nrow(object), '\n')
 		cat('ncol        :' , ncol(object), '\n')
-		cat('ncells      :' , ncells(object), '\n')
+		cat('ncells      :' , ncell(object), '\n')
 		cat('data type   :' , object at file@datanotation, '\n')
 		cat('data content:' ,  dataContent(object), '\n')
 		if (object at data@haveminmax) {
@@ -71,7 +71,7 @@
 		cat ('nlayers   :' , nlayers(object), '\n')
 		cat ('nrow      :' , nrow(object), '\n')
 		cat ('ncol      :' , ncol(object), '\n')
-		cat ('ncells    :' , ncells(object), '\n')
+		cat ('ncells    :' , ncell(object), '\n')
 		cat ('projection:' , projection(object, TRUE), '\n')
 		cat ('xmin      :' , xmin(object), '\n')
 		cat ('xmax      :' , xmax(object), '\n')
@@ -91,7 +91,7 @@
 		cat ('nlayers   :' , nlayers(object), '\n')
 		cat ('nrow      :' , nrow(object), '\n')
 		cat ('ncol      :' , ncol(object), '\n')
-		cat ('ncells    :' , ncells(object), '\n')
+		cat ('ncells    :' , ncell(object), '\n')
 		cat ('projection:' , projection(object, TRUE), '\n')
 		cat ('xmin      :' , xmin(object), '\n')
 		cat ('xmax      :' , xmax(object), '\n')

Modified: pkg/raster/R/standard.generic.functions.R
===================================================================
--- pkg/raster/R/standard.generic.functions.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/standard.generic.functions.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -35,7 +35,7 @@
 
 setMethod('summary', signature(object='RasterLayer'), 
 	function(object, ...) {
-		cat ("Cells: " , ncells(object), '\n')
+		cat ("Cells: " , ncell(object), '\n')
 		if ( dataContent(object) == "all") {
 			cat("NAs  : ", sum(is.na(values(object))), "\n")
 			summary(values(object))

Modified: pkg/raster/R/values.R
===================================================================
--- pkg/raster/R/values.R	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/R/values.R	2009-01-15 15:37:09 UTC (rev 139)
@@ -17,7 +17,7 @@
 	if (dataContent(raster) == 'sparse') {return (.valuesRow.sparse(raster, rownr)) 
 	} else if (dataContent(raster) != 'all') {stop('cannot do. Need all data')
 	} else {
-		startcell <- cellFromRowcol(raster, rownr, 1)
+		startcell <- cellFromRowCol(raster, rownr, 1)
 		endcell <- startcell+ncol(raster)-1
 		return(values(raster)[startcell:endcell])
 	}	
@@ -26,7 +26,7 @@
 
 .valuesRow.sparse <- function(raster, rownr, explode=TRUE) {
 	if (dataContent(raster) != 'sparse') {stop('cannot do. Need sparse')}
-	startcell <- cellFromRowcol(raster, rownr, 1)
+	startcell <- cellFromRowCol(raster, rownr, 1)
 	endcell <- startcell+ncol(raster)-1
 	d <- cbind(dataIndices(raster), values(raster))
 	d <- d[d[,1] >= startcell & d[,1] <= endcell, ] 

Modified: pkg/raster/man/Arith-methods.Rd
===================================================================
--- pkg/raster/man/Arith-methods.Rd	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/man/Arith-methods.Rd	2009-01-15 15:37:09 UTC (rev 139)
@@ -9,7 +9,7 @@
   Standard arithmic functions for computations with RasterLayer objects and numeric values
 }
 \section{Note}{
- The RasterLayer objects must have either all data in memory or on disk. If the data do not fit into memory you should use the Overlay() function instead.
+ The RasterLayer objects must have either all data in memory or on disk. If the data do not fit into memory you should use the overlay() function instead.
 }
 \author{Robert J. Hijmans \email{r.hijmans at gmail.com}}
 

Modified: pkg/raster/man/classes.Rd
===================================================================
--- pkg/raster/man/classes.Rd	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/man/classes.Rd	2009-01-15 15:37:09 UTC (rev 139)
@@ -22,7 +22,7 @@
 \alias{[,RasterLayer-method}
 \alias{[<-,RasterLayer-method}
 \alias{[,RasterStack-method}
-\alias{[[,RasterLayer,ANY,missing-method}
+\alias{[[,RasterLayer,ANY,ANY-method}
 \alias{[[<-,RasterLayer,ANY,missing-method}
 
 \title{Classes for handling raster data }

Modified: pkg/raster/man/get.Rd
===================================================================
--- pkg/raster/man/get.Rd	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/man/get.Rd	2009-01-15 15:37:09 UTC (rev 139)
@@ -1,7 +1,7 @@
 \name{get}
 \alias{colFromCell}
 \alias{rowFromCell}
-\alias{cellFromRowcol}
+\alias{cellFromRowCol}
 \alias{colFromX}
 \alias{rowFromY}
 \alias{cellFromXY}
@@ -23,7 +23,7 @@
 \usage{
 colFromCell(object, cell)
 rowFromCell(object, cell)
-cellFromRowcol(object, rownr, colnr)
+cellFromRowCol(object, rownr, colnr)
 colFromX(object, x)
 rowFromY(object, y)
 cellFromXY(object, xy)

Modified: pkg/raster/man/map.Rd
===================================================================
--- pkg/raster/man/map.Rd	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/man/map.Rd	2009-01-15 15:37:09 UTC (rev 139)
@@ -5,6 +5,7 @@
 \alias{plot,RasterLayer,RasterLayer-method}
 \alias{plot,RasterStack,numeric-method}
 \alias{plot,RasterStack,missing-method}
+\alias{click}
 
 \title{ Map a raster layer }
 \description{
@@ -12,6 +13,7 @@
 }
 \usage{
 map(object, index=1, col=rev(terrain.colors(25)), subsample=TRUE, maxdim=500, addbox=TRUE, axes = TRUE, xlab="", ylab="", ...)
+click(object, n=1, xy=FALSE, type = "n", ...)
 }
 
 \arguments{
@@ -24,7 +26,11 @@
   \item{axes}{see "?image"}
   \item{xlab}{see "?image"}
   \item{ylab}{see "?image"}
-  \item{...}{Any argument that can be passed to image.plot(fields) and to image(graphics)} 
+  \item{...}{For plot/map: Any argument that can be passed to image.plot(fields) and to image(graphics)} 
+  
+  \item{n}{number of clicks on the map}
+  \item{xy}{show xy coordinates}
+  \item{type}{see under ?locator}
  }
 \details{
   If \code{subsample=FALSE}, then \code{maxdim} is ingored. Subsampled maps are made by skipping rows and columns. This is always 

Modified: pkg/raster/man/overlay.Rd
===================================================================
--- pkg/raster/man/overlay.Rd	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/man/overlay.Rd	2009-01-15 15:37:09 UTC (rev 139)
@@ -1,26 +1,29 @@
-\name{Overlay}
-\alias{Overlay}
+\name{overlay}
+\alias{overlay,RasterLayer,RasterLayer-method}
+\alias{overlay}
 \alias{cover}
 
 \title{ Raster overlay calculation }
 \description{
   Calculate values for a new RasterLayer object, based on two other rasters.  
+  
+  overlay(raster1, raster2, fun=function(x,y){return(x+y)}, filename="", overwrite=FALSE) 
+  \item{fun}{ the function to be appliepd. This should be a function that takes two numbers as an argument }
+
 }
 \usage{
-	Overlay(raster1, raster2, fun=function(x,y){return(x+y)}, filename="", overwrite=FALSE) 
 	cover(raster1, raster2, filename="", overwrite=TRUE) 
 }
 
 \arguments{
   \item{raster1}{ a RasterLayer object }
   \item{raster2}{ a RasterLayer object }
-  \item{fun}{ the function to be appliepd. This should be a function that takes two numbers as an argument }
   \item{filename}{ filename for the output raster. A valid filename must be provided when the data of the input rasters are on disk }
   \item{overwrite}{logical. If \code{TRUE}, existing files will be overwritten}
 }
 
 \details{
-  The default function of Overlay sums the two rasters. Here are two other examples of functions that you can use:
+  The default function of overlay sums the two rasters. Here are two other examples of functions that you can use:
   multiply: \code{fun=function(x,y){return(x*y)}}
   percentage: \code{fun=function(x,y){return(100 * x / y)}}
   
@@ -37,7 +40,7 @@
 	r <- newRaster()
 	r1 <- init(r)
 	r2 <- init(r)
-	r3 <- Overlay(r1, r2)
+	r3 <- overlay(r1, r2)
 	r4 <- setNA(r3, value=1)
 	r5 <- cover(r4, r1)
 # hist(r1) 
@@ -46,7 +49,7 @@
 # hist(r5)	
 
 # long version
-	r6 <- Overlay(r1, r2, fun=function(x,y){return(x*y)} )
+	r6 <- overlay(r1, r2, fun=function(x,y){return(x*y)} )
 # short 'generic' function
 	r7 <- r1 * r2
 }	

Modified: pkg/raster/man/properties.Rd
===================================================================
--- pkg/raster/man/properties.Rd	2009-01-15 09:41:33 UTC (rev 138)
+++ pkg/raster/man/properties.Rd	2009-01-15 15:37:09 UTC (rev 139)
@@ -7,6 +7,7 @@
 \alias{nrow,BasicRaster-method}
 \alias{ncol,BasicRaster-method}
 \alias{ncells}
+\alias{ncell}
 \alias{xres}
 \alias{yres}
 \alias{resolution}
@@ -36,6 +37,7 @@
 ncol(x)
 nrow(x)
 ncells(object)
+ncell(object)
 xres(object)
 yres(object)
 resolution(object)



More information about the Raster-commits mailing list