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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Feb 2 15:52:40 CET 2009


Author: rhijmans
Date: 2009-02-02 15:52:39 +0100 (Mon, 02 Feb 2009)
New Revision: 236

Added:
   pkg/raster/R/depracated.R
   pkg/raster/man/init.Rd
   pkg/raster/man/neighborhood.Rd
   pkg/raster/man/reclass.Rd
Modified:
   pkg/raster/DESCRIPTION
   pkg/raster/R/aggregate.R
   pkg/raster/R/conversion.R
   pkg/raster/R/cover.R
   pkg/raster/R/init.R
   pkg/raster/man/Arith-methods.Rd
   pkg/raster/man/aggregate.Rd
   pkg/raster/man/bbox.Rd
   pkg/raster/man/calc.Rd
   pkg/raster/man/coerce.Rd
   pkg/raster/man/cover.Rd
   pkg/raster/man/disaggregate.Rd
   pkg/raster/man/mCalc.Rd
   pkg/raster/man/overlay.Rd
   pkg/raster/man/pointToRaster.Rd
Log:


Modified: pkg/raster/DESCRIPTION
===================================================================
--- pkg/raster/DESCRIPTION	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/DESCRIPTION	2009-02-02 14:52:39 UTC (rev 236)
@@ -1,8 +1,8 @@
 Package: raster
 Type: Package
 Title: Raster data handling for geographic data analysis and modeling
