[Raster-commits] r264 - in pkg/raster: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Feb 9 11:51:45 CET 2009
Author: rhijmans
Date: 2009-02-09 11:51:45 +0100 (Mon, 09 Feb 2009)
New Revision: 264
Added:
pkg/raster/R/round.R
Modified:
pkg/raster/DESCRIPTION
pkg/raster/R/compare.logical.functions.R
pkg/raster/man/Compare-methods.Rd
pkg/raster/man/Logic-methods.Rd
Log:
Modified: pkg/raster/DESCRIPTION
===================================================================
--- pkg/raster/DESCRIPTION 2009-02-08 12:06:32 UTC (rev 263)
+++ pkg/raster/DESCRIPTION 2009-02-09 10:51:45 UTC (rev 264)
@@ -1,8 +1,8 @@
Package: raster
Type: Package
Title: Raster data handling for geographic data analysis and modeling
-Version: 0.8.8-1
-Date: 8-Feb-2009
+Version: 0.8.8-2
+Date: 9-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/compare.logical.functions.R
===================================================================
--- pkg/raster/R/compare.logical.functions.R 2009-02-08 12:06:32 UTC (rev 263)
+++ pkg/raster/R/compare.logical.functions.R 2009-02-09 10:51:45 UTC (rev 264)
@@ -22,6 +22,7 @@
}
+
setMethod('==', signature(e1='BasicRaster', e2='BasicRaster'),
function(e1,e2){
cond <- compare(c(e1, e2), bb=TRUE, rowcol=TRUE, prj=TRUE, tolerance=0.05, stopiffalse=FALSE)
@@ -31,6 +32,7 @@
+
setMethod('!=', signature(e1='BasicRaster', e2='BasicRaster'),
function(e1,e2){
cond <- compare(c(e1, e2), bb=TRUE, rowcol=TRUE, prj=TRUE, tolerance=0.05, stopiffalse=FALSE)
@@ -61,6 +63,25 @@
}
)
+
+
+setMethod('!', signature(x='RasterLayer'),
+ function(x){
+ if (.CanProcessInMemory(x, 1)) {
+ return(setValues(x, !values(x)))
+ } else {
+ raster <- setRaster(x, filename=tempfile())
+ raster <- setDatatype(raster, datatype='logical', datasize=2)
+ for (r in 1:nrow(x)) {
+ raster <- setValues(raster, !.getRowValues(x, r), r)
+ raster <- writeRaster(raster)
+ }
+ return(raster)
+ }
+ }
+)
+
+
setMethod("Compare", signature(e1='numeric', e2='RasterLayer'),
function(e1,e2){
if (!isTRUE(is.atomic(e2) & length(e2)==1)) {
Added: pkg/raster/R/round.R
===================================================================
--- pkg/raster/R/round.R (rev 0)
+++ pkg/raster/R/round.R 2009-02-09 10:51:45 UTC (rev 264)
@@ -0,0 +1,76 @@
+# Authors: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date : January 2009
+# Version 0.8
+# Licence GPL v3
+
+
+
+setMethod(round, signature(x='RasterLayer'),
+ function (x, digits = 0) {
+ if (.CanProcessInMemory(x, 1)) {
+ return(setValues(x, round(values(x), digits)))
+ } else {
+ raster <- setRaster(x, filename=tempfile())
+ raster <- setDatatype(raster, datatype='logical', datasize=2)
+ for (r in 1:nrow(x)) {
+ raster <- setValues(raster, round(.getRowValues(x, r), digits), r)
+ raster <- writeRaster(raster)
+ }
+ return(raster)
+ }
+ }
+)
+
+
+setMethod(trunc, signature(x='RasterLayer'),
+ function (x) {
+ if (.CanProcessInMemory(x, 1)) {
+ return(setValues(x, trunc(values(x))))
+ } else {
+ raster <- setRaster(x, filename=tempfile())
+ raster <- setDatatype(raster, datatype='logical', datasize=2)
+ for (r in 1:nrow(x)) {
+ raster <- setValues(raster, trunc(.getRowValues(x, r)), r)
+ raster <- writeRaster(raster)
+ }
+ return(raster)
+ }
+ }
+)
+
+
+
+setMethod(ceiling, signature(x='RasterLayer'),
+ function (x) {
+ if (.CanProcessInMemory(x)) {
+ return(setValues(x, ceiling(values(x))))
+ } else {
+ raster <- setRaster(x, filename=tempfile())
+ raster <- setDatatype(raster, datatype='logical', datasize=2)
+ for (r in 1:nrow(x)) {
+ raster <- setValues(raster, ceiling(.getRowValues(x, r)), r)
+ raster <- writeRaster(raster)
+ }
+ return(raster)
+ }
+ }
+)
+
+
+setMethod(floor, signature(x='RasterLayer'),
+ function (x) {
+ if (.CanProcessInMemory(x)) {
+ return(setValues(x, floor(values(x))))
+ } else {
+ raster <- setRaster(x, filename=tempfile())
+ raster <- setDatatype(raster, datatype='logical', datasize=2)
+ for (r in 1:nrow(x)) {
+ raster <- setValues(raster, floor(.getRowValues(x, r)), r)
+ raster <- writeRaster(raster)
+ }
+ return(raster)
+ }
+ }
+)
+
Modified: pkg/raster/man/Compare-methods.Rd
===================================================================
--- pkg/raster/man/Compare-methods.Rd 2009-02-08 12:06:32 UTC (rev 263)
+++ pkg/raster/man/Compare-methods.Rd 2009-02-09 10:51:45 UTC (rev 264)
@@ -20,7 +20,7 @@
r1 <- setValues(r1, round(10 * runif(ncell(r1))))
r2 <- setValues(r1, round(10 * runif(ncell(r1))))
as(r1, "BasicRaster") == as(r2, "BasicRaster")
-r3 <- r1 > r2
+r3 <- r1 == r2
b <- newBbox(0, 360, 0, 180)
r4 <- setBbox(r2, b)
Modified: pkg/raster/man/Logic-methods.Rd
===================================================================
--- pkg/raster/man/Logic-methods.Rd 2009-02-08 12:06:32 UTC (rev 263)
+++ pkg/raster/man/Logic-methods.Rd 2009-02-09 10:51:45 UTC (rev 264)
@@ -6,14 +6,19 @@
\alias{is.nan,RasterLayer-method}
\alias{is.finite,RasterLayer-method}
\alias{is.infinite,RasterLayer-method}
+\alias{!,RasterLayer-method}
+
\title{ Methods for logical functions for RasterLayers' }
\description{
- The following boolean operators are available: '&', '|'
- These are also available (with object being a RasterLayer, and the result a RasterLayer with logical values:
- is.na(object)
- is.nan(object)
- is.finite(object)
+The following boolean operators are available: '&', '|', and '!'
+With r being a RasterLayer, and the result a RasterLayer with logical values:
+ r <- r < 3 | r < 6
+ r <- !r
+These are also available :
+ is.na(r)
+ is.nan(r)
+ is.finite(r)
is.infinite(object)
}
More information about the Raster-commits
mailing list