[Raster-commits] r304 - in pkg/raster: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Mar 3 07:54:11 CET 2009
Author: rhijmans
Date: 2009-03-03 07:54:10 +0100 (Tue, 03 Mar 2009)
New Revision: 304
Added:
pkg/raster/R/Artith.R
pkg/raster/R/Math.R
pkg/raster/R/getBbox.R
pkg/raster/man/BoundingBox-class.Rd
pkg/raster/man/getBbox.Rd
pkg/raster/man/plot-methods.Rd
pkg/raster/man/setBbox.Rd
pkg/raster/man/unionBbox.Rd
pkg/raster/man/writeFormats.Rd
pkg/raster/man/writeRaster.Rd
pkg/raster/man/writeStack.Rd
Removed:
pkg/raster/R/round.R
pkg/raster/man/bbox.Rd
pkg/raster/man/write.Rd
Modified:
pkg/raster/DESCRIPTION
pkg/raster/R/aggregate.R
pkg/raster/R/bounding.box.R
pkg/raster/R/group.generic.functions.R
pkg/raster/R/mCalc.R
pkg/raster/R/plot.R
pkg/raster/R/raster.create.R
pkg/raster/R/write.R
pkg/raster/man/Arith-methods.Rd
pkg/raster/man/Math-methods.Rd
pkg/raster/man/aggregate-methods.Rd
pkg/raster/man/calc-methods.Rd
pkg/raster/man/classes.Rd
pkg/raster/man/map.Rd
pkg/raster/man/overlay-methods.Rd
pkg/raster/man/saveAs.Rd
Log:
Modified: pkg/raster/DESCRIPTION
===================================================================
--- pkg/raster/DESCRIPTION 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/DESCRIPTION 2009-03-03 06:54:10 UTC (rev 304)
@@ -1,8 +1,8 @@
Package: raster
Type: Package
Title: Raster data handling for geographic data analysis and modeling
-Version: 0.8.8-8
-Date: 28-Feb-2009
+Version: 0.8.8-9
+Date: 3-March-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>
Added: pkg/raster/R/Artith.R
===================================================================
--- pkg/raster/R/Artith.R (rev 0)
+++ pkg/raster/R/Artith.R 2009-03-03 06:54:10 UTC (rev 304)
@@ -0,0 +1,65 @@
+# Authors: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date : January 2009
+# Version 0.8
+# Licence GPL v3
+
+
+
+setMethod("Arith", signature(e1='RasterLayer', e2='RasterLayer'),
+ function(e1, e2){
+ if ( compare(c(e1, e2)) ) {
+ if (.CanProcessInMemory(e1, 4)) {
+ raster <- setRaster(e1, values=callGeneric( as.numeric(.getRasterValues(e1)), .getRasterValues(e2)))
+ } else {
+ raster <- setRaster(e1, filename=tempfile())
+ for (r in 1:nrow(e1)) {
+ raster <- setValues(raster, callGeneric( as.numeric(.getRowValues(e1, r)), .getRowValues(e2, r) ), r)
+ raster <- writeRaster(raster)
+ }
+ if (options('verbose')[[1]]) {
+ cat('values were written to:', filename(raster))
+ }
+ }
+ return(raster)
+ }
+ }
+)
+
+
+setMethod("Arith", signature(e1='RasterLayer', e2='numeric'),
+ function(e1, e2){
+ if (.CanProcessInMemory(e1, 3)) {
+ return(setRaster(e1, values=callGeneric(as.numeric(.getRasterValues(e1)), e2) ) )
+ } else {
+ raster <- setRaster(e1, filename=tempfile())
+ for (r in 1:nrow(e1)) {
+ raster <- setValues(raster, callGeneric( as.numeric(.getRowValues(e1, r)), e2) , r)
+ raster <- writeRaster(raster)
+ }
+ if (options('verbose')[[1]]) {
+ cat('values were written to:', filename(raster))
+ }
+ return(raster)
+ }
+ }
+)
+
+setMethod("Arith", signature(e1='numeric', e2='RasterLayer'),
+ function(e1, e2){
+ if (.CanProcessInMemory(e2, 3)) {
+ return(setRaster(e2, values=callGeneric(as.numeric(e1), .getRasterValues(e2))))
+ } else {
+ raster <- setRaster(e2, filename=tempfile())
+ for (r in 1:nrow(e2)) {
+ raster <- setValues(raster, callGeneric(as.numeric(e1), .getRowValues(e2, r)) , r)
+ raster <- writeRaster(raster)
+ }
+ if (options('verbose')[[1]]) {
+ cat('values were written to:', filename(raster))
+ }
+ return(raster)
+ }
+ }
+)
+
Added: pkg/raster/R/Math.R
===================================================================
--- pkg/raster/R/Math.R (rev 0)
+++ pkg/raster/R/Math.R 2009-03-03 06:54:10 UTC (rev 304)
@@ -0,0 +1,57 @@
+# Authors: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date : January 2009
+# Version 0.8
+# Licence GPL v3
+
+
+setMethod("Math", signature(x='RasterLayer'),
+ function(x){
+
+ fname <- as.character(sys.call(sys.parent())[[1]])
+
+ if (.CanProcessInMemory(x, 3)) {
+ raster <- setRaster(x, values=callGeneric(.getRasterValues(x)))
+ if (fname %in% c('floor', 'ceiling', 'trunc')) {
+ raster <- setDatatype(raster, 'INT4S')
+ }
+ } else {
+ raster <- setRaster(x, filename=tempfile())
+ if (fname %in% c('floor', 'ceiling', 'trunc')) {
+ raster <- setDatatype(raster, 'INT4S')
+ }
+ for (r in 1:nrow(x)) {
+ raster <- setValues(raster, callGeneric( .getRowValues(x, r) ), r)
+ raster <- writeRaster(raster)
+ }
+ if (options('verbose')[[1]]) {
+ cat('values were written to:', filename(raster))
+ }
+ }
+ return(raster)
+ }
+)
+
+
+setMethod("Math2", signature(x='RasterLayer'),
+ function (x, digits=0) {
+ digits <- max(0, digits)
+ if (.CanProcessInMemory(x, 1)) {
+ x <- setValues(x, callGeneric(values(x), digits))
+ if (digits == 0) {
+ x <- setDatatype(x, 'INT4S')
+ }
+ return(x)
+ } else {
+ raster <- setRaster(x, filename=tempfile())
+ if (digits == 0) {
+ x <- setDatatype(x, 'INT4S')
+ }
+ for (r in 1:nrow(x)) {
+ raster <- setValues(raster, callGeneric(.getRowValues(x, r), digits), r)
+ raster <- writeRaster(raster)
+ }
+ return(raster)
+ }
+ }
+)
Modified: pkg/raster/R/aggregate.R
===================================================================
--- pkg/raster/R/aggregate.R 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/R/aggregate.R 2009-03-03 06:54:10 UTC (rev 304)
@@ -6,21 +6,26 @@
# Licence GPL v3
+setMethod('aggregate', signature(x='RasterLayer'),
-setMethod('aggregate', signature(x='RasterLayer'),
-function(x, fact=2, fun=mean, expand=TRUE, rm.NA=TRUE, filename="", overwrite=FALSE, filetype='raster', datatype='FLT4S', track=-1) {
+function(x, fact=2, fun=mean, expand=TRUE, na.rm=TRUE, filename=NULL, filetype='raster', datatype='FLT4S', overwrite=FALSE, track=-1) {
+
+ if (is.null(filename)) { filename <- "" }
+
if (length(fact)==1) {
- fact <- round(fact)
+ fact <- as.integer(round(fact))
if (fact < 2) { stop('fact should be > 1') }
xfact <- yfact <- fact
} else if (length(fact)==2) {
- xfact <- round(fact[1])
- yfact <- round(fact[2])
- if (xfact < 2) { stop('fact[1] should be > 1') }
- if (yfact < 2) { stop('fact[2] should be > 1') }
+ xfact <- as.integer(round(fact[[1]]))
+ yfact <- as.intger(round(fact[[2]]))
+ if (xfact < 2) { stop('fact[[1]] should be > 1') }
+ if (yfact < 2) { stop('fact[[2]] should be > 1') }
} else {
stop('length(fact) should be 1 or 2')
}
+ if (xfact > ncol(x)) {warning('aggregation factor is larger than the number of columns') }
+ if (yfact > nrow(x)) {warning('aggregation factor is larger than the number of rows')}
if (expand) {
rsteps <- as.integer(ceiling(nrow(x)/yfact))
@@ -44,19 +49,23 @@
rows <- rep(1:rsteps, each=ncol(x) * yfact)[1:ncell(x)]
cells <- cellFromRowCol(x, rows, cols)
- if (rm.NA) {
- outRaster <- setValues(outRaster, as.vector(tapply(values(x), cells, function(x){fun(na.omit(x))})))
+ if (na.rm) {
+ outRaster <- setValues(outRaster, as.vector( tapply(values(x), cells, function(x){fun(na.omit(x))})))
} else {
outRaster <- setValues(outRaster, as.vector(tapply(values(x), cells, fun)))
}
-
if (filename(outRaster) != "") {
- outRaster <- writeRaster(outRaster, overwrite=overwrite, filetype=filetype)
+ outRaster <- writeRaster(outRaster, overwrite=overwrite, filetype=filetype, datatype=datatype)
}
+
+ } else if ( dataSource(x) == 'disk') {
+ if (!.CanProcessInMemory(x, 1) && filename == '') {
+ filename <- tempfile()
+ outraster <- setFilename(outraster, filename )
+ if (options('verbose')[[1]]) { cat('values were written to:', filename(raster)) }
+ }
- } else if ( dataSource(x) == 'disk') {
starttime <- proc.time()
-
cols <- rep(rep(1:csteps,each=xfact)[1:ncol(x)], times=yfact)
rows <- rep(1, each=(ncol(x) * yfact))
v <- vector(length=0)
@@ -74,15 +83,18 @@
x <- readRows(x, startrow = startrow, nrows = nrows)
cells <- cellFromRowCol(x, theserows, cols)
- if (rm.NA) { vals <- tapply(values(x), cells, function(x){fun(na.omit(x))} )
- } else { vals <- tapply(values(x), cells, fun) }
+ if (na.rm) {
+ vals <- tapply(values(x), cells, function(x){fun(na.omit(x))} )
+ } else {
+ vals <- tapply(values(x), cells, fun)
+ }
vals <- as.vector(vals)
if (filename(outRaster) == "") {
v <- c(v, vals)
} else {
outRaster <- setValues(outRaster, vals, r)
- outRaster <- writeRaster(outRaster, overwrite=overwrite, filetype=filetype)
+ outRaster <- writeRaster(outRaster, overwrite=overwrite, filetype=filetype, datatype=datatype)
}
if (r %in% track) {
@@ -100,3 +112,4 @@
}
)
+
Modified: pkg/raster/R/bounding.box.R
===================================================================
--- pkg/raster/R/bounding.box.R 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/R/bounding.box.R 2009-03-03 06:54:10 UTC (rev 304)
@@ -43,61 +43,3 @@
}
)
-
-if (!isGeneric("getBbox")) {
- setGeneric("getBbox", function(object)
- standardGeneric("getBbox"))
-}
-
-setMethod('getBbox', signature(object='BoundingBox'),
- function(object){ return(object) }
-)
-
-setMethod('getBbox', signature(object='BasicRaster'),
- function(object){ return(object at bbox) }
-)
-
-setMethod('getBbox', signature(object='Spatial'),
- function(object){
- bndbox <- bbox(object)
- bb <- new('BoundingBox')
- bb at xmin <- bndbox[1,1]
- bb at xmax <- bndbox[1,2]
- bb at ymin <- bndbox[2,1]
- bb at ymax <- bndbox[2,2]
- return(bb)
- }
-)
-
-setMethod('getBbox', signature(object='matrix'),
- function(object){
- bb <- new('BoundingBox')
- bb at xmin <- object[1,1]
- bb at xmax <- object[1,2]
- bb at ymin <- object[2,1]
- bb at ymax <- object[2,2]
- }
-)
-
-setMethod('getBbox', signature(object='vector'),
- function(object){
- if (length(object) < 4) {
- stop('vector supplied is too short')
- }
- if (length(object) > 4) {
- warning('vector supplied is longer then expected (should be 4)')
- }
- bb <- new('BoundingBox')
- bb at xmin <- object[1]
- bb at xmax <- object[2]
- bb at ymin <- object[3]
- bb at ymax <- object[4]
- return(bb)
- }
-)
-
-
-
-
-
-
Added: pkg/raster/R/getBbox.R
===================================================================
--- pkg/raster/R/getBbox.R (rev 0)
+++ pkg/raster/R/getBbox.R 2009-03-03 06:54:10 UTC (rev 304)
@@ -0,0 +1,80 @@
+# R function for the raster package
+# Author: Robert J. Hijmans
+# International Rice Research Institute. Philippines
+# contact: r.hijmans at gmail.com
+# Date : January 2009
+# Version 0.8
+# Licence GPL v3
+
+
+
+.bboxmatrix <- function(x) {
+ xy <- matrix(NA, nrow=5, ncol=2)
+ xy[1,1] <- x at xmin
+ xy[1,2] <- x at ymax
+ xy[2,1] <- x at xmax
+ xy[2,2] <- x at ymax
+ xy[3,1] <- x at xmax
+ xy[3,2] <- x at ymin
+ xy[4,1] <- x at xmin
+ xy[4,2] <- x at ymin
+ return(xy)
+}
+
+
+
+if (!isGeneric("getBbox")) {
+ setGeneric("getBbox", function(x)
+ standardGeneric("getBbox"))
+}
+
+setMethod('getBbox', signature(x='BoundingBox'),
+ function(x){ return(x) }
+)
+
+setMethod('getBbox', signature(x='BasicRaster'),
+ function(x){ return(x at bbox) }
+)
+
+setMethod('getBbox', signature(x='Spatial'),
+ function(x){
+ bndbox <- bbox(x)
+ bb <- new('BoundingBox')
+ bb at xmin <- bndbox[1,1]
+ bb at xmax <- bndbox[1,2]
+ bb at ymin <- bndbox[2,1]
+ bb at ymax <- bndbox[2,2]
+ return(bb)
+ }
+)
+
+setMethod('getBbox', signature(x='matrix'),
+ function(x){
+ if (min(dim(x)) < 2) {
+ stop('matrix should have dimensions of at least 2 by 2') }
+ bb <- new('BoundingBox')
+ bb at xmin <- x[1,1]
+ bb at xmax <- x[1,2]
+ bb at ymin <- x[2,1]
+ bb at ymax <- x[2,2]
+ return(bb)
+ }
+)
+
+setMethod('getBbox', signature(x='vector'),
+ function(x){
+ if (length(x) < 4) {
+ stop('vector supplied is too short')
+ }
+ if (length(x) > 4) {
+ warning('vector supplied is longer then expected (should be 4)')
+ }
+ bb <- new('BoundingBox')
+ bb at xmin <- x[1]
+ bb at xmax <- x[2]
+ bb at ymin <- x[3]
+ bb at ymax <- x[4]
+ return(bb)
+ }
+)
+
Modified: pkg/raster/R/group.generic.functions.R
===================================================================
--- pkg/raster/R/group.generic.functions.R 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/R/group.generic.functions.R 2009-03-03 06:54:10 UTC (rev 304)
@@ -5,6 +5,7 @@
# Licence GPL v3
+# helper functions for group generic functions
.getRasterValues <- function(x) {
# need to take care of 'spase'
@@ -48,82 +49,3 @@
-
-setMethod("Math", signature(x='RasterLayer'),
- function(x){
- if (.CanProcessInMemory(x, 3)) {
- raster <- setRaster(x, values=callGeneric(.getRasterValues(x)))
- } else {
- raster <- setRaster(x, filename=tempfile())
- for (r in 1:nrow(x)) {
- raster <- setValues(raster, callGeneric( .getRowValues(x, r) ), r)
- raster <- writeRaster(raster)
- }
- if (options('verbose')[[1]]) {
- cat('values were written to:', filename(raster))
- }
- }
- return(raster)
- }
-)
-
-
-
-
-setMethod("Arith", signature(e1='RasterLayer', e2='RasterLayer'),
- function(e1, e2){
- if ( compare(c(e1, e2)) ) {
- if (.CanProcessInMemory(e1, 4)) {
- raster <- setRaster(e1, values=callGeneric( as.numeric(.getRasterValues(e1)), .getRasterValues(e2)))
- } else {
- raster <- setRaster(e1, filename=tempfile())
- for (r in 1:nrow(e1)) {
- raster <- setValues(raster, callGeneric( as.numeric(.getRowValues(e1, r)), .getRowValues(e2, r) ), r)
- raster <- writeRaster(raster)
- }
- if (options('verbose')[[1]]) {
- cat('values were written to:', filename(raster))
- }
- }
- return(raster)
- }
- }
-)
-
-
-setMethod("Arith", signature(e1='RasterLayer', e2='numeric'),
- function(e1, e2){
- if (.CanProcessInMemory(e1, 3)) {
- return(setRaster(e1, values=callGeneric(as.numeric(.getRasterValues(e1)), e2) ) )
- } else {
- raster <- setRaster(e1, filename=tempfile())
- for (r in 1:nrow(e1)) {
- raster <- setValues(raster, callGeneric( as.numeric(.getRowValues(e1, r)), e2) , r)
- raster <- writeRaster(raster)
- }
- if (options('verbose')[[1]]) {
- cat('values were written to:', filename(raster))
- }
- return(raster)
- }
- }
-)
-
-setMethod("Arith", signature(e1='numeric', e2='RasterLayer'),
- function(e1, e2){
- if (.CanProcessInMemory(e2, 3)) {
- return(setRaster(e2, values=callGeneric(as.numeric(e1), .getRasterValues(e2))))
- } else {
- raster <- setRaster(e2, filename=tempfile())
- for (r in 1:nrow(e2)) {
- raster <- setValues(raster, callGeneric(as.numeric(e1), .getRowValues(e2, r)) , r)
- raster <- writeRaster(raster)
- }
- if (options('verbose')[[1]]) {
- cat('values were written to:', filename(raster))
- }
- return(raster)
- }
- }
-)
-
Modified: pkg/raster/R/mCalc.R
===================================================================
--- pkg/raster/R/mCalc.R 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/R/mCalc.R 2009-03-03 06:54:10 UTC (rev 304)
@@ -5,9 +5,7 @@
# Licence GPL v3
-mCalc <- function(...) {
- stop('mCalc has been replaced by generic function "calc"')
-}
+#mCalc <- function(...) { stop('mCalc has been replaced by generic function "calc"')}
setMethod('calc', signature(x='RasterStack', fun='function'),
function(x, fun, filename="", overwrite=FALSE, filetype='raster', datatype='FLT4S', track=-1) {
Modified: pkg/raster/R/plot.R
===================================================================
--- pkg/raster/R/plot.R 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/R/plot.R 2009-03-03 06:54:10 UTC (rev 304)
@@ -4,7 +4,46 @@
# Version 0,8
# Licence GPL v3
+.bboxmatrix <- function(x) {
+ xy <- matrix(NA, nrow=5, ncol=2)
+ xy[1,1] <- x at xmin
+ xy[1,2] <- x at ymax
+ xy[2,1] <- x at xmax
+ xy[2,2] <- x at ymax
+ xy[3,1] <- x at xmax
+ xy[3,2] <- x at ymin
+ xy[4,1] <- x at xmin
+ xy[4,2] <- x at ymin
+ return(xy)
+}
+
+setMethod("plot", signature(x='BoundingBox', y='ANY'),
+ function(x, y, ...) {
+ xy <- .bboxmatrix(x)
+ xy[5,] <- xy[1,]
+ plot(xy, type='l', ...)
+ if (class(y) == 'BoundingBox') {
+ lines(y)
+ }
+ }
+)
+
+
+if (!isGeneric("lines")) {
+ setGeneric("lines", function(x, ...)
+ standardGeneric("lines"))
+}
+
+setMethod("lines", signature(x='BoundingBox'),
+ function(x, ...) {
+ xy <- .bboxmatrix(x)
+ xy[5,] <- xy[1,]
+ lines(xy, ...)
+ }
+)
+
+
setMethod("plot", signature(x='Raster', y='missing'),
function(x, y, ...) {
map(x, ...)
Modified: pkg/raster/R/raster.create.R
===================================================================
--- pkg/raster/R/raster.create.R 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/R/raster.create.R 2009-03-03 06:54:10 UTC (rev 304)
@@ -17,10 +17,9 @@
}
-newRaster <- function(xmn=-180, xmx=180, ymn=-90, ymx=90, nrows=180, ncols=360, projstring="+proj=longlat +datum=WGS84") {
- warning("'newRaster' is deprecated. Use 'raster' instead")
- return(raster(xmn, xmx, ymn, ymx, nrows, ncols, projstring))
-}
+#newRaster <- function(xmn=-180, xmx=180, ymn=-90, ymx=90, nrows=180, ncols=360, projstring="+proj=longlat +datum=WGS84") {
+# warning("'newRaster' is deprecated. Use 'raster' instead")
+# return(raster(xmn, xmx, ymn, ymx, nrows, ncols, projstring)) }
raster <- function(xmn=-180, xmx=180, ymn=-90, ymx=90, nrows=180, ncols=360, projstring="+proj=longlat +datum=WGS84") {
Deleted: pkg/raster/R/round.R
===================================================================
--- pkg/raster/R/round.R 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/R/round.R 2009-03-03 06:54:10 UTC (rev 304)
@@ -1,89 +0,0 @@
-# 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) {
- digits <- max(0, digits)
- if (.CanProcessInMemory(x, 1)) {
- x <- setValues(x, round(values(x), digits))
- if (digits == 0) {
- x <- setDatatype(x, 'INT4S')
- }
- return(x)
- } else {
- raster <- setRaster(x, filename=tempfile())
- if (digits == 0) {
- x <- setDatatype(x, 'INT4S')
- }
- 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)) {
- x <- setValues(x, trunc(values(x)))
- x <- setDatatype(x, 'INT4S')
- return(x)
- } else {
- raster <- setRaster(x, filename=tempfile())
- raster <- setDatatype(raster, 'INT4S')
- 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)) {
- x <- setValues(x, ceiling(values(x)))
- x <- setDatatype(x, 'INT4S')
- return(x)
- } else {
- raster <- setRaster(x, filename=tempfile())
- raster <- setDatatype(raster, 'INT4S')
- 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)) {
- x <- setValues(x, floor(values(x)))
- x <- setDatatype(x, 'INT4S')
- return(x)
- } else {
- raster <- setRaster(x, filename=tempfile())
- raster <- setDatatype(raster, 'INT4S')
- for (r in 1:nrow(x)) {
- raster <- setValues(raster, floor(.getRowValues(x, r)), r)
- raster <- writeRaster(raster)
- }
- return(raster)
- }
- }
-)
-
Modified: pkg/raster/R/write.R
===================================================================
--- pkg/raster/R/write.R 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/R/write.R 2009-03-03 06:54:10 UTC (rev 304)
@@ -8,7 +8,7 @@
-rasterWriteFormats <- function() {
+writeFormats <- function() {
gd <- gdalDrivers()
gd <- as.matrix(subset(gd, gd[,3] == T))
short <- c("raster", "ascii", as.vector(gd[,1]))
@@ -23,7 +23,7 @@
gd <- gdalDrivers()
gd <- as.matrix(subset(gd, gd[,3] == T))
res <- dname %in% gd
- if (!res) { stop(paste(dname, "is not a supported file format. See rasterWriteFormats()" ) ) }
+ if (!res) { stop(paste(dname, "is not a supported file format. See writeFormats()" ) ) }
return(res)
}
Modified: pkg/raster/man/Arith-methods.Rd
===================================================================
--- pkg/raster/man/Arith-methods.Rd 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/man/Arith-methods.Rd 2009-03-03 06:54:10 UTC (rev 304)
@@ -1,23 +1,36 @@
\name{Arith-methods}
+
\docType{methods}
+
\alias{Arith-methods}
\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
+ Standard arithmic functions, \code{"+", "-", "*", "/", "^", "\%\%", "\%/\%"}, for computations with RasterLayer objects and numeric values.
+ Functions are applied on a cell by cell basis (single numeric values are recycled).
+ Input RasterLayers must have the same extent and resolution.
}
+
\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.
+ If the values of the output RasterLayer cannot be held in memory, they will be saved to a temporary file.
+ If you want to set the filename (and perhaps filetype and datatype), use \code{\link[raster]{overlay-methods}} or \code{\link[raster]{calc-methods}} instead of the Arith-methods.
}
+
+\seealso{ \code{\link[raster]{Math-methods}}, \code{\link[raster]{overlay-methods}}, \code{\link[raster]{calc-methods}} }
+
+
\author{Robert J. Hijmans}
\examples{
r1 <- raster(ncols=10, nrows=10)
-r1 <- setValues(r1, runif(ncell(r1)))
+r1[] <- runif(ncell(r1))
r2 <- setValues(r1, 1:ncell(r1) / ncell(r1) )
+r3 <- r1 + r2
+r2 <- r1 / 10
r3 <- r1 * (r2 - 1 + r1^2 / r2)
}
Added: pkg/raster/man/BoundingBox-class.Rd
===================================================================
--- pkg/raster/man/BoundingBox-class.Rd (rev 0)
+++ pkg/raster/man/BoundingBox-class.Rd 2009-03-03 06:54:10 UTC (rev 304)
@@ -0,0 +1,33 @@
+\name{BoundingBox-class}
+\docType{class}
+\alias{BoundingBox-class}
+\alias{show,BoundingBox-method}
+
+\title{Class "BoundingBox" }
+\description{ The BoundingBox class described the geographic extremes of a Raster* object}
+\section{Objects from the Class}{
+Objects can be created by calls of the form \code{new("BoundingBox", ...)}.
+}
+\section{Slots}{
+ \describe{
+ \item{\code{xmin}:}{minumum x coordinate}
+ \item{\code{xmax}:}{maximum x coordinate}
+ \item{\code{ymin}:}{minumum y coordinate}
+ \item{\code{ymax}:}{maximum y coordinate}
+ }
+}
+\section{Methods}{
+ \describe{
+ \item{show}{\code{signature(object = "BoundingBox")}: display values of a BoundingBox object }
+ }
+}
+\author{ Robert J. Hijmans}
+
+
+\seealso{ \code{\link[raster]{getBoundingBox}}, \code{\link[raster]{setBoundingBox}} }
+
+\examples{
+showClass("BoundingBox")
+}
+\keyword{classes}
+\keyword{spatial}
Modified: pkg/raster/man/Math-methods.Rd
===================================================================
--- pkg/raster/man/Math-methods.Rd 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/man/Math-methods.Rd 2009-03-03 06:54:10 UTC (rev 304)
@@ -5,13 +5,17 @@
\title{ Mathematical function for RasterLayer objects }
\description{
- The following standard mathematical functions can be used for computation with a single RasterLayer object
- "abs", "sign", "sqrt", "ceiling", "floor", "trunc", "cummax", "cummin", "cumprod", "cumsum", "log", "log10", "log2", "log1p", "acos", "acosh", "asin", "asinh", "atan", "atanh", "exp", "expm1", "cos", "cosh", "sin", "sinh", "tan", "tanh", "gamma", "lgamma", "digamma", "trigamma"
+ Standard mathematical functions that can be used with a RasterLayer object as argument:
+ \code{"abs", "sign", "sqrt", "ceiling", "floor", "trunc", "log", "log10", "log2", "log1p", "acos", "acosh", "asin", "asinh", "atan", "atanh", "exp", "expm1", "cos", "cosh", "sin", "sinh", "tan", "tanh"}.
}
\section{Note}{
- The RasterLayer object must have either all data in memory or on disk. If the data do not into memory you should use the calc() function instead.
+ If the values of the output RasterLayer cannot be held in memory, they will be saved to a temporary file.
+ If you want to set the filename (and perhaps filetype and datatype), use \code{\link[raster]{calc-methods}} instead of the Math-methods.
}
+\seealso{ \code{\link[raster]{Arith-methods}}, \code{\link[raster]{overlay-methods}}, \code{\link[raster]{calc-methods}} }
+
+
\author{Robert J. Hijmans}
\examples{
Modified: pkg/raster/man/aggregate-methods.Rd
===================================================================
--- pkg/raster/man/aggregate-methods.Rd 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/man/aggregate-methods.Rd 2009-03-03 06:54:10 UTC (rev 304)
@@ -2,50 +2,65 @@
\docType{methods}
\alias{aggregate}
\alias{aggregate,RasterLayer-method}
-\title{ Aggregate a RasterLayer }
+\title{Aggregate}
-\description{Aggregate a RasterLayer to create a new raster with a lower resolution.
- \code{aggregate} is a generic function described in the package `stats'.}
+\description{
+Aggregate a RasterLayer to create a new raster with a lower resolution (larger cells). Aggregation groups rectangular areas of RasterLayer cells to create a new RaterLayer with larger cells.
+A new value is computed for the resulting cells according to a user specified function (default value = \code{mean}).
+}
\section{Methods}{
\describe{
-\code{aggregate(x, fact = 2, fun = mean, expand = TRUE, rm.NA = TRUE, filename="", overwrite=FALSE, filetype='raster', datatype='FLT4S') }
-
-
-\item{x}{ a RasterLayer object}
- \item{fun}{function used to aggregate values. It should return one number. E.g. mean or max}
- \item{fact}{degree of aggregation or disaggregation expressed as number of cells (horizontally and vertically). See details}
- \item{expand}{if \code{expand == TRUE} grids will get larger if \code{factor} if the number of the division of the columns or rows with factor does not return an integer}
- \item{rm.NA}{if \code{rm.NA == TRUE}, remove NA cells from calculations}
- \item{filename}{output filename}
- \item{overwrite}{logical. If \code{TRUE}, "filename" will be overwritten if it exists}
- \item{filetype}{output file type. Either 'raster', 'ascii' or a supported GDAL 'driver' name see \code{\link[raster]{writeRaster}}}
- \item{datatype}{output data type; see \code{\link[raster]{setDatatype}}}
- \item{track}{vector of row numbers for which the function will report that they have been processed}
+\code{aggregate(x, fact=2, fun=mean, expand=TRUE, na.rm=TRUE, filename=NULL, filetype='raster', datatype='FLT4S', overwrite=FALSE, track=-1) }
+
+ \item{\code{x}}{a RasterLayer object}
+ \item{\code{fun}}{function used to aggregate values}
+ \item{\code{fact}}{integer. Aggregation factor expressed as number of cells in each direction (horizontally and vertically). Or two integers (horizontal and vertial aggregation fcator). See details}
+ \item{\code{expand}}{logical. If \code{TRUE} the output RasterLayer will get larger if a division of the number of columns or rows with \code{factor} does not return an integer}
+ \item{\code{na.rm}}{logical. If \code{TRUE}, remove NA cells from calculations}
+ \item{\code{filename}}{character. output filename}
+ \item{\code{overwrite}}{logical. If \code{TRUE}, "filename" will be overwritten if it exists}
+ \item{\code{filetype}}{character. output file type. Either 'raster', 'ascii' or a supported GDAL 'driver' name see \code{\link[raster]{rasterFormats}}}
+ \item{\code{datatype}}{character. output data type; see \code{\link[raster]{setDatatype}}}
+ \item{\code{track}}{vector of row numbers for which the function will report that they have been processed}
}
}
\details{
- In aggregation \code{fact = 2} will result in a grid with 2 x 2 = 4 times fewer cells.
+ Aggregation will result in a RasterLayer with \code{fact*fact} fewer cells; sometimes adjusted according to the values of \code{expand}.
+ For example, \code{fact=2} will result in a new RasterLayer with \code{2*2=4} times fewer cells.
+ If two numbers are supplied, e.g., \code{fact=c(2,3)}, the first will be used for aggregating in the horizontal direction,
+ and the second for aggregating in the vertical direction, and the new RasterLayer will have \code{2*3=6} times fewer cells.
+
+ If the input RasterLayer has 100 columns, and \code{fact=12}, the output RasterLayer will have either 8 columns (\code{expand=FALSE}) or
+ 9 columns (\code{expand=TRUE}). The maximum x coordinate of the output RasterLayer will, of course, also be affected.
+
+ Aggregation starts at the upper-left end of a raster.
+
+ The function \code{fun} should take multiple numbers, and return a single number. For example \code{mean}, \code{min} or \code{max}.
+
+ If no filename is specified, and the resulting RasterLayer is too large to hold in memory, it is saved to a temporary 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}
+
+\seealso{ \code{\link[raster]{disaggregate}} }
+
+\author{Robert J. Hijmans and Jacob van Etten}
+
\examples{
r <- raster()
+# a new aggregated raster, no values
+ra <- aggregate(r, fact=10)
r <- setValues(r, runif(ncell(r)))
ra <- aggregate(r, fact=10, fun=max)
+# a new aggregated raster, max of the values
}
-
\keyword{methods}
\keyword{spatial}
-
-
-
-
-
Deleted: pkg/raster/man/bbox.Rd
===================================================================
--- pkg/raster/man/bbox.Rd 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/man/bbox.Rd 2009-03-03 06:54:10 UTC (rev 304)
@@ -1,74 +0,0 @@
-\name{BoundingBox}
-\alias{getBbox}
-\alias{getBbox,BoundingBox-method}
-\alias{getBbox,BasicRaster-method}
-\alias{getBbox,Spatial-method}
-\alias{getBbox,matrix-method}
-\alias{getBbox,vector-method}
-\alias{bbox,Raster-method}
-
-\alias{newBbox}
-\alias{setBbox}
-\alias{changeBbox}
-\alias{unionBbox}
-\alias{intersectBbox}
-\alias{alignBbox}
-
-\alias{xmin<-}
-\alias{xmax<-}
-\alias{ymin<-}
-\alias{ymax<-}
-
-\title{Bounding box functions}
-\description{
-getBbox extracts a bounding box from a Raster* or Spatial* object (or from a BoundingBox object). It will also create a BoundingBox object from a matrix (2 x 2) or vector (length=4)
-newBbox creates a new bounding box (as in the "Spatial" object from the SP package)
-setBbox sets the bounding box of a Raster* object
-changeBbox changes the bounding box of a Raster* object
-alignBbox aligns a bounding box with the cells of a Raster* object
-unionBbox returns the union of multiple bounding boxes
-intersectBbox returns the instersection of multiple bounding boxes
-}
-
-\usage{
-newBbox(xmn, xmx, ymn, ymx)
-getBbox(object)
-setBbox(object, bndbox, keepres=FALSE, snap=FALSE)
-changeBbox(object, xmn=xmin(object), xmx=xmax(object), ymn=ymin(object), ymx = ymax(object), keepres=FALSE)
-alignBbox(bndbox, object)
-unionBbox(x, ...)
-intersectBbox(x, ...)
-}
-
-\arguments{
- \item{xmn}{the minimum x coordinate of the bounding box}
- \item{xmx}{the maximum x coordinate of the bounding box}
- \item{ymn}{the minimum y coordinate of the bounding box}
- \item{ymx}{the maximum y coordinate of the bounding box}
- \item{object}{A Raster* object}
- \item{bndbox}{An object of class BoundingBox (which you can create with newBbox() )}
- \item{keepres}{logical. If \code{TRUE}, the resolution of the cells will stay the same after adjusting the bounding box (by adjusting the number of rows and columns). if \code{FALSE}, the number of rows and columns will stay the same, and the resolution will be adjusted}
- \item{snap}{Adjust the bounding box so that the new raster is aligned with the old raster }
- \item{x}{A BoundingBox or Raster* object }
- \item{...}{ additional BoundingBox or Raster* objects }
-}
-
-\value{
-in most cases a BoundingBox object
-}
-
-\author{Robert J. Hijmans}
-
-\seealso{ \code{\link[raster]{clickBbox}} }
-
-\examples{
-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)
-# change BoundingBox coordinates one by one
-xmin(r) <- -30
-ymax(r) <- 60
-}
-
-\keyword{spatial}
Modified: pkg/raster/man/calc-methods.Rd
===================================================================
--- pkg/raster/man/calc-methods.Rd 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/man/calc-methods.Rd 2009-03-03 06:54:10 UTC (rev 304)
@@ -46,6 +46,11 @@
\value{
a new RasterLayer
}
+
+
+\seealso{ \code{\link[raster]{Math-methods}} }
+
+
\author{ Robert J. Hijmans}
\examples{
Modified: pkg/raster/man/classes.Rd
===================================================================
--- pkg/raster/man/classes.Rd 2009-02-28 09:26:26 UTC (rev 303)
+++ pkg/raster/man/classes.Rd 2009-03-03 06:54:10 UTC (rev 304)
@@ -2,19 +2,15 @@
\docType{class}
-\alias{BoundingBox-class}
\alias{BasicRaster-class}
\alias{Raster-class}
\alias{RasterLayer-class}
\alias{RasterStack-class}
-\alias{show,BoundingBox-method}
\alias{show,BasicRaster-method}
\alias{show,RasterLayer-method}
\alias{show,RasterStack-method}
\alias{show,RasterLayerSummary-method}
\alias{hist,Raster-method}
-\alias{plot,Raster,missing-method}
-\alias{plot,Raster,numeric-method}
\alias{dim,BasicRaster-method}
\alias{summary,RasterLayer-method}
\alias{summary,RasterStack-method}
@@ -40,8 +36,6 @@
generic methods implemented for these classes are:
\code{summary}, \code{show}, \code{dim}, \code{hist}, \code{plot} (with a single object as argument, and in the case of hist and plot, with additional ... parameters)
- \code{plot} can also be supplied with an additional numeric argument indicating the layer in a RasterStack object that should be plotted (mapped)
- \code{plot} can also be supplied with the two RasterLayer objects, creating a scatter plot (if they have matching extent and resolution)
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/raster -r 304
More information about the Raster-commits
mailing list