-Version: 0.8.7-7
-Date: 31-Jan-2009
+Version: 0.8.7-8
+Date: 2-Feb-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/R/aggregate.R
===================================================================
--- pkg/raster/R/aggregate.R	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/R/aggregate.R	2009-02-02 14:52:39 UTC (rev 236)
@@ -8,7 +8,7 @@
 
 
 setMethod('aggregate', signature(x='RasterLayer'), 
-function(x, fact = 2, fun = mean, expand = TRUE, rm.NA = TRUE, filename="", overwrite=FALSE, asInt = FALSE)  {
+function(x, fact=2, fun=mean, expand=TRUE, rm.NA=TRUE, filename="", overwrite=FALSE, asInt = FALSE)  {
 	if (length(fact)==1) {
 		fact <- round(fact)
 		if (fact < 2) { stop('fact should be > 1') }

Modified: pkg/raster/R/conversion.R
===================================================================
--- pkg/raster/R/conversion.R	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/R/conversion.R	2009-02-02 14:52:39 UTC (rev 236)
@@ -1,11 +1,13 @@
+# R code for changing rasters (spatial data)
+# Authors: Robert J. Hijmans
+# International Rice Research Institute
+#contact: r.hijmans at gmail.com
+# Date : October 2008
+# Version 0.8
+# Licence GPL v3
 
 
-setAs('SpatialGridDataFrame', 'RasterStack',
-	function(from){ return(asRasterStack (from)) }
-)
-setAs('SpatialPixelsDataFrame', 'RasterStack', 
-	function(from){ return(asRasterStack (from)) }
-)
+
 	
 setAs('SpatialGridDataFrame', 'RasterLayer', 
 	function(from){ return(asRasterLayer (from)) }
@@ -136,28 +138,36 @@
 )
 
 
-asRasterStack <- function(spgrid) {
+
+
+setAs('SpatialGrid', 'RasterStack',
+	function(from){ return(asRasterStack (from)) }
+)
+
+setAs('SpatialGridDataFrame', 'RasterStack',
+	function(from){ return(asRasterStack (from)) }
+)
+
+setAs('SpatialPixelsDataFrame', 'RasterStack', 
+	function(from){ return(asRasterStack (from)) }
+)
+
+setAs('SpatialPixels', 'RasterStack', 
+	function(from){ return(asRasterStack (from)) }
+)
+
+
+.asRasterStack <- function(spgrid) {
 	stk <- new("RasterStack")
 	stk <- setBbox(stk, getBbox(spgrid))
 	stk <- setProjection(stk, spgrid at proj4string)
 	stk <- setRowCol(stk, spgrid at grid@cells.dim[2], spgrid at grid@cells.dim[1])
 	
-	if (class(spgrid)=='SpatialPixels') {
-		# do noting, there is no data
-		# we could store the indices, but then we would have a sparse raster with no data (or with NAs). That goes against our definition of sparse (all NAs have been removed)
-		stop('cannot make a RasterStack from a SpatialPixels object. Make a RasterLayer instead')		
-	} else if (class(spgrid)=='SpatialPixelsDataFrame') {
+	if (class(spgrid)=='SpatialPixelsDataFrame') {
 		spgrid <- as(spgrid, 'SpatialGridDataFrame')
-		rs <- as(stk, 'RasterLayer')
+	}
+	if (class(spgrid)=='SpatialGridDataFrame' ) {
 		stk <- setValues(stk, as.matrix(spgrid at data))
-		for (i in 1:ncol(spgrid at data)) {
-			stk at layers[i] <- rs
-		}
-	} else if ( class(spgrid)=='SpatialGrid' ) {
-		# do nothing, there is no data
-		stop('cannot make a RasterStack from a SpatialGrid object. Make a RasterLayer instead')
-	} else if (class(spgrid)=='SpatialGridDataFrame' ) {
-		stk <- setValues(stk, as.matrix(spgrid at data))
 		rs <- as(stk, 'RasterLayer')
 		stk <- setValues(stk, as.matrix(spgrid at data))
 		for (i in 1:ncol(spgrid at data)) {

Modified: pkg/raster/R/cover.R
===================================================================
--- pkg/raster/R/cover.R	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/R/cover.R	2009-02-02 14:52:39 UTC (rev 236)
@@ -1,31 +1,49 @@
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date :  June 2008
+# Version 0.8
+# Licence GPL v3
 
 
-cover <- function(raster1, raster2, filename="", overwrite=TRUE) {
-	if (class(raster1) != 'RasterLayer' | class(raster2) != 'RasterLayer') {
+cover <- function(x, y, filename="", overwrite=TRUE) {
+	if (class(x) != 'RasterLayer' | class(y) != 'RasterLayer') {
 		stop('first two arguments should be objects of class "RasterLayer"')
 	}
-	if (!compare(c(raster1, raster2))) { 
+	if (!compare(c(x, y))) { 
 		stop('rasters do not match') 
 	}
-	outraster <- setRaster(raster1, filename)
-	if ( dataContent(raster1) == 'all' &  dataContent(raster2) == 'all') {
-		vals <- values(raster1)
-		vals[is.na(vals)] <- values(raster2)[is.na(vals)]
-		outraster <- setValues(outraster, vals)
-		if (filename(outraster) != "") { writeRaster(outraster, overwrite=overwrite) }
-	} else if ( dataSource(raster1) == 'disk' &  dataSource(raster2) == 'disk') {
-		for (r in 1:nrow(outraster)) {
-			raster1 <- readRow(raster1, r)
-			raster2 <- readRow(raster2, r)
-			vals <- values(raster1)
-			vals[is.na(vals)] <- values(raster2)[is.na(vals)] 
-			outraster <- setValues(outraster, vals, r)
-			outraster <- writeRaster(outraster, overwrite=overwrite)
+	outRaster <- setRaster(x, filename)
+	if ( dataContent(x) == 'all' & dataContent(y) == 'all') {
+		x at data@values[is.na(x at data@values)] <- values(y)[is.na(x at data@values)]
+		rm(y)
+		outRaster <- setValues(outRaster, values(x))
+		if (filename(outRaster) != "") { 
+			writeRaster(outRaster, overwrite=overwrite) 
 		}
 	} else {
-		stop('data must be either in memory or on disk')
+		if (dataContent(x) == 'nodata'  &  dataSource(x) == 'ram' ) {
+			stop('values for x are not available')
+		}
+		if (dataContent(y) == 'nodata'  &  dataSource(y) == 'ram' ) {
+			stop('values for y are not available')
+		}
+		v <- vector(length=0)
+		for (r in 1:nrow(outRaster)) {
+			x <- readRow(x, r)
+			y <- readRow(y, r)
+			vals <- values(x)
+			vals[is.na(vals)] <- values(y)[is.na(vals)] 
+			if (filename == "") {
+				v <- c(v, vals)
+			} else {
+				outRaster <- setValues(outRaster, vals, r)
+				outRaster <- writeRaster(outRaster, overwrite=overwrite)
+			}
+		}
+		if (filename(outRaster) == "") {
+			outRaster <- setValues(outRaster, v)
+		}
 	}
-	return(outraster)
+	return(outRaster)
 }
 
-

Added: pkg/raster/R/depracated.R
===================================================================
--- pkg/raster/R/depracated.R	                        (rev 0)
+++ pkg/raster/R/depracated.R	2009-02-02 14:52:39 UTC (rev 236)
@@ -0,0 +1,21 @@
+
+# no longer used. Use calc instead. See ?calc
+
+...isNA <- function(raster, value=0, filename="", overwrite=FALSE, asInt=FALSE) {
+	fun <- function(x) { x[is.na(x)] <- value; return(x)} 
+	raster <- calc(raster, fun, filename, overwrite=overwrite, asInt=asInt)
+	return(raster) 
+}
+
+	
+...setNA <- function(raster, operator= "<=", value=0, filename="", overwrite=FALSE, asInt=FALSE) {
+	if (operator == ">") { fun <- function(x) { x[x>value] <- NA; return(x)}
+	} else if (operator == "<") { fun <- function(x) { x[x<value] <- NA; return(x)}
+	} else if (operator == "<=") { fun <- function(x) { x[x<=value] <- NA; return(x)}
+	} else if (operator == ">=") { fun <- function(x) { x[x>=value] <- NA; return(x)}
+	} else if (operator == "==") { fun <- function(x) { x[x==value] <- NA; return(x)}
+	} else if (operator == "!=") { fun <- function(x) { x[x!=value] <- NA; return(x)}
+	}
+	return(calc(raster, fun, filename, overwrite=overwrite, asInt=asInt))
+}
+

Modified: pkg/raster/R/init.R
===================================================================
--- pkg/raster/R/init.R	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/R/init.R	2009-02-02 14:52:39 UTC (rev 236)
@@ -37,22 +37,3 @@
 }
 
 
-isNA <- function(raster, value=0, filename="", overwrite=FALSE, asInt=FALSE) {
-	fun <- function(x) { x[is.na(x)] <- value; return(x)} 
-	raster <- calc(raster, fun, filename, overwrite=overwrite, asInt=asInt)
-	return(raster) 
-}
-
-	
-setNA <- function(raster, operator= "<=", value=0, filename="", overwrite=FALSE, asInt=FALSE) {
-	if (operator == ">") { fun <- function(x) { x[x>value] <- NA; return(x)}
-	} else if (operator == "<") { fun <- function(x) { x[x<value] <- NA; return(x)}
-	} else if (operator == "<=") { fun <- function(x) { x[x<=value] <- NA; return(x)}
-	} else if (operator == ">=") { fun <- function(x) { x[x>=value] <- NA; return(x)}
-	} else if (operator == "==") { fun <- function(x) { x[x==value] <- NA; return(x)}
-	} else if (operator == "!=") { fun <- function(x) { x[x!=value] <- NA; return(x)}
-	}
-	return(calc(raster, fun, filename, overwrite=overwrite, asInt=asInt))
-}
-
-

Modified: pkg/raster/man/Arith-methods.Rd
===================================================================
--- pkg/raster/man/Arith-methods.Rd	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/man/Arith-methods.Rd	2009-02-02 14:52:39 UTC (rev 236)
@@ -4,6 +4,7 @@
 \alias{Arith,numeric,RasterLayer-method}
 \alias{Arith,RasterLayer,numeric-method}
 \alias{Arith,RasterLayer,RasterLayer-method}
+
 \title{Methods for arithmic function for RasterLayer objects}
 \description{
   Standard arithmic functions for computations with RasterLayer objects and numeric values 

Modified: pkg/raster/man/aggregate.Rd
===================================================================
--- pkg/raster/man/aggregate.Rd	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/man/aggregate.Rd	2009-02-02 14:52:39 UTC (rev 236)
@@ -4,7 +4,7 @@
 
 \title{Aggregate}
 \description{
-	aggregate a raster to create a new raster with a lower resolution
+	Aggregate a RasterLayer to create a new raster with a lower resolution.
 }
 \usage{
 aggregate(x, fact = 2, fun = mean, expand = TRUE, rm.NA = TRUE, filename="", overwrite=FALSE, asInt = FALSE) 
@@ -22,7 +22,7 @@
 }
 
 \details{
- In aggregation \code{fact = 2} will result in a grid with 2 x 2 = 4 times fewer cells, while in disaggregation 4 times more cells will be created.
+ In aggregation \code{fact = 2} will result in a grid with 2 x 2 = 4 times fewer cells.
 }
 
 \value{

Modified: pkg/raster/man/bbox.Rd
===================================================================
--- pkg/raster/man/bbox.Rd	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/man/bbox.Rd	2009-02-02 14:52:39 UTC (rev 236)
@@ -19,7 +19,7 @@
 setBbox sets the bounding box of a Raster* object
 changeBbox changes the bounding box of a Raster* object
 
-You can also use bbox(object) to get a sp type bbox (a 2 x 2 matrix), but such an object cannot be used as a bounding box in this package.
+You can also use bbox(object) to get a sp type bbox (a 2 x 2 matrix), but such an object cannot be used with the other functon described here as it returns a matrix, and not a BoundingBox object.
 }
 
 \usage{
@@ -41,12 +41,12 @@
   \item{snap}{Adjust the bounding box so that the new raster is aligned with the old raster }
 }
   
-\author{Robert J. Hijmans  \email{r.hijmans at gmail.com}}
+\author{Robert J. Hijmans}
 \examples{
-	rs <- raster()
-	bb <- newBbox(-10, 10, -20, 20)
-	rs <- setBbox(rs, bb, keepres=TRUE)
-	rs <- changeBbox(rs, ymx = 90)
+r <- raster()
+bb <- newBbox(-10, 10, -20, 20)
+r <- setBbox(r, bb, keepres=TRUE)
+r <- changeBbox(r, xmn=xmin(r)+1, xmx=xmax(r)+1)
 }
 
 \keyword{spatial}

Modified: pkg/raster/man/calc.Rd
===================================================================
--- pkg/raster/man/calc.Rd	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/man/calc.Rd	2009-02-02 14:52:39 UTC (rev 236)
@@ -1,11 +1,6 @@
-\name{calc}
+\name{calculate}
 
 \alias{calc}
-\alias{reclass}
-\alias{neighborhood}
-\alias{isNA}
-\alias{setNA}
-\alias{init}
 
 \title{RasterLayer calculate}
 \description{
@@ -13,74 +8,46 @@
 }
 \usage{
 calc(raster, fun=sqrt, filename="", overwrite=FALSE, asInt=FALSE)
-isNA(raster, value = 0, filename="", overwrite=FALSE, asInt = FALSE)
-setNA(raster, operator = "<=", value = 0, filename="", overwrite=FALSE, asInt = FALSE)
-init(raster, fun=runif, filename="", overwrite=FALSE, asInt = FALSE) 
-neighborhood(raster, fun=mean, filename="", ngb=3, keepdata=TRUE, overwrite=FALSE, asInt=FALSE) 
-reclass(raster, rclmat, filename="", overwrite=FALSE, asInt = FALSE)
 }
 
 \arguments{
   \item{raster}{A RasterLayer object}
   \item{fun}{The function to be applied}
-  \item{value}{The (threshold) value to replace with NA or that should be set to NA}
-  \item{operator}{The operator in setNA relative to the \code{value}, to set e.g. all values <= 2 to NA}
-  \item{rclmat}{Matrix for reclassifcation. (see below)}
   \item{filename}{Output filename for a new raster; if NA the result is not written to a file but returned with the RasterLayer object, in the data slot}
   \item{overwrite}{Logical to indicate whether an existing output file should be overwritten}
   \item{asInt}{logical. If \code{TRUE}, output will be integer values}
-  \item{ngb}{Neighborhood size. Expressed in number of cells in a single direction. I.e. 3 refers to 2 cells at each side of the focal cell. Queen's case, 8 cells in total}
-  \item{keepdata}{Logical. If \code{TRUE}, NA will be removed for neighborhood computations. The result will only be NA if all cells are NA}
 }
 
 \details{
-	Use \code{calc} to calculate values for a new raster using a function (\code{fun}) that takes a single number as an argument (and retruns a single number). E.g. to add, multiply or divide a number (cell value) by a constant.
-	\code{isNA} replaces NA with a value and setNA sets values to NA; both are helper functions based on calc.
-	\code{init} sets a value without reference to existing values. E.g. initialize with a single, sequential, or random number.
-	\code{neighborhood} computes a neighborhood value. I.e. a value computed with function 'fun', for all cells in the square neigborhood (of size ngb * ngb) around each cell 
-	\code{reclass} reclassifies groups of values to other values. E.g. All values between 1 and 10 become 1, and between 11 and 15 become 2. 
-	Reclassification is done with matrix "rclmat". This matrix must have 3 columns. The first two columns are "from" "to" of the input values, and the third column has the new value for that range.
+Use \code{calc} to calculate values for a new raster using a function (\code{fun}) that takes a single number as an argument (and retruns a single number). E.g. to add, multiply or divide a number (cell value) by a constant.
 	
-	If the input raster has all values in memory (after readAll(raster)), the functions will also return the new data in memory. If there is a file name, the data will also be saved to that file. 
-	If the values are not in memory the new values will be written to file. 
-	}
+If the input RasterLayer object has all values in memory (e.g. after readAll(raster)), the function will also return the new values in memory. If a filename is provided, the values will also be saved to that file. 
+If the values are not in memory the new values will be written to file. 
+}
+
 \value{
-	a new raster file (on disk and/or in memory) and associated object (in the R environment)
+A new RasterLayer object (in the R environment), and in some cases the side effect of a new file on disk.
 }
-\author{Robert J. Hijmans \email{r.hijmans at gmail.com}}
+\author{Robert J. Hijmans}
 
 \examples{
 
- r <- raster(ncols=36, nrows=18)
- 
-# two ways to set all value to 1 
-# with a function
- set1function <- function(x){rep(1, x)}
- r <- init(r, fun=set1function)
-# "manually" 
- r <- setValues(r, rep(1, ncell(r)))
- 
-# random values (see ?runif )
- r <- init(r, fun=runif)
- 
-# neighborhood calc
- ngb <- neighborhood(r, fun=sum) 
+r <- raster(ncols=36, nrows=18)
+r[] <- 1:ncell(r)
 
-# all values below 0.5 become NA
- r2 <- setNA(r, operator = "<", value=0.5)
-# change the NAs to -9999
- r3 <- isNA(r2, -9999)  
+
+# multiply values with 10
+fun <- function(x) { x * 10 }
+rc <- calc(r, fun)
+
+# set values below 100 to NA. 
+fun <- function(x) { x[x<100] <- NA; return(x) }
+rc <- calc(r, fun)
+
+# set NA values to -9999
+fun <- function(x) { x[is.na(x)] <- -9999; return(x)} 
+rc <- calc(rc, fun)
  
-# reclassify the values into three groups 
-# all values between 0 and 0.25 become 1, etc.
- m <- c(0, 0.25, 1,  0.25, 0.5, 2,  0.5, 1, 3)
- rclmat <- matrix(m, ncol=3, byrow=TRUE)
- r4 <- reclass(r, rclmat)
- 
-#hist(r)
-#hist(r2)
-#hist(r3)
-#hist(r4)
- 
 }
+
 \keyword{spatial}

Modified: pkg/raster/man/coerce.Rd
===================================================================
--- pkg/raster/man/coerce.Rd	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/man/coerce.Rd	2009-02-02 14:52:39 UTC (rev 236)
@@ -8,21 +8,18 @@
 \alias{asRasterLayer,SpatialPixels,numeric-method}
 \alias{asRasterLayer,SpatialPixelsDataFrame,numeric-method}
 \alias{asRasterLayer,SpatialGridDataFrame,numeric-method}
-
 \alias{asRasterLayer}
-\alias{asRasterStack}
 \alias{asSpGrid}
 
 \title{ Coercion of Raster*, SpatialGrid and SpatialPixels* objects. }
 
 \description{  
-	Functions to coerce a Raster* objects into an sp SpatialGridDataFrame object and 
-	to coerce a RasterLayer or RasterStack object from a sp SpatialPixels* or SpatialGrid* object
+Functions to coerce a Raster* objects into an sp SpatialGridDataFrame object and 
+to coerce a RasterLayer or RasterStack object from a sp SpatialPixels* or SpatialGrid* object
 }
 
 \usage{
 asRasterLayer(object, index) 
-asRasterStack(spgrid) 
 asSpGrid(object, type='grid') 
 }
 
@@ -36,6 +33,13 @@
 \details{
  if \code{type} is 'pixel' a SpatialPixel* object is returned. If the RasterLayer object has data a SpatialPixelDataFrame will be returned.
  if \code{type} is 'grid' a SpatialGrid* object is returned. If the RasterLayer object has data a SpatialGridDataFrame will be returned.
+ 
+ In most cases you can also coerce objects using setAs, except that you cannot change the default 'index' (variable) and the first variable (column of the data frame of a Spatial* object) is used.
+ 
+ e.g.: setAs(aSpatialPixelsDataFrame, "RasterStack") or setAs(aRasterLayer, "SpatialGridDataFrame")
+ 
+)
+ 
 }
 
 \value{

Modified: pkg/raster/man/cover.Rd
===================================================================
--- pkg/raster/man/cover.Rd	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/man/cover.Rd	2009-02-02 14:52:39 UTC (rev 236)
@@ -7,30 +7,35 @@
 }
 
 \usage{
-	cover(raster1, raster2, filename="", overwrite=TRUE) 
+cover(x, y, filename="", overwrite=TRUE) 
 }
 
 \arguments{
-  \item{raster1}{ a RasterLayer object }
-  \item{raster2}{ a RasterLayer object }
+  \item{x}{ a RasterLayer object }
+  \item{y}{ a RasterLayer object }
   \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 function returns a RasterLayer with the values of the second RasterLayer where the first RasterLayer values are NA; and the values of the first RasterLayer elsewhere.
+The function returns a RasterLayer with the values of the second RasterLayer where the values of the first RasterLayer are NA and the values of the first RasterLayer elsewhere.
+
+If the input RasterLayer object has all values in memory (e.g. after readAll(raster)), the function will also return the new values in memory. If a filename is provided, the values will also be saved to that file. 
+If the values are not in memory the new values will be written to file. 
 }
+
 \value{
-  a new RasterLayer object (if a filename is provided, a file on disk) 
+A new RasterLayer object (in the R environment), and in some cases the side effect of a new file on disk.
 }
-\author{ Robert J. Hijmans \email{r.hijmans at gmail.com} }
+\author{Robert J. Hijmans}
 
 \examples{
-	r <- raster()
-	r1 <- init(r)
-	r2 <- init(r)
-	r3 <- setNA(r2, value=0.5)
-	r4 <- cover(r3, r1)
+r1 <- raster()
+r1[] <- 1:ncell(r1)
+r2 <- setValues(r1, runif(ncell(r1)))
+fun <- function(x) { x[x<0.5] <- NA; return(x) }
+r2 <- calc(r2, fun)
+r3 <- cover(r2, r1)
 }	
 
 \keyword{ spatial }

Modified: pkg/raster/man/disaggregate.Rd
===================================================================
--- pkg/raster/man/disaggregate.Rd	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/man/disaggregate.Rd	2009-02-02 14:52:39 UTC (rev 236)
@@ -3,7 +3,7 @@
 
 \title{Disaggregate}
 \description{
-	Disaggregate a raster to create a new raster 
+Disaggregate a raster to create a new raster 
 }
 \usage{
 disaggregate(raster, fact=2, filename="", overwrite=FALSE) 
@@ -17,7 +17,7 @@
 }
 
 \details{
- Fact can be a single integer or two integers c(x,y), in which case the first one is the horizontal disaggregation factor and y the vertical disaggreation factor
+Fact can be a single integer or two integers c(x,y), in which case the first one is the horizontal disaggregation factor and y the vertical disaggreation factor. If a single integer values is supplied, cells are disaggregated with the same factor in x and y direction.
 }
 
 \value{
@@ -26,10 +26,10 @@
 \author{Robert J. Hijmans \email{r.hijmans at gmail.com}}
 
 \examples{
-	r <- raster(ncols=10, nrows=10)
-	rd <- disaggregate(r, fact=c(10, 5))
-	ncol(rd)
-	nrow(rd)	
+r <- raster(ncols=10, nrows=10)
+rd <- disaggregate(r, fact=c(10, 5))
+ncol(rd)
+nrow(rd)
 }
 
 \keyword{spatial}

Added: pkg/raster/man/init.Rd
===================================================================
--- pkg/raster/man/init.Rd	                        (rev 0)
+++ pkg/raster/man/init.Rd	2009-02-02 14:52:39 UTC (rev 236)
@@ -0,0 +1,49 @@
+\name{initialize}
+
+\alias{init}
+
+\title{Intitialize values of a RasterLayer}
+\description{
+  Set values for a new raster (from scratch)
+}
+\usage{
+init(raster, fun=runif, filename="", overwrite=FALSE, asInt = FALSE) 
+}
+
+\arguments{
+  \item{raster}{A RasterLayer object}
+  \item{fun}{The function to be applied}
+  \item{filename}{Output filename for a new raster; if NA the result is not written to a file but returned with the RasterLayer object, in the data slot}
+  \item{overwrite}{Logical to indicate whether an existing output file should be overwritten}
+  \item{asInt}{logical. If \code{TRUE}, output will be integer values}
+}
+
+\details{
+\code{init} sets a value without reference to existing values. E.g. initialize with a single, sequential, or random number.
+	
+If the input RasterLayer object has all values in memory (e.g. after readAll(raster)), the function will also return the new values in memory. If a filename is provided, the values will also be saved to that file. 
+If the values are not in memory the new values will be written to file. 
+}
+
+\value{
+A new RasterLayer object (in the R environment), and in some cases the side effect of a new file on disk.
+}
+\author{Robert J. Hijmans}
+
+\examples{
+
+r <- raster(ncols=36, nrows=18)
+ 
+# there are different ways to set all values to 1 
+# with a function (this will work for very large files if a file name is supplied)
+ set1function <- function(x){rep(1, x)}
+ r <- init(r, fun=set1function, filename='test.grd')
+# "manually", if all the values can be kept in memory.
+ r <- setValues(r, rep(1, ncell(r)))
+# or  
+ r[] <- rep(1, ncell(r))
+ 
+}
+
+\keyword{spatial}
+

Modified: pkg/raster/man/mCalc.Rd
===================================================================
--- pkg/raster/man/mCalc.Rd	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/man/mCalc.Rd	2009-02-02 14:52:39 UTC (rev 236)
@@ -3,7 +3,7 @@
 
 \title{ multiple layers calculate }
 \description{
-  Calculate values for a new raster from the layers in a RasterStack
+  Calculate values for a new RasterLayer from the layers in a RasterStack
 }
 
 \usage{
@@ -20,44 +20,15 @@
 
 \details{
 	\code{fun} should be a function that takes a one dimensional vector of value as input, and returns a single value.
-	
-	If the input raster has all values in memory (after readAll(raster)), the functions will also return the new data in memory. If there is a file name, the data will also be saved to that file. 
-	If the values are not in memory the new values will be written to file. 
-	}
+}
+
 \value{
 	a new RasterLayer 
 }
-\author{ Robert J. Hijmans \email{r.hijmans at gmail.com} }
+\author{ Robert J. Hijmans}
 
 \examples{
 
- r <- raster(ncols=36, nrows=18)
- 
-# two ways to set all value to 1 
-#1, with a function
- set1function <- function(x){rep(1, x)}
- r <- init(r, fun=set1function)
-# 2, "manually" 
- r <- setValues(r, rep(1, ncell(r)))
- 
-# random values (see ?runif )
- r <- init(r, fun=runif)
 
-# all values below 0.5 become NA
- r2 <- setNA(r, operator ="<", value=0.5)
-# change the NAs to -9999
- r3 <- isNA(r2, -9999)  
- 
-# reclassify the values into three groups 
-# all values between 0 and 0.25 become 1, etc.
- m <- c(0, 0.25, 1,  0.25, 0.5, 2,  0.5, 1, 3)
- rclmat <- matrix(m, ncol=3, byrow=TRUE)
- r4 <- reclass(r, rclmat)
- 
-#hist(r)
-#hist(r2)
-#hist(r3)
-#hist(r4)
- 
 }
 \keyword{ spatial }

Added: pkg/raster/man/neighborhood.Rd
===================================================================
--- pkg/raster/man/neighborhood.Rd	                        (rev 0)
+++ pkg/raster/man/neighborhood.Rd	2009-02-02 14:52:39 UTC (rev 236)
@@ -0,0 +1,40 @@
+\name{neighborhood}
+
+\alias{neighborhood}
+
+\title{RasterLayer calculate}
+\description{
+Neighborhood calculations
+}
+\usage{
+neighborhood(raster, fun=mean, filename="", ngb=3, keepdata=TRUE, overwrite=FALSE, asInt=FALSE) 
+}
+
+\arguments{
+  \item{raster}{A RasterLayer object}
+  \item{fun}{The function to be applied}
+  \item{filename}{Output filename for a new raster; if NA the result is not written to a file but returned with the RasterLayer object, in the data slot}
+  \item{ngb}{Neighborhood size. Expressed in number of cells in a single direction. I.e. 3 refers to 2 cells at each side of the focal cell. Queen's case, 8 cells in total}
+  \item{keepdata}{Logical. If \code{TRUE}, NA will be removed for neighborhood computations. The result will only be NA if all cells are NA}
+  \item{overwrite}{Logical to indicate whether an existing output file should be overwritten}
+  \item{asInt}{logical. If \code{TRUE}, output will be integer values}
+}
+
+\details{
+\code{neighborhood} computes a neighborhood value. I.e. a value computed with function 'fun', for all cells in the square neigborhood (of size ngb * ngb) around each cell 
+If the input RasterLayer object has all values in memory (e.g. after readAll(raster)), the function will also return the new values in memory. If a filename is provided, the values will also be saved to that file. 
+If the values are not in memory the new values will be written to file. 
+	}
+\value{
+A new RasterLayer object (in the R environment), and in some cases the side effect of a new file on disk.
+}
+\author{Robert J. Hijmans}
+
+\examples{
+
+r <- raster(ncols=36, nrows=18)
+r[] <- runif(ncell(r)) 
+ngb <- neighborhood(r, fun=sum) 
+ 
+}
+\keyword{spatial}

Modified: pkg/raster/man/overlay.Rd
===================================================================
--- pkg/raster/man/overlay.Rd	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/man/overlay.Rd	2009-02-02 14:52:39 UTC (rev 236)
@@ -1,4 +1,5 @@
 \name{overlay}
+\alias{overlay}
 \alias{overlay,RasterLayer,RasterLayer-method}
 
 \title{ Raster overlay calculation }

Modified: pkg/raster/man/pointToRaster.Rd
===================================================================
--- pkg/raster/man/pointToRaster.Rd	2009-02-02 06:43:00 UTC (rev 235)
+++ pkg/raster/man/pointToRaster.Rd	2009-02-02 14:52:39 UTC (rev 236)
@@ -1,6 +1,5 @@
 \name{ point to raster conversion}
 \alias{pointsToRaster}
-\alias{diversity.index.richness}
 
 \title{ Point to raster diversity functions }
 \description{
@@ -11,24 +10,32 @@
 }
 
 \arguments{
-  \item{raster}{ ~~Describe \code{rs} here~~ }
-  \item{filename}{ ~~Describe \code{filename} here~~ }
-  \item{overwrite}{ ~~Describe \code{filename} here~~ }  
-  \item{xy}{ ~~Describe \code{xya} here~~ }
-  \item{values}{ ~~Describe \code{xya} here~~ }  
-  \item{fun}{ ~~Describe \code{fun} here~~ }
+  \item{raster}{ a RasterLayer object }
+  \item{xy}{ a matrix of x and y coordinates (in the same map reference system as the raster) }
+  \item{filename}{ output filename }
+  \item{overwrite}{if \code{TRUE}, the file will be overwritten if it exists}  
+  \item{values}{a vector of length xy[,1] with the values to be used}  
+  \item{fun}{ the function to be applied}
 }
 
-
 \details{
+Each point is assinged to a grid cell. The value of a grid cell is determined by the values associated with the points and function fun.
+If you want the count of points in each grid cell, use the (default) \code{length} function. I.e. for each cell it computes the length of the vector of points.
+If you want the sum of the values, use \code{sum} for the sum.
+If you want a yes/no result, you can use fun=function(x){if(lenght(x)>0 {r<-1} else {r<-0}; return(r)}
 }
 \value{
   a RasterLayer object
 }
-\author{Robert J. Hijmans  \email{r.hijmans at gmail.com}}
+\author{Robert J. Hijmans}
 
-
 \examples{
-
+r <- raster(ncols=36, nrows=18)
+n <- 1000
+x <- runif(n)* 360 - 180
+y <- runif(n)* 180 - 90
+xy <- cbind(x, y)
+vals <- rep(1, n)
+r <- pointsToRaster(r, xy, vals)
 }
 \keyword{ spatial }

Added: pkg/raster/man/reclass.Rd
===================================================================
--- pkg/raster/man/reclass.Rd	                        (rev 0)
+++ pkg/raster/man/reclass.Rd	2009-02-02 14:52:39 UTC (rev 236)
@@ -0,0 +1,45 @@
+\name{reclass}
+
+\alias{reclass}
+
+\title{Reclassify values of a RasterLayer}
+\description{
+Reclassify values of a RasterLayer
+}
+\usage{
+reclass(raster, rclmat, filename="", overwrite=FALSE, asInt = FALSE)
+}
+
+\arguments{
+  \item{raster}{A RasterLayer object}
+  \item{rclmat}{Matrix for reclassifcation. (see below)}
+  \item{filename}{Output filename for a new raster; if NA the result is not written to a file but returned with the RasterLayer object, in the data slot}
+  \item{overwrite}{Logical to indicate whether an existing output file should be overwritten}
+  \item{asInt}{logical. If \code{TRUE}, output will be integer values}
+}
+
+\details{
+\code{reclass} reclassifies groups of values to other values. E.g. All values between 1 and 10 become 1, and between 11 and 15 become 2. 
+Reclassification is done with matrix "rclmat". This matrix must have 3 columns. The first two columns are "from" "to" of the input values, and the third column has the new value for that range.
+	
+If the input RasterLayer object has all values in memory (e.g. after readAll(raster)), the function will also return the new values in memory. If a filename is provided, the values will also be saved to that file. 
+If the values are not in memory the new values will be written to file. 
+}
+\value{
+A new RasterLayer object (in the R environment), and in some cases the side effect of a new file on disk.
+}
+
+\author{Robert J. Hijmans}
+
+\examples{
+
+r <- raster(ncols=36, nrows=18)
+r[] <- runif(ncell(r)) 
+# reclassify the values into three groups 
+# all values between 0 and 0.25 become 1, etc.
+m <- c(0, 0.25, 1,  0.25, 0.5, 2,  0.5, 1, 3)
+rclmat <- matrix(m, ncol=3, byrow=TRUE)
+rc <- reclass(r, rclmat)
+ 
+}
+\keyword{spatial}



More information about the Raster-commits mailing list