[Raster-commits] r315 - in pkg/raster: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Mar 5 15:29:05 CET 2009
Author: rhijmans
Date: 2009-03-05 15:29:04 +0100 (Thu, 05 Mar 2009)
New Revision: 315
Added:
pkg/raster/R/cells.R
pkg/raster/R/setMinMax.R
Modified:
pkg/raster/NAMESPACE
pkg/raster/R/properties.R
pkg/raster/R/set.R
pkg/raster/R/standard.generic.functions.R
pkg/raster/man/set.Rd
pkg/raster/man/values.Rd
Log:
Modified: pkg/raster/NAMESPACE
===================================================================
--- pkg/raster/NAMESPACE 2009-03-05 12:23:25 UTC (rev 314)
+++ pkg/raster/NAMESPACE 2009-03-05 14:29:04 UTC (rev 315)
@@ -4,5 +4,5 @@
importFrom("utils", stack)
importFrom("sp", overlay, bbox, Spatial, SpatialPixels, SpatialPixelsDataFrame, SpatialGrid, SpatialGridDataFrame)
exportClasses(BoundingBox, BasicRaster, Raster, RasterLayer, RasterStack)
-exportMethods(calc, overlay, bbox, aggregate, stack, show, summary, plot, hist, ncol, nrow, ncell, length, dim, lines, median)
+exportMethods(calc, overlay, bbox, aggregate, stack, show, summary, plot, hist, ncol, nrow, ncell, dim, lines, median)
exportPattern("^[^\\.]")
\ No newline at end of file
Added: pkg/raster/R/cells.R
===================================================================
--- pkg/raster/R/cells.R (rev 0)
+++ pkg/raster/R/cells.R 2009-03-05 14:29:04 UTC (rev 315)
@@ -0,0 +1,30 @@
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date : June 2008
+# Version 0.8
+# Licence GPL v3
+
+
+cells <- function(x, ...) {
+ funs <- list(...)
+ if (length(funs) == 0) {
+ return(NULL)
+ }
+ res <- list()
+ if (dataContent(x) != 'all') {
+ if (dataSource(x) == 'ram') {
+ stop('no values associated with this RasterLayer')
+ }
+ if (.CanProcessInMemory(x, 2)) {
+ x <- readAll(x)
+ }
+ }
+ if (dataContent(x) == 'all') {
+ for(i in seq(along=funs)) {
+ res[i] <- funs[[i]](x at data@values)
+ }
+ } else {
+ stop('sorry, only implemented for rasters that can be loaded into memory')
+ }
+}
+
Modified: pkg/raster/R/properties.R
===================================================================
--- pkg/raster/R/properties.R 2009-03-05 12:23:25 UTC (rev 314)
+++ pkg/raster/R/properties.R 2009-03-05 14:29:04 UTC (rev 315)
@@ -90,8 +90,11 @@
minValue <- function(object, layer=1) {
- if (layer < 1) { return(NA)
- } else return(object at data@min[layer])
+ if (layer < 1) {
+ return(NA)
+ } else {
+ return(object at data@min[layer])
+ }
}
Modified: pkg/raster/R/set.R
===================================================================
--- pkg/raster/R/set.R 2009-03-05 12:23:25 UTC (rev 314)
+++ pkg/raster/R/set.R 2009-03-05 14:29:04 UTC (rev 315)
@@ -106,41 +106,6 @@
return(bb)
}
-
-setMinMax <- function(raster, readfromdisk=FALSE) {
- if (dataContent(raster) != 'all' & dataContent(raster) != 'sparse') {
- if (readfromdisk) {
- raster at data@min <- 3e34
- raster at data@max <- -3e34
- for (r in 1:nrow(raster)) {
- raster <- readRow(raster, r)
- rsd <- na.omit(values(raster)) # min and max values
- if (length(rsd) > 0) {
- raster at data@min <- min(minValue(raster), min(rsd))
- raster at data@max <- max(maxValue(raster), max(rsd))
- }
- }
- raster <- clearValues(raster)
- } else {
- stop('no data in memory, and readfromdisk=FALSE')
- }
- } else {
- vals <- na.omit(values(raster)) # min and max values
- if (length(vals) > 0) {
- raster at data@min <- min(vals)
- raster at data@max <- max(vals)
- } else {
- raster at data@min <- NA
- raster at data@max <- NA
- }
- }
-# if (raster at file@datatype == 'logical') {
-# raster at data@min <- as.logical(raster at data@min)
-# raster at data@max <- as.logical(raster at data@max)
-# }
- raster at data@haveminmax <- TRUE
- return(raster)
-}
setNAvalue <- function(raster, value) {
raster at file@nodatavalue <- value
Added: pkg/raster/R/setMinMax.R
===================================================================
--- pkg/raster/R/setMinMax.R (rev 0)
+++ pkg/raster/R/setMinMax.R 2009-03-05 14:29:04 UTC (rev 315)
@@ -0,0 +1,51 @@
+
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date : June 2008
+# Version 0.8
+# Licence GPL v3
+
+
+setMinMax <- function(raster) {
+ clear <- FALSE
+ if (dataContent(raster) != 'all' & dataContent(raster) != 'sparse') {
+ if (dataSource(raster) == 'ram') {
+ stop('no values associated with this RasterLayer')
+ }
+ if (.CanProcessInMemory(raster, 2)) {
+ raster <- readAll(raster)
+ clear <- TRUE
+ }
+ }
+
+ if (dataContent(raster)=='all' | dataContent(raster)=='sparse') {
+ vals <- na.omit(values(raster)) # min and max values
+ if (clear) {raster <- clearValues(raster)}
+ if (length(vals) > 0) {
+ raster at data@min <- min(vals)
+ raster at data@max <- max(vals)
+ } else {
+ raster at data@min <- NA
+ raster at data@max <- NA
+ }
+ } else {
+ raster at data@min <- Inf
+ raster at data@max <- -Inf
+ for (r in 1:nrow(raster)) {
+ raster <- readRow(raster, r)
+ rsd <- na.omit(values(raster)) # min and max values
+ if (length(rsd) > 0) {
+ raster at data@min <- min(minValue(raster), min(rsd))
+ raster at data@max <- max(maxValue(raster), max(rsd))
+ }
+ }
+ raster <- clearValues(raster)
+ }
+# if (raster at file@datatype == 'logical') {
+# raster at data@min <- as.logical(raster at data@min)
+# raster at data@max <- as.logical(raster at data@max)
+# }
+ raster at data@haveminmax <- TRUE
+ return(raster)
+}
+
Modified: pkg/raster/R/standard.generic.functions.R
===================================================================
--- pkg/raster/R/standard.generic.functions.R 2009-03-05 12:23:25 UTC (rev 314)
+++ pkg/raster/R/standard.generic.functions.R 2009-03-05 14:29:04 UTC (rev 315)
@@ -1,7 +1,7 @@
# Author: Robert J. Hijmans, r.hijmans at gmail.com
# International Rice Research Institute
# Date : June 2008
-# Version 0,8
+# Version 0.8
# Licence GPL v3
@@ -18,6 +18,5 @@
)
-setMethod('length', signature(x='Raster'),
- function(x) { return(length(x at data@values)) }
-)
+#setMethod('length', signature(x='Raster'), function(x) { return(length(x at data@values)) )
+
Modified: pkg/raster/man/set.Rd
===================================================================
--- pkg/raster/man/set.Rd 2009-03-05 12:23:25 UTC (rev 314)
+++ pkg/raster/man/set.Rd 2009-03-05 14:29:04 UTC (rev 315)
@@ -23,7 +23,7 @@
setRaster(object, filename="", values=NULL)
setRowCol(raster, nrows=nrow(raster), ncols=ncol(raster))
setRes(object, xres, yres=xres)
-setMinMax(raster, readfromdisk=FALSE)
+setMinMax(raster)
setNAvalue(raster, value)
}
@@ -37,7 +37,6 @@
\item{xres}{ the new x resolution}
\item{yres}{ the new y resolution}
\item{projstring}{a character string describing a projection and datum in PROJ4 format }
- \item{readfromdisk}{Logical. If \code{TRUE} then data are read from disk (if available) to determine the min and max value}
\item{value}{the value to be interpreted as NA; set this before reading the values from the file. Integer values are matched exactely; for decimal values files any value <= the value will be interpreted as NA}
}
Modified: pkg/raster/man/values.Rd
===================================================================
--- pkg/raster/man/values.Rd 2009-03-05 12:23:25 UTC (rev 314)
+++ pkg/raster/man/values.Rd 2009-03-05 14:29:04 UTC (rev 315)
@@ -55,7 +55,7 @@
minValue(r)
maxValue(r)
-r1 <- setMinMax(r, TRUE)
+r1 <- setMinMax(r)
# now they are known:
minValue(r1)
maxValue(r1)
More information about the Raster-commits
mailing list