[Raster-commits] r379 - in pkg/raster: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Mar 20 17:25:53 CET 2009
Author: rhijmans
Date: 2009-03-20 17:25:53 +0100 (Fri, 20 Mar 2009)
New Revision: 379
Added:
pkg/raster/man/makeSparse.Rd
Modified:
pkg/raster/R/setValues.R
pkg/raster/man/setValues.Rd
Log:
Modified: pkg/raster/R/setValues.R
===================================================================
--- pkg/raster/R/setValues.R 2009-03-20 15:04:16 UTC (rev 378)
+++ pkg/raster/R/setValues.R 2009-03-20 16:25:53 UTC (rev 379)
@@ -5,17 +5,35 @@
# Licence GPL v3
+setValuesRows <- function(object, values, startrow, endrow) {
+ if (!is.vector(values)) {stop('values must be a vector')}
+ if (!(is.numeric(values) | is.integer(values) | is.logical(values))) {
+ stop('values must be numeric, integer or logical.') }
+ startow <- round(start)
+ endrow <- round(endrow)
+ if (startrow > endrow) {stop()}
+ if (startrow < 1 | startrow > nrow(object)) {
+ stop(paste("rownumber out of bounds"))
+ }
+ object at data@values <- values
+ object at data@content <- 'row'
+ firstcell <- cellFromRowCol(object, rownr=startrow, colnr=1)
+ lastcell <- cellFromRowCol(object, rownr=endrow, colnr=ncol(object))
+ object at data@indices <- c(firstcell, lastcell)
+ if (length(values) != (lastcell-firstcell) + 1) {stop('wrong length')}
+ return(object)
+}
+
if (!isGeneric('setValues')) {
setGeneric('setValues', function(object, values, rownr=-1, layer=-1)
standardGeneric('setValues'))
}
-
setMethod('setValues', signature(object='RasterLayer'),
- function(object, values, rownr=-1, layer=-1) {
+function(object, values, rownr=-1, layer=-1) {
if (!is.vector(values)) {stop('values must be a vector')}
if (!(is.numeric(values) | is.integer(values) | is.logical(values))) {
@@ -51,6 +69,8 @@
lastcell <- cellFromRowCol(object, rownr=rownr, colnr=ncol(object))
object at data@indices <- c(firstcell, lastcell)
return(object)
+ } else if (length(values) / ncol(object) ) {
+
} else {
stop("length(values) is not equal to ncell(object) or ncol(object)")
}
Added: pkg/raster/man/makeSparse.Rd
===================================================================
--- pkg/raster/man/makeSparse.Rd (rev 0)
+++ pkg/raster/man/makeSparse.Rd 2009-03-20 16:25:53 UTC (rev 379)
@@ -0,0 +1,32 @@
+\name{makeSparse}
+
+\alias{makeSparse}
+
+\title{ Make sparse}
+
+\description{
+Make a sparse RasterLayer object.
+}
+
+\usage{
+makeSparse(raster)
+}
+
+\arguments{
+ \item{raster}{ A \code{RasterLayer} object }
+}
+
+\value{
+a RasterLayer object
+}
+\author{ Robert J. Hijmans }
+
+\examples{
+ r <- raster()
+ r[] <- runif(ncell(r))
+ r[r > 0.001] <- NA
+ rs <- makeSparse(r)
+}
+
+\keyword{ spatial }
+
Modified: pkg/raster/man/setValues.Rd
===================================================================
--- pkg/raster/man/setValues.Rd 2009-03-20 15:04:16 UTC (rev 378)
+++ pkg/raster/man/setValues.Rd 2009-03-20 16:25:53 UTC (rev 379)
@@ -1,26 +1,27 @@
\name{setValues}
+
\alias{setValues}
\alias{setValues,RasterLayer-method}
\alias{setValues,RasterStack-method}
\alias{setValuesBlock}
+\alias{setValuesRows}
\alias{setValuesSparse}
\alias{clearValues}
-\alias{makeSparse}
\title{ Set values of a RasterLayer object }
\description{
-Use these functions to assign values ot a RasterLayer object. While you can access the slots of the object directly, you would do that at your own peril because the value of one raster property can affect values in other properties, and changing slot values may thus break the integrity of the objects. Using slots directly may also lead to code to break in the future if underlying class definitions change.
-
+Use these functions to assign values ot a RasterLayer object.
+While you can access the slots of the object directly, you would do that at your own peril because when setting values,
+multiple slots need to be changed.
}
\usage{
setValues(object, values, rownr=-1, layer=-1)
+setValuesRows(object, values, startrow, endrow)
setValuesBlock(raster, blockvalues, firstcell, lastcell)
setValuesSparse(raster, sparsevalues, cellnumbers)
clearValues(object)
-
-makeSparse(raster)
}
\arguments{
@@ -30,8 +31,10 @@
\item{layer}{ layer number (only relevant for RasterStack objects) }
\item{rownr}{ row number, between 1 and nrow(raster) }
\item{blockvalues}{ Data values to associate with the RasterLayer object for a block of data, i.e. a rectangular area within the entire raster }
- \item{firstcell}{ first cell (upper left corner) of the blockdata }
- \item{lastcell}{ last cell (upper left corner) of the blockdata }
+ \item{startrow}{ first row}
+ \item{endrow}{ last row}
+ \item{firstcell}{ first cell (upper left corner) of the block values }
+ \item{lastcell}{ last cell (upper left corner) of the block values }
\item{sparsevalues}{ not implemented yet -- sparse data values. I.e. values for a number of raster cells }
\item{cellnumbers}{ the cell numbers corresponding to the sparse data }
}
More information about the Raster-commits
mailing list