[Raster-commits] r265 - in pkg/raster: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Feb 9 12:26:11 CET 2009
Author: rhijmans
Date: 2009-02-09 12:26:11 +0100 (Mon, 09 Feb 2009)
New Revision: 265
Added:
pkg/raster/man/round.Rd
Modified:
pkg/raster/R/round.R
Log:
Modified: pkg/raster/R/round.R
===================================================================
--- pkg/raster/R/round.R 2009-02-09 10:51:45 UTC (rev 264)
+++ pkg/raster/R/round.R 2009-02-09 11:26:11 UTC (rev 265)
@@ -8,11 +8,18 @@
setMethod(round, signature(x='RasterLayer'),
function (x, digits = 0) {
+ digits <- max(0, digits)
if (.CanProcessInMemory(x, 1)) {
- return(setValues(x, round(values(x), digits)))
+ x <- setValues(x, round(values(x), digits))
+ if (digits == 0) {
+ x <- setDatatype(x, 'integer')
+ }
+ return(x)
} else {
raster <- setRaster(x, filename=tempfile())
- raster <- setDatatype(raster, datatype='logical', datasize=2)
+ if (digits == 0) {
+ x <- setDatatype(x, 'integer')
+ }
for (r in 1:nrow(x)) {
raster <- setValues(raster, round(.getRowValues(x, r), digits), r)
raster <- writeRaster(raster)
@@ -26,10 +33,12 @@
setMethod(trunc, signature(x='RasterLayer'),
function (x) {
if (.CanProcessInMemory(x, 1)) {
- return(setValues(x, trunc(values(x))))
+ x <- setValues(x, trunc(values(x)))
+ x <- setDatatype(x, 'integer')
+ return(x)
} else {
raster <- setRaster(x, filename=tempfile())
- raster <- setDatatype(raster, datatype='logical', datasize=2)
+ raster <- setDatatype(raster, 'integer')
for (r in 1:nrow(x)) {
raster <- setValues(raster, trunc(.getRowValues(x, r)), r)
raster <- writeRaster(raster)
@@ -44,10 +53,12 @@
setMethod(ceiling, signature(x='RasterLayer'),
function (x) {
if (.CanProcessInMemory(x)) {
- return(setValues(x, ceiling(values(x))))
+ x <- setValues(x, ceiling(values(x)))
+ x <- setDatatype(x, 'integer')
+ return(x)
} else {
raster <- setRaster(x, filename=tempfile())
- raster <- setDatatype(raster, datatype='logical', datasize=2)
+ raster <- setDatatype(raster, 'integer')
for (r in 1:nrow(x)) {
raster <- setValues(raster, ceiling(.getRowValues(x, r)), r)
raster <- writeRaster(raster)
@@ -61,10 +72,12 @@
setMethod(floor, signature(x='RasterLayer'),
function (x) {
if (.CanProcessInMemory(x)) {
- return(setValues(x, floor(values(x))))
+ x <- setValues(x, floor(values(x)))
+ x <- setDatatype(x, 'integer')
+ return(x)
} else {
raster <- setRaster(x, filename=tempfile())
- raster <- setDatatype(raster, datatype='logical', datasize=2)
+ raster <- setDatatype(raster, 'integer')
for (r in 1:nrow(x)) {
raster <- setValues(raster, floor(.getRowValues(x, r)), r)
raster <- writeRaster(raster)
Added: pkg/raster/man/round.Rd
===================================================================
--- pkg/raster/man/round.Rd (rev 0)
+++ pkg/raster/man/round.Rd 2009-02-09 11:26:11 UTC (rev 265)
@@ -0,0 +1,52 @@
+\name{round}
+\docType{methods}
+\alias{round,RasterLayer-method}
+\alias{trunc,RasterLayer-method}
+\alias{ceiling,RasterLayer-method}
+\alias{floor,RasterLayer-method}
+
+
+\title{ Functions to create integer values for a RasterLayer }
+
+\description{
+These functions take a single RasterLayer argument \code{x}
+
+ceiling returns a RasterLayer with the smallest integers not less than the corresponding values of x.
+
+floor returns a RasterLayer with the largest integers not greater than the corresponding values of x.
+
+trunc returns a RasterLayer with the integers formed by truncating the values in x toward 0.
+
+round returns a RasterLayer with values rounded to the specified number of digits (decimal places; default 0).
+}
+
+
+\section{Methods}{
+\describe{
+ceiling(x)
+floor(x)
+trunc(x, ...)
+round(x, digits = 0)
+
+
+\item{x}{a RasterLayer object}
+\item{digits}{integer indicating the precision to be used}
+\item{...}{arguments to be passed to methods}
+}
+}
+
+
+\details{
+see ?base::round
+
+}
+\value{
+a RasterLayer object
+}
+\author{Robert J.Hijmans}
+\examples{
+r <- raster(ncol=10, nrow=10)
+r[] <- runif(ncell(r)) * 10
+s <- round(r)
+}
+\keyword{spatial}
More information about the Raster-commits
mailing list