[Raster-commits] r117 - pkg/raster/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jan 12 01:45:05 CET 2009
Author: rhijmans
Date: 2009-01-12 01:45:05 +0100 (Mon, 12 Jan 2009)
New Revision: 117
Modified:
pkg/raster/R/all.classes.R
pkg/raster/R/values.R
Log:
Modified: pkg/raster/R/all.classes.R
===================================================================
--- pkg/raster/R/all.classes.R 2009-01-11 16:03:37 UTC (rev 116)
+++ pkg/raster/R/all.classes.R 2009-01-12 00:45:05 UTC (rev 117)
@@ -94,6 +94,7 @@
values='vector',
content='character', #nodata, all, row, block, sparse
indices = 'vector',
+ colnames = 'character',
haveminmax = 'logical',
min = 'vector',
max = 'vector',
@@ -103,6 +104,7 @@
values=vector(),
content='nodata',
indices = vector(mode='numeric'),
+ colnames = '',
haveminmax = FALSE,
min = numeric(0),
max = numeric(0),
@@ -133,14 +135,14 @@
values='matrix',
content='character', #nodata, all, row, block, sparse
indices = 'vector',
- varnames = 'character',
+ colnames = 'vector',
nlayers='integer'
),
prototype (
values=matrix(NA,0,0),
content='nodata',
indices =vector(mode='numeric'),
- varnames =vector(mode='character'),
+ colnames =vector(mode='character'),
nlayers=as.integer(0)
),
validity = function(object)
Modified: pkg/raster/R/values.R
===================================================================
--- pkg/raster/R/values.R 2009-01-11 16:03:37 UTC (rev 116)
+++ pkg/raster/R/values.R 2009-01-12 00:45:05 UTC (rev 117)
@@ -3,6 +3,8 @@
if (object at data@content=="nodata") {stop("first read some data (e.g., readAll()") }
if (format=='matrix') {
return(.values.as.matrix(object, names))
+ if (format=='dataframe') {
+ return(.values.as.dataframe(object))
} else {
return(object at data@values)
}
@@ -39,15 +41,25 @@
}
+.values.as.dataframe <- function(raster) {
+ m <- as.data.frame(values.as.matrix(raster, FALSE))
+ if raster at data@colnames != '' {
+ colnames(m) <- raster at data@colnames
+ } else {
+ colnames(m) <- seq(1:ncol(m))
+ }
+ rownames(m) <- seq(1:nrow(m))
+ return(m)
+}
.values.as.matrix <- function(raster, names=FALSE) {
if (dataContent(raster)=="nodata") {stop("first read some data (e.g., readAll() or readRow()") }
- if (is.matrix(raster at data@values)) {
- return(raster at data@values)
+ if (is.matrix(values(raster))) {
+ return(values(raster))
} else if (dataContent(raster)=="all") {
- mdata <- matrix(raster at data@values, nrow=nrow(raster), ncol=ncol(raster), byrow=TRUE)
+ mdata <- matrix(values(raster), nrow=nrow(raster), ncol=ncol(raster), byrow=TRUE)
if (names) {
colnames(mdata) <- seq(1:ncol(raster))
rownames(mdata) <- seq(1:nrow(raster))
@@ -65,7 +77,7 @@
return(mdata)
} else if (dataContent(raster)=="row") {
- mdata <- matrix(raster at data@values, nrow=1, ncol=ncol(raster), byrow=TRUE)
+ mdata <- matrix(values(raster), nrow=1, ncol=ncol(raster), byrow=TRUE)
if (names) {
colnames(mdata) <- seq(1:ncol(raster))
therow <- rowFromCell(raster, dataIndices(raster)[1])
More information about the Raster-commits
mailing list