[Raster-commits] r114 - in pkg/raster: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jan 11 15:26:44 CET 2009
Author: rhijmans
Date: 2009-01-11 15:26:44 +0100 (Sun, 11 Jan 2009)
New Revision: 114
Added:
pkg/raster/man/Arith-methods.Rd
pkg/raster/man/Compare-methods.Rd
pkg/raster/man/Logic-methods.Rd
pkg/raster/man/Math-methods.Rd
pkg/raster/man/Summary-methods.Rd
pkg/raster/man/classes.Rd
Removed:
pkg/raster/man/class.brick.Rd
pkg/raster/man/class.raster.Rd
pkg/raster/man/class.stack.Rd
Modified:
pkg/raster/DESCRIPTION
pkg/raster/NAMESPACE
pkg/raster/R/Merge.R
pkg/raster/R/all.classes.R
pkg/raster/R/conversion.R
pkg/raster/R/expand.R
pkg/raster/R/export.R
pkg/raster/R/map.R
pkg/raster/R/neighborhood.R
pkg/raster/R/properties.R
pkg/raster/R/raster.create.R
pkg/raster/R/raster.read.R
pkg/raster/R/raster.write.R
pkg/raster/R/set.R
pkg/raster/R/standard.generic.functions.R
pkg/raster/R/values.R
pkg/raster/man/export.Rd
pkg/raster/man/properties.Rd
pkg/raster/man/raster-package.Rd
Log:
Modified: pkg/raster/DESCRIPTION
===================================================================
--- pkg/raster/DESCRIPTION 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/DESCRIPTION 2009-01-11 14:26:44 UTC (rev 114)
@@ -2,7 +2,7 @@
Type: Package
Title: Raster data handling for geographic data analysis and modeling
Version: 0.8.4
-Date: 10-Jan-2009
+Date: 11-Jan-2009
Depends: methods, sp, rgdal (>= 0.5-33)
Author: Robert J. Hijmans & Jacob van Etten
Maintainer: Robert J. Hijmans <r.hijmans at gmail.com>
Modified: pkg/raster/NAMESPACE
===================================================================
--- pkg/raster/NAMESPACE 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/NAMESPACE 2009-01-11 14:26:44 UTC (rev 114)
@@ -1,6 +1,5 @@
-importFrom("methods", Ops, Arith, Compare, Logic, Math, Math2, Summary, Complex)
+importFrom("methods", Arith, Compare, Logic, Math)
importFrom("graphics", hist, plot)
-importClassesFrom("sp", Spatial)
-exportClasses(RasterLayer, RasterBrick, RasterStack)
+exportClasses(Raster, RasterLayer, RasterBrick, RasterStack)
exportMethods(show, summary, plot, hist, ncol, nrow)
exportPattern("^[^\\.]")
\ No newline at end of file
Modified: pkg/raster/R/Merge.R
===================================================================
--- pkg/raster/R/Merge.R 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/R/Merge.R 2009-01-11 14:26:44 UTC (rev 114)
@@ -14,10 +14,10 @@
bb <- getBbox(objects[[1]])
for (i in 2:length(objects)) {
bb2 <- getBbox(objects[[i]])
- bb at xmin <- min(bb at xmin, bb2 at xmin)
- bb at xmax <- max(bb at xmax, bb2 at xmax)
- bb at ymin <- min(bb at ymin, bb2 at ymin)
- bb at ymax <- max(bb at ymax, bb2 at ymax)
+ bb at xmin <- min(xmin(bb), xmin(bb2))
+ bb at xmax <- max(xmax(bb), xmax(bb2))
+ bb at ymin <- min(ymin(bb), ymin(bb2))
+ bb at ymax <- max(ymax(bb), ymax(bb2))
}
return(bb)
}
@@ -29,10 +29,10 @@
bb <- getBbox(objects[[1]])
for (i in 2:length(objects)) {
bb2 <- getBbox(objects[[i]])
- bb at xmin <- max(bb at xmin, bb2 at xmin)
- bb at xmax <- min(bb at xmax, bb2 at xmax)
- bb at ymin <- max(bb at ymin, bb2 at ymin)
- bb at ymax <- min(bb at ymax, bb2 at ymax)
+ bb at xmin <- max(xmin(bb), xmin(bb2))
+ bb at xmax <- min(xmax(bb), xmax(bb2))
+ bb at ymin <- max(ymin(bb), ymin(bb2))
+ bb at ymax <- min(ymax(bb), ymax(bb2))
}
validObject(bb)
return(bb)
Modified: pkg/raster/R/all.classes.R
===================================================================
--- pkg/raster/R/all.classes.R 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/R/all.classes.R 2009-01-11 14:26:44 UTC (rev 114)
@@ -29,7 +29,8 @@
)
-setClass ('AbstractRaster',
+setClass ('Raster',
+ contains = 'VIRTUAL',
representation (
bbox = 'BoundingBox',
ncols ='integer',
@@ -49,8 +50,8 @@
}
)
+
-
setClass('RasterFile',
representation (
name ='character',
@@ -114,7 +115,7 @@
setClass ('RasterLayer',
- contains = 'AbstractRaster',
+ contains = 'Raster',
representation (
title = 'character',
file = 'RasterFile',
@@ -126,39 +127,7 @@
)
)
-
-setMethod ('show' , 'RasterLayer',
- function(object) {
- cat('class :' , class(object), '\n')
- cat('filename :' , filename(object), '\n')
- if (object at file@nbands > 1) {
-# cat('nbands :' , object at file@nbands, '\n')
- cat('band :' , object at file@band, '\n')
- }
- cat('nrow :' , nrow(object), '\n')
- cat('ncol :' , ncol(object), '\n')
- cat('ncells :' , ncells(object), '\n')
- cat('data type :' , object at file@datanotation, '\n')
- cat('data content:' , dataContent(object), '\n')
- if (object at data@haveminmax) {
- cat('min value :' , minValue(object), '\n')
- cat('max value :' , maxValue(object), '\n')
- } else { #if (object at data@source == 'disk') {
- cat('min value : NA \n')
- cat('max value : NA \n')
- }
- cat('projection :' , projection(object, TRUE), '\n')
- cat('xmin :' , xmin(object), '\n')
- cat('xmax :' , xmax(object), '\n')
- cat('ymin :' , ymin(object), '\n')
- cat('ymax :' , ymax(object), '\n')
- cat('xres :' , xres(object), '\n')
- cat('yres :' , yres(object), '\n')
- cat ('\n')
- }
-)
-
setClass('MultipleRasterData',
representation (
values='matrix',
@@ -181,7 +150,7 @@
setClass ('RasterBrick',
- contains = 'AbstractRaster',
+ contains = 'Raster',
representation (
data = 'MultipleRasterData',
title = 'character',
@@ -200,29 +169,10 @@
-setMethod ('show' , 'RasterBrick',
- function ( object ){
- cat ('class :' , class ( object ) , '\n')
- cat ('filename :' , filename(object), '\n')
- cat ('nlayers :' , nlayers(object), '\n')
- cat ('nrow :' , nrow(object), '\n')
- cat ('ncol :' , ncol(object), '\n')
- cat ('ncells :' , ncells(object), '\n')
- cat ('projection:' , projection(object, TRUE), '\n')
- cat ('xmin :' , xmin(object), '\n')
- cat ('xmax :' , xmax(object), '\n')
- cat ('ymin :' , ymin(object), '\n')
- cat ('ymax :' , ymax(object), '\n')
- cat ('xres :' , xres(object) , '\n')
- cat ('yres :' , yres(object) , '\n')
- cat ('\n')
- }
-)
-
setClass ('RasterStack',
- contains = 'AbstractRaster',
+ contains = 'Raster',
representation (
filename ='character',
rasters ='list',
@@ -241,23 +191,3 @@
}
)
-
-setMethod ('show' , 'RasterStack',
- function ( object ){
- cat ('class :' , class ( object ) , '\n')
- cat ('filename :' , object at filename, '\n')
- cat ('nlayers :' , object at data@nlayers, '\n')
- cat ('nrow :' , nrow(object), '\n')
- cat ('ncol :' , ncol(object), '\n')
- cat ('ncells :' , ncells(object), '\n')
- cat ('projection:' , projection(object, TRUE), '\n')
- cat ('xmin :' , xmin(object), '\n')
- cat ('xmax :' , xmax(object), '\n')
- cat ('ymin :' , ymin(object), '\n')
- cat ('ymax :' , ymax(object), '\n')
- cat ('xres :' , xres(object) , '\n')
- cat ('yres :' , yres(object) , '\n')
- cat ('\n')
- }
-)
-
Modified: pkg/raster/R/conversion.R
===================================================================
--- pkg/raster/R/conversion.R 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/R/conversion.R 2009-01-11 14:26:44 UTC (rev 114)
@@ -96,23 +96,23 @@
-asSpGrid <- function(raster, type='grid') {
- bb <- .toSpBbox(raster)
- cs <- resolution(raster)
+asSpGrid <- function(object, type='grid') {
+ bb <- .toSpBbox(object)
+ cs <- resolution(object)
cc <- bb[,1] + (cs/2)
cd <- ceiling(diff(t(bb))/cs)
grd <- GridTopology(cellcentre.offset=cc, cellsize=cs, cells.dim=cd)
if (type=='pixel') {
- raster <- makeSparse(raster)
- pts <- SpatialPoints(xyFromCell(raster, dataIndices(raster)))
- sp <- SpatialPixelsDataFrame(points=pts, data=as.data.frame(values(raster)), proj4string=projection(raster, FALSE))
+ object <- makeSparse(object)
+ pts <- SpatialPoints(xyFromCell(object, dataIndices(object)))
+ sp <- SpatialPixelsDataFrame(points=pts, data=as.data.frame(values(object)), proj4string=projection(object, FALSE))
} else if (type=='grid') {
- if ( dataContent(raster) == 'all') {
- values <- as.data.frame(values(raster))
- sp <- SpatialGridDataFrame(grd, proj4string=projection(raster, FALSE), data=values)
+ if ( dataContent(object) == 'all') {
+ values <- as.data.frame(values(object))
+ sp <- SpatialGridDataFrame(grd, proj4string=projection(object, FALSE), data=values)
} else {
- sp <- SpatialGrid(grd, proj4string=projection(raster, FALSE))
+ sp <- SpatialGrid(grd, proj4string=projection(object, FALSE))
}
}
return(sp)
Modified: pkg/raster/R/expand.R
===================================================================
--- pkg/raster/R/expand.R 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/R/expand.R 2009-01-11 14:26:44 UTC (rev 114)
@@ -11,10 +11,10 @@
bndbox <- getBbox(bndbox)
res <- resolution(raster)
# snap points to pixel boundaries
- xmn <- round(bndbox at xmin / res[1]) * res[1]
- xmx <- round(bndbox at xmax / res[1]) * res[1]
- ymn <- round(bndbox at ymin / res[2]) * res[2]
- ymx <- round(bndbox at ymax / res[2]) * res[2]
+ xmn <- round(xmin(bndbox) / res[1]) * res[1]
+ xmx <- round(xmax(bndbox) / res[1]) * res[1]
+ ymn <- round(ymin(bndbox) / res[2]) * res[2]
+ ymx <- round(ymax(bndbox) / res[2]) * res[2]
# only expanding here, not cutting
xmn <- min(xmn, xmin(raster))
Modified: pkg/raster/R/export.R
===================================================================
--- pkg/raster/R/export.R 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/R/export.R 2009-01-11 14:26:44 UTC (rev 114)
@@ -1,7 +1,7 @@
import <- function(raster, filename="", overwrite=FALSE) {
# check extension
- if (raster at file@driver == "raster") {
+ if (.driver(raster) == "raster") {
stop("file is a raster format file, it cannot be imported")
}
filename <- trim(filename)
@@ -82,7 +82,7 @@
writeAscii <- function(raster, filename, overwrite=FALSE) {
- if (raster at data@indices[1] == 1) {
+ if (dataIndices(raster)[1] == 1) {
resdif <- abs((yres(raster) - xres(raster)) / yres(raster) )
if (resdif > 0.01) {
stop(paste("raster has unequal horizontal and vertical resolutions","\n", "these data cannot be stored in arc-ascii format"))
@@ -97,14 +97,15 @@
cat("XLLCORNER", xmin(raster), "\n", file = thefile)
cat("YLLCORNER", ymin(raster), "\n", file = thefile)
cat("CELLSIZE", xres(raster), "\n", file = thefile)
- cat("NODATA_value", raster at file@nodatavalue, "\n", file = thefile)
+ cat("NODATA_value", .nodatavalue(raster), "\n", file = thefile)
close(thefile) #close connection
} else if ( dataIndices(raster)[2] > ncells(raster)) {
- stop(paste('writing beyond end of file. last cell:', raster at data@indices[2], '>', ncells(raster)))
+ stop(paste('writing beyond end of file. last cell:', dataIndices(raster)[2], '>', ncells(raster)))
}
- raster at data@values[is.na(values(raster))] <- raster at file@nodatavalue
+
+ raster at data@values[is.na(values(raster))] <- .nodatavalue(raster)
if (dataContent(raster) == 'all') {
for (r in 1:nrow(raster)) {
write.table(t(valuesRow(raster, r)), filename, append = TRUE, quote = FALSE,
@@ -147,7 +148,7 @@
thefile <- file(hdrfile, "w") # open an txt file connectionis
cat("NROWS ", nrow(raster), "\n", file = thefile)
cat("NCOLS ", ncol(raster), "\n", file = thefile)
- cat("NBANDS ", raster at file@nbands, "\n", file = thefile)
+ cat("NBANDS ", nbands(raster), "\n", file = thefile)
cat("NBITS ", raster at file@datasize * 8, "\n", file = thefile)
if (.Platform$endian == "little") { btorder <- "I"
} else { btorder <- "M" }
@@ -166,9 +167,9 @@
cat("YDIM", yres(raster), "\n", file = thefile)
browbytes <- round(ncol(raster) * raster at file@datasize)
cat("BANDROWBYTES ", browbytes, "\n", file = thefile)
- cat("TOTALROWBYTES ", browbytes * raster at file@nbands, "\n", file = thefile)
+ cat("TOTALROWBYTES ", browbytes * nbands(raster), "\n", file = thefile)
cat("BANDGAPBYTES 0", "\n", file = thefile)
- cat("NODATA", raster at file@nodatavalue, "\n", file = thefile)
+ cat("NODATA", .nodatavalue(raster), "\n", file = thefile)
cat("\n\n", file = thefile)
cat("The below is additional metadata, not part of the BIL/HDR format\n", file = thefile)
@@ -192,7 +193,7 @@
cat("HEIGHT ", nrow(raster), "\n", file = thefile)
cat("WIDTH ", ncol(raster), "\n", file = thefile)
- cat("NUM_LAYERS ", raster at file@nbands, "\n", file = thefile)
+ cat("NUM_LAYERS ", nbands(raster), "\n", file = thefile)
if (raster at file@datatype == 'integer') { dd <- "S"
} else { dd <- "F" }
Modified: pkg/raster/R/map.R
===================================================================
--- pkg/raster/R/map.R 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/R/map.R 2009-01-11 14:26:44 UTC (rev 114)
@@ -12,13 +12,13 @@
if (class(object) == 'character') {
object <- rasterFromFile(object)
}
- if ( class(object) == 'RasterStack' ) {
+ if ( class(object) != 'RasterLayer' ) {
index <- round(index)
- i <- min(max(1, index), object at data@nlayers)
+ i <- min(max(1, index), nlayers(object))
if (i != index) { stop("index should be >= 1 and <=", nlayers(object), " =nlayers(stack)") }
raster2 <- object at rasters[[i]]
- if (object at data@content == 'all') {
- raster2 <- setValues(raster2, object at data@values[i,])
+ if (dataContent(object) == 'all') {
+ raster2 <- setValues(raster2, values(object)[i,])
}
object <- raster2
}
Modified: pkg/raster/R/neighborhood.R
===================================================================
--- pkg/raster/R/neighborhood.R 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/R/neighborhood.R 2009-01-11 14:26:44 UTC (rev 114)
@@ -52,7 +52,7 @@
if (ForceIntOutput) {setDatatype(ngbgrid, 'integer') }
# first create an empty matrix with nrows = ngb and ncols = raster at ncols
- ngbdata1 <- array(data = NA, dim = c(ngb, raster at ncols))
+ ngbdata1 <- array(data = NA, dim = c(ngb, ncol(raster)))
ngbdata <- ngbdata1
rr <- 1
Modified: pkg/raster/R/properties.R
===================================================================
--- pkg/raster/R/properties.R 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/R/properties.R 2009-01-11 14:26:44 UTC (rev 114)
@@ -6,6 +6,9 @@
filename <- function(object) {
+ if (class(object) == 'RasterStack') {
+ return(object at filename)
+ }
return(object at file@name)
}
@@ -134,3 +137,13 @@
return(object at data@source)
}
+.driver <- function(object) {
+ return(object at file@driver)
+}
+
+.nodatavalue <- function(object) {
+ if (class(object) == 'RasterStack') {
+ stop("no such thing exist for an entire 'RasterStack'")
+ }
+ return(object at file@nodatavalue)
+}
Modified: pkg/raster/R/raster.create.R
===================================================================
--- pkg/raster/R/raster.create.R 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/R/raster.create.R 2009-01-11 14:26:44 UTC (rev 114)
@@ -71,9 +71,9 @@
raster at file@nbands <- as.integer(gdalinfo[["bands"]])
band <- as.integer(band)
- if (band > raster at file@nbands) {
+ if (band > nbands(raster) ) {
warning("band too high. Set to nbands")
- band <- raster at file@nbands }
+ band <- nbands(raster) }
if ( band < 1) {
warning("band too low. Set to 1")
band <- 1 }
Modified: pkg/raster/R/raster.read.R
===================================================================
--- pkg/raster/R/raster.read.R 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/R/raster.read.R 2009-01-11 14:26:44 UTC (rev 114)
@@ -54,7 +54,7 @@
ncolumns <- ncol(raster) - startcol + 1
}
- if (raster at file@driver == 'raster') {
+ if (.driver(raster) == 'raster') {
rastergri <- .setFileExtensionValues(filename(raster))
if (!file.exists( filename(raster))) {
stop(paste(filename(raster)," does not exist"))
@@ -73,7 +73,7 @@
}
close(con)
result[is.nan(result)] <- NA
- result[result <= (0.999 * raster at file@nodatavalue) ] <- NA
+ result[result <= (0.999 * .nodatavalue(raster)) ] <- NA
}
else { #use GDAL
if (is.na(raster at file@band)) { result <- NA }
@@ -234,7 +234,7 @@
if (dataContent(raster) == 'all') {
vals <- cbind(uniquecells, values(raster)[uniquecells])
} else if (dataSource(raster) == 'disk') {
- if (raster at file@driver == 'gdal') {
+ if (.driver(raster) == 'gdal') {
vals <- .readCellsGDAL(raster, uniquecells)
} else {
vals <- .readCellsRaster(raster, uniquecells)
@@ -298,7 +298,7 @@
res[i] <- readBin(con, what=dtype, n=1, size=raster at file@datasize, endian=raster at file@byteorder)
}
close(con)
- res[res <= max(-3e+38, raster at file@nodatavalue)] <- NA
+ res[res <= max(-3e+38, .nodatavalue(raster))] <- NA
return(cbind(cells,res))
}
Modified: pkg/raster/R/raster.write.R
===================================================================
--- pkg/raster/R/raster.write.R 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/R/raster.write.R 2009-01-11 14:26:44 UTC (rev 114)
@@ -81,9 +81,9 @@
.writeRasterRow <- function(raster, overwrite=FALSE) {
- if (raster at data@content != 'row') { stop('raster does not contain a row') }
+ if (dataContent(raster) != 'row') { stop('raster does not contain a row') }
- if (raster at data@indices[1] == 1) {
+ if (dataIndices(raster)[1] == 1) {
# FIRST ROW
raster <- setFilename(raster, .setFileExtensionHeader(filename(raster)))
if (filename(raster) == "") {
@@ -116,7 +116,7 @@
# raster at data@values[is.na(raster at data@values)] <- raster at file@nodatavalue
writeBin(as.vector(raster at data@values), raster at filecon, size = raster at file@datasize)
- if (raster at data@indices[2] == ncells(raster)) {
+ if (dataIndices(raster)[2] == ncells(raster)) {
# LAST ROW
.writeRasterHdr(raster)
close(raster at filecon)
@@ -125,8 +125,8 @@
raster at data@content <- 'nodata'
raster at data@values <- vector(length=0)
}
- if (raster at data@indices[2] > ncells(raster)) {
- stop(paste('writing beyond end of file. last cell:', raster at data@indices[2], '>', ncells(raster)))
+ if (dataIndices(raster)[2] > ncells(raster)) {
+ stop(paste('writing beyond end of file. last cell:', dataIndices(raster)[2], '>', ncells(raster)))
}
return(raster)
}
@@ -192,11 +192,11 @@
cat("DataType=", datatype, "\n", file = thefile)
cat("ByteOrder=", .Platform$endian, "\n", file = thefile)
}
- cat("nbands=", raster at file@nbands, "\n", file = thefile)
+ cat("nbands=", nbands(raster), "\n", file = thefile)
cat("bandOrder=", raster at file@bandorder, "\n", file = thefile)
cat("minValue=", minValue(raster), "\n", file = thefile)
cat("maxValue=", maxValue(raster), "\n", file = thefile)
- cat("NoDataValue=", raster at file@nodatavalue, "\n", file = thefile)
+ cat("NoDataValue=", .nodatavalue(raster), "\n", file = thefile)
# cat("Sparse=", raster at sparse, "\n", file = thefile)
# cat("nCellvals=", raster at data@ncellvals, "\n", file = thefile)
close(thefile)
Modified: pkg/raster/R/set.R
===================================================================
--- pkg/raster/R/set.R 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/R/set.R 2009-01-11 14:26:44 UTC (rev 114)
@@ -247,7 +247,7 @@
}
setMinmax <- function(raster) {
- if (raster at data@content == 'nodata') {
+ if (dataContent(raster) == 'nodata') {
stop('no data in memory')
}
vals <- na.omit(values(raster)) # min and max values
Modified: pkg/raster/R/standard.generic.functions.R
===================================================================
--- pkg/raster/R/standard.generic.functions.R 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/R/standard.generic.functions.R 2009-01-11 14:26:44 UTC (rev 114)
@@ -5,16 +5,87 @@
# Licence GPL v3
+
+setMethod ('show' , 'RasterLayer',
+ function(object) {
+ cat('class :' , class(object), '\n')
+ cat('filename :' , filename(object), '\n')
+ if (nbands(object) > 1) {
+ cat('band :' , band(object), '\n')
+ }
+ cat('nrow :' , nrow(object), '\n')
+ cat('ncol :' , ncol(object), '\n')
+ cat('ncells :' , ncells(object), '\n')
+ cat('data type :' , object at file@datanotation, '\n')
+ cat('data content:' , dataContent(object), '\n')
+ if (object at data@haveminmax) {
+ cat('min value :' , minValue(object), '\n')
+ cat('max value :' , maxValue(object), '\n')
+ } else { #if (object at data@source == 'disk') {
+ cat('min value : NA \n')
+ cat('max value : NA \n')
+ }
+ cat('projection :' , projection(object, TRUE), '\n')
+ cat('xmin :' , xmin(object), '\n')
+ cat('xmax :' , xmax(object), '\n')
+ cat('ymin :' , ymin(object), '\n')
+ cat('ymax :' , ymax(object), '\n')
+ cat('xres :' , xres(object), '\n')
+ cat('yres :' , yres(object), '\n')
+ cat ('\n')
+ }
+)
-setMethod('==', signature(e1='AbstractRaster', e2='AbstractRaster'),
+setMethod ('show' , 'RasterBrick',
+ function ( object ){
+ cat ('class :' , class ( object ) , '\n')
+ cat ('filename :' , filename(object), '\n')
+ cat ('nlayers :' , nlayers(object), '\n')
+ cat ('nrow :' , nrow(object), '\n')
+ cat ('ncol :' , ncol(object), '\n')
+ cat ('ncells :' , ncells(object), '\n')
+ cat ('projection:' , projection(object, TRUE), '\n')
+ cat ('xmin :' , xmin(object), '\n')
+ cat ('xmax :' , xmax(object), '\n')
+ cat ('ymin :' , ymin(object), '\n')
+ cat ('ymax :' , ymax(object), '\n')
+ cat ('xres :' , xres(object) , '\n')
+ cat ('yres :' , yres(object) , '\n')
+ cat ('\n')
+ }
+)
+
+
+setMethod ('show' , 'RasterStack',
+ function ( object ){
+ cat ('class :' , class ( object ) , '\n')
+ cat ('filename :' , filename(object), '\n')
+ cat ('nlayers :' , nlayers(object), '\n')
+ cat ('nrow :' , nrow(object), '\n')
+ cat ('ncol :' , ncol(object), '\n')
+ cat ('ncells :' , ncells(object), '\n')
+ cat ('projection:' , projection(object, TRUE), '\n')
+ cat ('xmin :' , xmin(object), '\n')
+ cat ('xmax :' , xmax(object), '\n')
+ cat ('ymin :' , ymin(object), '\n')
+ cat ('ymax :' , ymax(object), '\n')
+ cat ('xres :' , xres(object) , '\n')
+ cat ('yres :' , yres(object) , '\n')
+ cat ('\n')
+ }
+)
+
+
+
+setMethod('==', signature(e1='Raster', e2='Raster'),
function(e1,e2){
cond <- compare(c(e1, e2), bb=TRUE, rowcol=TRUE, prj=TRUE, tolerance=0.0001, stopiffalse=FALSE)
return(cond)
}
)
-setMethod('!=', signature(e1='AbstractRaster', e2='AbstractRaster'),
+setMethod('!=', signature(e1='Raster', e2='Raster'),
function(e1,e2){
cond <- compare(c(e1, e2), bb=TRUE, rowcol=TRUE, prj=TRUE, tolerance=0.0001, stopiffalse=FALSE)
return(!cond)
@@ -22,7 +93,7 @@
)
-.getValues <- function(x) {
+.getRasterValues <- function(x) {
# need to take care of 'spase'
if (dataContent(x) != 'all') {
if (class(x) == "RasterLayer") {
@@ -37,15 +108,15 @@
}
.getLogicalValues <- function(x) {
- v <- .getValues(x)
+ v <- .getRasterValues(x)
v[v<0] <- 0
v[v>0] <- 1
return(v)
}
-.getTheValues <- function(x, y, i) {
+.getAllTypeOfValues <- function(x, y, i) {
if ( (class(y) == 'RasterLayer' | class(y) == 'RasterStack' | class(y) == 'RasterBrick') & compare(c(x, y)) ) {
- return(.getValues(y))
+ return(.getRasterValues(y))
} else if (is.atomic(y)) {
return(rep(y, ncells(x)))
} else if (length(y)==ncells(x)) {
@@ -57,7 +128,7 @@
setMethod("[", "RasterLayer",
function(x, i, j, ..., drop = TRUE) {
- if (!missing(drop)) { stop("don't supply drop: it needs to be FALSE anyway") }
+ if (!missing(drop)) { stop("drop is ignored. It is always set to FALSE") }
if (!missing(j)) { stop("can only set values with a single index (a vector)") }
if (missing(i)) { return(x) }
return(setRaster(x, values=i))
@@ -67,7 +138,7 @@
setMethod("Math", signature(x='RasterLayer'),
function(x){
- return(setRaster(x, values=callGeneric(.getValues(x))))
+ return(setRaster(x, values=callGeneric(.getRasterValues(x))))
}
)
@@ -82,66 +153,49 @@
setMethod("Arith", signature(e1='RasterLayer', e2='RasterLayer'),
function(e1, e2){
if (compare(c(e1, e2))) {
- return(setRaster(e1, values=callGeneric(.getValues(e1), .getValues(e2))))
+ return(setRaster(e1, values=callGeneric(.getRasterValues(e1), .getRasterValues(e2))))
}
}
)
setMethod("Arith", signature(e1='RasterLayer', e2='numeric'),
function(e1, e2){
- return(setRaster(e1, values=callGeneric(.getValues(e1), e2)))
+ return(setRaster(e1, values=callGeneric(.getRasterValues(e1), e2)))
}
)
setMethod("Arith", signature(e1='numeric', e2='RasterLayer'),
function(e1, e2){
- return(setRaster(e2, values=callGeneric(.getValues(e2), e1)))
+ return(setRaster(e2, values=callGeneric(.getRasterValues(e2), e1)))
}
)
-setMethod("max", signature(x='RasterLayer'),
+setMethod("max", signature(x='Raster'),
function(x, ..., na.rm=FALSE){
obs <- list(...)
if (length(obs) == 0) {
- return(x)
+ return(setRaster(x, values=apply(as.matrix(.getRasterValues(x)), 1, max, na.rm=na.rm)))
} else {
- v <- .getValues(x)
+ v <- .getRasterValues(x)
for (i in 1:length(obs)) {
- v <- apply(cbind(v, .getTheValues(x, obs[[i]], i)), 1, max, na.rm=na.rm)
+ v <- apply(cbind(v, .getAllTypeOfValues(x, obs[[i]], i)), 1, max, na.rm=na.rm)
}
return(setRaster(x, values=v))
}
}
)
-setMethod("max", signature(x='RasterStack'),
- function(x, ..., na.rm=FALSE){
- obs <- list(...)
- if (length(obs) == 0) {
- return(setRaster(x, values=apply(.getValues(x), 1, max, na.rm=na.rm)))
- } else {
- v <- .getValues(x)
- for (i in 1:length(obs)) {
- v <- apply(cbind(v, .getTheValues(x, obs[[i]], i)), 1, max, na.rm=na.rm)
- }
- return(setRaster(x, values=v))
- }
- }
-)
-
-
-setMethod("min", signature(x='RasterLayer'),
+setMethod("min", signature(x='Raster'),
function(x, ..., na.rm=FALSE){
obs <- list(...)
if (length(obs) == 0) {
- return(x)
+ return(setRaster(x, values=apply(as.matrix(.getRasterValues(x)), 1, min, na.rm=na.rm)))
} else {
- v <- .getValues(x)
+ v <- .getRasterValues(x)
for (i in 1:length(obs)) {
- vv <- .getTheValues(x, obs[[i]], i)
- v <- pmin(v, vv, na.rm=na.rm)
+ v <- apply(cbind(v, .getAllTypeOfValues(x, obs[[i]], i)), 1, min, na.rm=na.rm)
}
return(setRaster(x, values=v))
}
@@ -149,77 +203,30 @@
)
-setMethod("min", signature(x='RasterStack'),
+setMethod("sum", signature(x='Raster'),
function(x, ..., na.rm=FALSE){
obs <- list(...)
if (length(obs) == 0) {
- return(setRaster(x, values=pmin(.getValues(x), na.rm)))
+ return(setRaster(x, values=rowSums(as.matrix(.getRasterValues(x)), na.rm)))
} else {
- v <- .getValues(x)
+ v <- .getRasterValues(x)
+ if (!(is.null(dim(v)))) {
+ v <- rowSums(as.matrix(.getRasterValues(x)), na.rm=na.rm)
+ }
for (i in 1:length(obs)) {
- vv <- .getTheValues(x, obs[[i]], i)
- v <- pmin(v, vv, na.rm=na.rm)
+ vv <- .getAllTypeOfValues(x, obs[[i]], i)
+ v <- rowSums(cbind(v, vv), na.rm=na.rm)
}
- return(setRaster(x, values=v))
+ return(setRaster(x, values=v))
}
}
)
-
-
-.getSum <- function(obs, x, ..., na.rm=FALSE) {
- v <- .getValues(x)
- if (!(is.null(dim(v)))) {
- v <- rowSums(.getValues(x), na.rm=na.rm)
- }
- for (i in 1:length(obs)) {
- vv <- .getTheValues(x, obs[[i]], i)
- v <- rowSums(cbind(v, vv), na.rm=na.rm)
- }
- return(setRaster(x, values=v))
-}
-
-
-setMethod("sum", signature(x='RasterLayer'),
- function(x, ..., na.rm=FALSE){
- obs <- list(...)
- if (length(obs) == 0) {
- return(x)
- } else {
- return(.getSum(obs, x, ..., na.rm))
- }
- }
-)
-
-
-setMethod("sum", signature(x='RasterStack'),
- function(x, ..., na.rm=FALSE){
- obs <- list(...)
- if (length(obs) == 0) {
- return(setRaster(x, values=rowSums(.getValues(x), na.rm)))
- } else {
- return(.getSum(obs, x, ..., na.rm))
- }
- }
-)
-
-
-setMethod("sum", signature(x='RasterBrick'),
- function(x, ..., na.rm=FALSE){
- obs <- list(...)
- if (length(obs) == 0) {
- return(setRaster(x, values=rowSums(.getValues(x), na.rm)))
- } else {
- return(.getSum(obs, x, ..., na.rm))
- }
- }
-)
-
#todo "any", "all"
-setMethod("range", signature(x='RasterLayer'),
+setMethod("range", signature(x='Raster'),
function(x, ..., na.rm=FALSE){
return(max(x, ..., na.rm=na.rm) - min(x, ..., na.rm=na.rm))
}
@@ -227,35 +234,26 @@
setMethod("is.na", signature(x='RasterLayer'),
function(x) {
- return(setRaster(x, values=is.na(.getValues(x))))
+ return(setRaster(x, values=is.na(.getRasterValues(x))))
}
)
-setMethod('dim', signature(x='AbstractRaster'),
- function(x){ return(c(nrow(x), ncol(x)))}
-)
-
-setMethod('dim', signature(x='RasterStack'),
+setMethod('dim', signature(x='Raster'),
function(x){ return(c(nrow(x), ncol(x), nlayers(x)))}
)
-setMethod('dim', signature(x='RasterBrick'),
- function(x){ return(c(nrow(x), ncol(x), nlayers(x)))}
-)
-
-setMethod('nrow', signature(x='AbstractRaster'),
+setMethod('nrow', signature(x='Raster'),
function(x){ return(x at nrows)}
)
-setMethod('ncol', signature(x='AbstractRaster'),
+setMethod('ncol', signature(x='Raster'),
function(x){ return(x at ncols) }
)
-
-setMethod('summary', signature(object='AbstractRaster'),
+setMethod('summary', signature(object='Raster'),
function(object, ...) {
# to be replaces by something more typical for summary in R, i.e. a sumary of the raster values
cat ("Cells: " , ncells(object), '\n')
@@ -281,36 +279,20 @@
)
-setMethod("plot", signature(x='RasterLayer', y='missing'),
+setMethod("plot", signature(x='Raster', y='missing'),
function(x, y, ...) {
map(x, ...)
}
)
-
-setMethod("plot", signature(x='RasterStack', y='numeric'),
+setMethod("plot", signature(x='Raster', y='numeric'),
function(x, y, ...) {
map(x, y, ...)
}
)
-setMethod("plot", signature(x='RasterStack', y='missing'),
- function(x, ...) {
- map(x, 1, ...)
- }
-)
-
-setMethod("plot", signature(x='RasterBrick', y='numeric'),
- function(x, y, ...) {
- ind <- as.integer(round(y))
- ind <- min(max(ind, 1), nlayers(x))
- map(x, ind, ...)
- }
-)
-
-
-
+# helper functions to set ... variables if they are not specified by the user. There probably exists a formal, and direct, mechanism to do this in R, but I have not discovered this yet...
.getmaxdim <- function(maxdim=1000, ...) {
return(maxdim)
}
@@ -326,7 +308,6 @@
nc <- ncells(x)
x <- readSkip(x, maxdim=maxdim)
y <- readSkip(y, maxdim=maxdim)
- rm(maxdim)
if (length(x) < nc) {
warning(paste('plot used a sample of ', round(100*length(x)/ncells(y)), "% of the cells", sep=""))
}
Modified: pkg/raster/R/values.R
===================================================================
--- pkg/raster/R/values.R 2009-01-10 16:06:50 UTC (rev 113)
+++ pkg/raster/R/values.R 2009-01-11 14:26:44 UTC (rev 114)
@@ -41,12 +41,12 @@
.values.as.matrix <- function(raster, names=FALSE) {
- if (raster at data@content=="nodata") {stop("first read some data (e.g., readAll() or readRow()") }
+ 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)
- } else if (raster at data@content=="all") {
+ } else if (dataContent(raster)=="all") {
mdata <- matrix(raster at data@values, nrow=nrow(raster), ncol=ncol(raster), byrow=TRUE)
if (names) {
colnames(mdata) <- seq(1:ncol(raster))
@@ -54,9 +54,9 @@
}
return(mdata)
- } else if (raster at data@content=="sparse") {
+ } else if (dataContent(raster)=="sparse") {
mdata <- matrix(NA, nrow=nrow(raster), ncol=ncol(raster), byrow=TRUE)
- vals <- cbind(raster at data@indices, values(raster))
+ vals <- cbind(dataIndices(raster), values(raster))
mdata[vals[,1]] <- vals[1,2]
if (names) {
colnames(mdata) <- seq(1:ncol(raster))
@@ -64,24 +64,24 @@
}
return(mdata)
- } else if (raster at data@content=="row") {
+ } else if (dataContent(raster)=="row") {
mdata <- matrix(raster at data@values, nrow=1, ncol=ncol(raster), byrow=TRUE)
if (names) {
colnames(mdata) <- seq(1:ncol(raster))
- therow <- rowFromCell(raster, raster at data@indices[1])
+ therow <- rowFromCell(raster, dataIndices(raster)[1])
rownames(mdata) <- therow
}
return(mdata)
- } else if (raster at data@content=="block") {
- startrow <- rowFromCell(raster, raster at data@indices[1])
- startcol <- colFromCell(raster, raster at data@indices[1])
- endrow <- rowFromCell(raster, raster at data@indices[2])
- endcol <- colFromCell(raster, raster at data@indices[2])
+ } else if (dataContent(raster)=="block") {
+ startrow <- rowFromCell(raster, dataIndices(raster)[1])
+ startcol <- colFromCell(raster, dataIndices(raster)[1])
+ endrow <- rowFromCell(raster, dataIndices(raster)[2])
+ endcol <- colFromCell(raster, dataIndices(raster)[2])
ncols <- 1 + endcol - startcol
nrows <- 1 + endrow - startrow
- mdata <- as.matrix(t(raster at data@values[1:ncols]))
+ mdata <- as.matrix(t(values(raster)[1:ncols]))
if (nrows > 1) {
for (i in 2:nrows) {
Added: pkg/raster/man/Arith-methods.Rd
===================================================================
--- pkg/raster/man/Arith-methods.Rd (rev 0)
+++ pkg/raster/man/Arith-methods.Rd 2009-01-11 14:26:44 UTC (rev 114)
@@ -0,0 +1,25 @@
+\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{
+ The following standard arithmic functions can be used for computations with RasterLayers objects and numeric values
+ "+", "-", "*", "^", "%%", "%/%", "/"
+}
+\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.
+}
+\author{Robert J. Hijmans \email{r.hijmans at gmail.com}}
+
+\examples{
+r1 <- newRaster()
+r1 <- setValues(r1, runif(ncells(r1)))
+r2 <- setValues(r1, 1:ncells(r1)) / ncells(r1)
+r3 <- r1 * r2 - 1
+}
+
+\keyword{methods}
+\keyword{math}
Added: pkg/raster/man/Compare-methods.Rd
===================================================================
--- pkg/raster/man/Compare-methods.Rd (rev 0)
+++ pkg/raster/man/Compare-methods.Rd 2009-01-11 14:26:44 UTC (rev 114)
@@ -0,0 +1,27 @@
+\name{Compare-methods}
+\docType{methods}
+\alias{Compare-methods}
+\alias{==,Raster,Raster-method}
+\alias{!=,Raster,Raster-method}
+
+\title{ Methods to compare Raster* objects}
+\description{
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/raster -r 114
More information about the Raster-commits
mailing list