[Raster-commits] r222 - in pkg/raster: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jan 30 16:18:58 CET 2009
Author: rhijmans
Date: 2009-01-30 16:18:58 +0100 (Fri, 30 Jan 2009)
New Revision: 222
Added:
pkg/raster/R/pointsToRaster.R
pkg/raster/R/setDatatype.R
pkg/raster/man/setDatatype.Rd
Removed:
pkg/raster/R/point2raster.R
Modified:
pkg/raster/DESCRIPTION
pkg/raster/R/click.R
pkg/raster/R/group.generic.functions.R
pkg/raster/R/makeProjString.R
pkg/raster/R/raster.create.R
pkg/raster/R/read.raster.R
pkg/raster/R/readSurfer.R
pkg/raster/R/replacement.R
pkg/raster/R/set.R
pkg/raster/man/classes.Rd
pkg/raster/man/set.Rd
Log:
Modified: pkg/raster/DESCRIPTION
===================================================================
--- pkg/raster/DESCRIPTION 2009-01-30 09:16:32 UTC (rev 221)
+++ pkg/raster/DESCRIPTION 2009-01-30 15:18:58 UTC (rev 222)
@@ -1,7 +1,7 @@
Package: raster
Type: Package
Title: Raster data handling for geographic data analysis and modeling
-Version: 0.8.7-5
+Version: 0.8.7-6
Date: 30-Jan-2009
Depends: methods, sp, rgdal (>= 0.5-33), R (>= 2.8.0)
Author: Robert J. Hijmans & Jacob van Etten
Modified: pkg/raster/R/click.R
===================================================================
--- pkg/raster/R/click.R 2009-01-30 09:16:32 UTC (rev 221)
+++ pkg/raster/R/click.R 2009-01-30 15:18:58 UTC (rev 222)
@@ -7,8 +7,8 @@
# Licence GPL v3
-click <- function(object, n=1, xy=FALSE, type = "n", ...) {
- loc <- locator(n)
+click <- function(object, n=1, xy=FALSE, type="n", ...) {
+ loc <- locator(n, type, ...)
x <- loc$x
y <- loc$y
xyCoords <- cbind(x, y)
Modified: pkg/raster/R/group.generic.functions.R
===================================================================
--- pkg/raster/R/group.generic.functions.R 2009-01-30 09:16:32 UTC (rev 221)
+++ pkg/raster/R/group.generic.functions.R 2009-01-30 15:18:58 UTC (rev 222)
@@ -9,7 +9,7 @@
# memalloc <- n * ncell(raster) * 8
# memavailable <- memory.limit()-memory.size()
# For now something simplistic :
- maxalloc <- 10^8
+ maxalloc <- 10^7
if ( (ncell(raster) * n * datasize) > maxalloc ) {
return( FALSE )
} else {
Modified: pkg/raster/R/makeProjString.R
===================================================================
--- pkg/raster/R/makeProjString.R 2009-01-30 09:16:32 UTC (rev 221)
+++ pkg/raster/R/makeProjString.R 2009-01-30 15:18:58 UTC (rev 222)
@@ -6,6 +6,22 @@
+newCRS <- function(projstring) {
+ projstring <- trim(projstring)
+ if (is.na(projstring) | nchar(projstring) < 3) {
+ projs <- (CRS(as.character(NA)))
+ } else {
+ projs <- try(CRS(projstring), silent = T)
+ if (class(projs) == "try-error") {
+ warning(paste(projstring, 'is not a valid proj4 CRS string'))
+ projs <- CRS(as.character(NA))
+ }
+ }
+ return(projs)
+}
+
+
+
makeProj <- function(projection='longlat', ..., ellipsoid="", datum="", asText=TRUE) {
prj <- projInfo("proj")
ell <- projInfo("ellps")
Deleted: pkg/raster/R/point2raster.R
===================================================================
--- pkg/raster/R/point2raster.R 2009-01-30 09:16:32 UTC (rev 221)
+++ pkg/raster/R/point2raster.R 2009-01-30 15:18:58 UTC (rev 222)
@@ -1,46 +0,0 @@
-
-pointsToRaster <- function(raster, xy, values, fun=length, filename="", overwrite=FALSE) {
- if (class(xy) != 'matrix') {stop('xy must be a matrix')}
- if (length(values) != length(xy[,1])) {stop('values must be a vector of length=length(xy[,1])')}
-
- rs <- setRaster(raster, filename)
- cells <- cellFromXY(rs, xy)
- rows <- rowFromCell(rs, cells)
- cols <- colFromCell(rs, cells)
- xyarc <- cbind(xy, values, rows, cols)
- urows <- unique(rows)
- urows <- urows[order(urows)]
- d <- vector(length=ncol(rs))
- d[] <- NA
- dna <- d
- v <- vector(length=0)
- for (r in 1:rs at nrows) {
- if (r %in% urows) {
- ss <- subset(xyarc, xyarc[,4] == r)
- ucols <- unique(ss[,5])
- ucols <- ucols[order(ucols)]
- d <- dna
- for (c in 1:length(ucols)) {
- sss <- subset(ss, ss[,5] == ucols[c] )
- d[ucols[c]] <- fun(sss[,3])
- }
- if (filename != "") {
- rs <- setValues(rs, d, r)
- rs <- writeRaster(rs)
- } else {
- v <- c(v, d)
- }
- } else {
- if (filename != "") {
- rs <- setValues(rs, dna, r)
- rs <- writeRaster(rs, r)
- } else {
- v <- c(v, dna)
- }
- }
- }
- if (filename == "") {
- rs <- setValues(rs, v)
- }
- return(rs)
-}
Added: pkg/raster/R/pointsToRaster.R
===================================================================
--- pkg/raster/R/pointsToRaster.R (rev 0)
+++ pkg/raster/R/pointsToRaster.R 2009-01-30 15:18:58 UTC (rev 222)
@@ -0,0 +1,60 @@
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date : January 2009
+# Version 0.8
+# Licence GPL v3
+
+
+pointsToRaster <- function(raster, xy, values, fun=length, filename="", overwrite=FALSE) {
+# make this an argument ? so that you can use e.g. background=0
+ background=NA
+
+ if (class(xy) != 'matrix') {
+ stop('xy must be a matrix')
+ }
+ if (length(values) != length(xy[,1])) {
+ stop('values must be a vector of length=length(xy[,1])')
+ }
+
+ rs <- setRaster(raster, filename)
+ cells <- cellFromXY(rs, xy)
+ rows <- rowFromCell(rs, cells)
+ cols <- colFromCell(rs, cells)
+ xyarc <- cbind(xy, values, rows, cols)
+ urows <- unique(rows)
+ urows <- urows[order(urows)]
+ dna <- vector(length=ncol(rs))
+ dna[] <- background
+ v <- vector(length=0)
+ for (r in 1:rs at nrows) {
+ if (r %in% urows) {
+ ss <- subset(xyarc, xyarc[,4] == r)
+ ucols <- unique(ss[,5])
+# ucols <- ucols[order(ucols)]
+ d <- dna
+ for (c in 1:length(ucols)) {
+ sss <- subset(ss, ss[,5] == ucols[c] )
+ d[ucols[c]] <- fun(sss[,3])
+ }
+ if (filename != "") {
+ rs <- setValues(rs, d, r)
+ rs <- writeRaster(rs)
+ } else {
+ v <- c(v, d)
+ }
+ } else {
+ if (filename != "") {
+ rs <- setValues(rs, dna, r)
+ rs <- writeRaster(rs, r)
+ } else {
+ v <- c(v, dna)
+ }
+ }
+ }
+ if (filename == "") {
+ rs <- setValues(rs, v)
+ }
+ return(rs)
+}
+
+
Modified: pkg/raster/R/raster.create.R
===================================================================
--- pkg/raster/R/raster.create.R 2009-01-30 09:16:32 UTC (rev 221)
+++ pkg/raster/R/raster.create.R 2009-01-30 15:18:58 UTC (rev 222)
@@ -174,7 +174,8 @@
} else if (substr(inidatatype, 1, 3) == "ASC") { datatp="ascii"
} else { datatp="numeric" }
datasz <- as.integer(substr(inidatatype, 4, 4))
- raster <- setDatatype(raster, datatype=datatp, datasize=datasz)
+ dsign <- substr(inidatatype, 5, 1)
+ raster <- setDatatype(raster, datatype=datatp, datasize=datasz, signed=dsign)
if ((byteorder == "little") | (byteorder == "big")) { raster at file@byteorder <- byteorder }
raster at file@nbands <- as.integer(nbands)
raster at file@band <- as.integer(band)
Modified: pkg/raster/R/read.raster.R
===================================================================
--- pkg/raster/R/read.raster.R 2009-01-30 09:16:32 UTC (rev 221)
+++ pkg/raster/R/read.raster.R 2009-01-30 15:18:58 UTC (rev 222)
@@ -25,16 +25,19 @@
nrows <- endrow - startrow + 1
}
raster <- .rasterRead(raster, startrow, startcol, ncolumns)
- blockdata <- values(raster)
+ blockvalues <- values(raster)
if (nrows > 1) {
for (r in (startrow+1):endrow) {
raster <- .rasterRead(raster, r, startcol, ncolumns)
- blockdata <- c(blockdata, values(raster))
+ blockvalues <- c(blockvalues, values(raster))
}
}
- startcell <- cellFromRowCol(raster, startrow, startcol)
- endcell <- cellFromRowCol(raster, endrow, (startcol+ncolumns-1))
- raster <- setValuesBlock(raster, blockdata, startcell, endcell)
+ raster at data@values <- blockvalues
+ raster at data@content <- 'block'
+ firstcell <- cellFromRowCol(raster, startrow, startcol)
+ lastcell <- cellFromRowCol(raster, endrow, (startcol+ncolumns-1))
+ raster at data@indices <- c(firstcell, lastcell)
+
return(raster)
}
@@ -55,9 +58,7 @@
}
if (dataSource(raster)=='ram') {
-
result <- valuesRow(raster, rownr)[startcol:endcol]
-
} else if (.driver(raster) == 'raster') {
rastergri <- .setFileExtensionValues(filename(raster))
@@ -74,13 +75,17 @@
}
if (rownr > 0) {
seek(con, ((rownr-1) * ncol(raster) + (startcol-1)) * raster at file@datasize)
- result <- readBin(con, what=dtype, n = ncolumns, size = raster at file@datasize, endian = raster at file@byteorder) }
+ result <- readBin(con, what=dtype, n=ncolumns, size=raster at file@datasize, signed=raster at file@datasigned, endian=raster at file@byteorder) }
else {
- result <- readBin(con, what=dtype, n = ncell(raster), size = raster at file@datasize, endian = raster at file@byteorder)
+ result <- readBin(con, what=dtype, n=ncell(raster), size=raster at file@datasize, signed=raster at file@datasigned, endian=raster at file@byteorder)
}
close(con)
result[is.nan(result)] <- NA
- result[result <= (0.999 * .nodatavalue(raster)) ] <- NA
+ if (dtype == 'numeric') {
+ result[result <= (0.999 * .nodatavalue(raster)) ] <- NA
+ } else {
+ result[result == raster at file@nodatavalue ] <- NA
+ }
if (raster at file@datatype == 'logical') {
result <- as.logical(result)
}
@@ -204,7 +209,7 @@
ymn <- ymin(raster) + (nrow(raster) - row) * yres(raster)
bndbox <- changeBbox(raster, xmx=xmx, ymn=ymn)
outras <- setBbox(outras, bndbox, keepres=F)
- outras <- setValues(outras, dd)
+ outras at data@values <- dd
}
if (asRaster) {
return(outras)
Modified: pkg/raster/R/readSurfer.R
===================================================================
--- pkg/raster/R/readSurfer.R 2009-01-30 09:16:32 UTC (rev 221)
+++ pkg/raster/R/readSurfer.R 2009-01-30 15:18:58 UTC (rev 222)
@@ -3,8 +3,8 @@
con <- file(filename, "rb")
id <- readBin(con, "characater", n=1, size=4)
r <- raster()
- r at ncols <- readBin(con, "int", n=4, size=2)
- r at rows <- readBin(con, "int", n=4, size=2)
+ r at ncols <- readBin(con, "int", n=1, size=2)
+ r at rows <- readBin(con, "int", n=1, size=2)
r at bbox@xmin <- readBin(con, "double", n=1, size=8)
r at bbox@xmax <- readBin(con, "double", n=1, size=8)
r at bbox@ymin <- readBin(con, "double", n=1, size=8)
@@ -16,7 +16,8 @@
close(con)
m <- matrix(v, nrow=r at rows, ncol=r at ncol, byrow=T)
m <- m[nrow(m):1, ]
- r <- setValues(r, as.vector(t(m)))
+ r at data@values <- as.vector(t(m))
+ r at data@source <- 'disk'
r at file@driver <- "surfer"
return(r)
}
Modified: pkg/raster/R/replacement.R
===================================================================
--- pkg/raster/R/replacement.R 2009-01-30 09:16:32 UTC (rev 221)
+++ pkg/raster/R/replacement.R 2009-01-30 15:18:58 UTC (rev 222)
@@ -1,14 +1,13 @@
# Author: Robert J. Hijmans, r.hijmans at gmail.com
# International Rice Research Institute
-# Date : June 2008
-# Version 0,8
+# Date : January 2009
+# Version 0.8
# Licence GPL v3
'filename<-' <- function(x, value) {
return( setFilename(x, value) )
}
-
'projection<-' <- function(x, value) {
return( setProjection(x, value) )
}
@@ -22,6 +21,8 @@
}
+
+
.getColValues <- function(r, colnr) {
firstcol <- 1:nrow(r) * ncol(r) - ncol(r)
cells <- colnr + firstcol
@@ -30,7 +31,6 @@
-
setMethod("[", "RasterLayer",
function(x,i,j,...,drop=FALSE) {
if (!missing(j)) { stop("incorrect number of dimensions") }
@@ -50,7 +50,18 @@
setReplaceMethod("[", "RasterLayer",
function(x, i, j, value) {
- if (!missing(j)) { stop("incorrect number of dimensions") }
+ if (!missing(j)) {
+ stop("incorrect number of dimensions")
+ }
+ if (missing(i)) {
+ if (length(value) == ncell(x)) {
+ return(setValues(x, value))
+ } else if (length(value) == 1) {
+ return( setValues(x, rep(value, times=ncell(x))) )
+ } else {
+ stop('length of replacement values should be 1 or ncell')
+ }
+ }
if (class(i) == "RasterLayer") {
i <- as.logical( .getRasterValues(i) )
}
@@ -91,15 +102,42 @@
}
}
return( matrix(values(x), nrow(x), ncol(x), byrow=T)[i,j] )
-
-# if (missing(i)) { rows <- 1:nrow(x) } else { rows <- i }
-# if (missing(j)) { cols <- 1:ncol(x) } else { cols <- j }
- # ugly R code
-# cells <- cellFromRowcol(rep(rows[1], length(cols)), cols)
-# for (a in 2:rows) { cells <- c(cells, cells + (a - 1) * ncol(x)) }
-# vals <- values(x)[cells]
-# return( matrix(vals, length(rows), lenght(cols), byrow=T) )
}
)
+setReplaceMethod("[[", "RasterLayer",
+ function(x, i, j, value) {
+ if (!missing(i)) {
+ if (class(i) == "RasterLayer") {
+ i <- as.logical( .getRasterValues(i) )
+ }
+ }
+ if (!missing(j)) {
+ if (class(j) == "RasterLayer") {
+ j <- as.logical( .getRasterValues(i) )
+ }
+ }
+
+ if (dataContent(x) == 'nodata') {
+ if (ncell(x) < 1000000) {
+ if (dataSource(x) == 'disk') {
+ x <- readAll(x)
+ } else {
+ x <- setValues(x, rep(NA, times=ncell(x)))
+ }
+ } else {
+ stop('Large raster with no data in memory, use readAll() first')
+ }
+ }
+ v <- matrix(values(x), nrow(x), ncol(x), byrow=T)
+ x <- clearValues(x)
+ v[i,j] <- value
+ x <- setValues(x, as.vector(t(v)))
+ x <- setFilename(x, "")
+ x <- setMinMax(x)
+ return(x)
+ }
+)
+
+
Modified: pkg/raster/R/set.R
===================================================================
--- pkg/raster/R/set.R 2009-01-30 09:16:32 UTC (rev 221)
+++ pkg/raster/R/set.R 2009-01-30 15:18:58 UTC (rev 222)
@@ -82,22 +82,7 @@
}
-newCRS <- function(projstring) {
- projstring <- trim(projstring)
- if (is.na(projstring) | nchar(projstring) < 3) {
- projs <- (CRS(as.character(NA)))
- } else {
- projs <- try(CRS(projstring), silent = T)
- if (class(projs) == "try-error") {
- warning(paste(projstring, 'is not a valid proj4 CRS string'))
- projs <- CRS(as.character(NA))
- }
- }
- return(projs)
-}
-
-
roundCoords <- function(object, digits=0) {
digits <- max(0, digits)
b <- getBbox(object)
@@ -149,61 +134,3 @@
return(raster)
}
-
-setDatatype <- function(raster, datatype, datasize=4) {
-# signed" should become variable
- signed <- TRUE
- if (datatype == "numeric") {
- raster at file@datatype <- datatype
- if (dataContent(raster) != 'nodata') {
- raster at data@values <- as.numeric(values(raster))
- }
- if (datasize == 4) {
- raster at file@datasize <- as.integer(4)
- raster at file@nodatavalue <- -3.4E38
- raster at file@datanotation <- "FLT4S"
- } else if (datasize == 8) {
- raster at file@datasize <- as.integer(8)
- raster at file@nodatavalue <- -1.7E308
- raster at file@datanotation <- "FLT8S"
- } else {
- stop("invalid datasize for this datatype")
- }
- } else if (datatype == "integer") {
- raster at file@datatype <- datatype
- raster at data@min <- round(minValue(raster))
- raster at data@max <- round(maxValue(raster))
- if (dataContent(raster) != 'nodata') {
- raster at data@values <- as.integer(round(values(raster)))
- }
- if (datasize == 4) {
- raster at file@datasize <- as.integer(4)
- raster at file@nodatavalue <- -2147483647
- raster at file@datanotation <- "INT4S"
- } else if (datasize == 2) {
- raster at file@datasize <- as.integer(2)
- raster at file@nodatavalue <- -32768
- raster at file@datanotation <- "INT2S"
- } else if (datasize == 1) {
- raster at file@datasize <- as.integer(1)
- raster at file@nodatavalue <- -1
- raster at file@datanotation <- "INT1U"
- warning("binary files of single byte do not have NA values on disk")
- } else if (datasize == 8) {
- raster at file@datasize <- as.integer(8)
- raster at file@nodatavalue <- -2^63
- raster at file@datanotation <- "INT8S"
- } else {
- stop("invalid datasize for this datatype")
- }
- } else if ( datatype == 'logical' ) {
- raster at file@datatype <- datatype
- raster at file@datasize <- as.integer(1)
- raster at file@nodatavalue <- -126
- raster at file@datanotation <- "LOGICAL"
- } else {
- stop("unknown datatype")
- }
- return(raster)
-}
-
Added: pkg/raster/R/setDatatype.R
===================================================================
--- pkg/raster/R/setDatatype.R (rev 0)
+++ pkg/raster/R/setDatatype.R 2009-01-30 15:18:58 UTC (rev 222)
@@ -0,0 +1,84 @@
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date : June 2008
+# Version 0.8
+# Licence GPL v3
+
+setDatatype <- function(raster, datatype, datasize=4, signed=TRUE) {
+ if (datatype == "numeric") {
+ raster at file@datasigned <- TRUE
+ raster at file@datatype <- datatype
+ if (dataContent(raster) != 'nodata') {
+ raster at data@values <- as.numeric(values(raster))
+ }
+ if (datasize == 4) {
+ raster at file@datasize <- as.integer(4)
+ raster at file@nodatavalue <- -3.4E38
+ raster at file@datanotation <- "FLT4S"
+ } else if (datasize == 8) {
+ raster at file@datasize <- as.integer(8)
+ raster at file@nodatavalue <- -1.7E308
+ raster at file@datanotation <- "FLT8S"
+ } else {
+ stop("invalid datasize for this datatype")
+ }
+ } else if (datatype == "integer") {
+ raster at file@datasigned <- signed
+ raster at file@datatype <- datatype
+ raster at data@min <- round(minValue(raster))
+ raster at data@max <- round(maxValue(raster))
+ if (dataContent(raster) != 'nodata') {
+ raster at data@values <- as.integer(round(values(raster)))
+ }
+ if (datasize == 4) {
+ raster at file@datasize <- as.integer(4)
+ if (signed) {
+ raster at file@datanotation <- "INT4S"
+ raster at file@nodatavalue <- -2147483647
+ } else {
+ raster at file@datanotation <- "INT4U"
+ raster at file@nodatavalue <- 4294967295
+ }
+ } else if (datasize == 2) {
+ raster at file@datasize <- as.integer(2)
+ if (signed) {
+ raster at file@datanotation <- "INT2S"
+ raster at file@nodatavalue <- -32768
+ } else {
+ raster at file@datanotation <- "INT2U"
+ raster at file@nodatavalue <- 65535
+ }
+ } else if (datasize == 1) {
+ raster at file@datasize <- as.integer(1)
+ # there is no nodata value for byte
+ raster at file@nodatavalue <- -9999
+ if (signed) {
+ raster at file@datanotation <- "INT1S"
+ } else {
+ raster at file@datanotation <- "INT1U"
+ }
+ warning("binary files of a single byte do not have NA values on disk")
+ } else if (datasize == 8) {
+ raster at file@datasize <- as.integer(8)
+ if (signed) {
+ raster at file@datanotation <- "INT8S"
+ raster at file@nodatavalue <- -9223372036854775808
+ } else {
+ raster at file@datanotation <- "INT8U"
+ raster at file@nodatavalue <- 18446744073709551615
+ }
+ } else {
+ stop("invalid datasize for this datatype")
+ }
+ } else if ( datatype == 'logical' ) {
+ raster at file@datasigned <- TRUE
+ raster at file@datatype <- datatype
+ raster at file@datasize <- as.integer(1)
+ raster at file@nodatavalue <- -127
+ raster at file@datanotation <- "LOGICAL"
+ } else {
+ stop("unknown datatype")
+ }
+ return(raster)
+}
+
Modified: pkg/raster/man/classes.Rd
===================================================================
--- pkg/raster/man/classes.Rd 2009-01-30 09:16:32 UTC (rev 221)
+++ pkg/raster/man/classes.Rd 2009-01-30 15:18:58 UTC (rev 222)
@@ -22,7 +22,7 @@
\alias{[<-,RasterLayer-method}
\alias{[,RasterStack-method}
\alias{[[,RasterLayer,ANY,ANY-method}
-\alias{[[<-,RasterLayer,ANY,missing-method}
+\alias{[[<-,RasterLayer,ANY,ANY-method}
\title{Classes for handling raster data }
\description{ \code{RasterLayer}, \code{RasterStack} (Raster* in short) are all classes for handling spatial raster (grid) data.
Modified: pkg/raster/man/set.Rd
===================================================================
--- pkg/raster/man/set.Rd 2009-01-30 09:16:32 UTC (rev 221)
+++ pkg/raster/man/set.Rd 2009-01-30 15:18:58 UTC (rev 222)
@@ -2,7 +2,6 @@
\alias{setRaster}
\alias{setFilename}
\alias{setProjection}
-\alias{setDatatype}
\alias{setRowCol}
\alias{setRes}
\alias{setMinMax}
@@ -10,14 +9,13 @@
\title{ Set properties of a RasterLayer object }
\description{
-Use these functions to set name and datatype properties of a RasterLayer object. While you can access the slots of the object directly, you would do that at your own peril because the value of one raster property can affect values in other properties, and changing slot values may thus break the integrity of the objects. Using slots directly may also lead to code to break in the future if underlying class definitions change.
+Use these functions to set certain properties of a RasterLayer object.
}
\usage{
setProjection(object, projstring)
setFilename(object, filename)
setRaster(object, filename="", values=NA)
-setDatatype(raster, datatype, datasize)
setRowCol(raster, nrows=nrow(raster), ncols=ncol(raster))
setRes(object, xres, yres=xres)
setMinMax(raster, readfromdisk=FALSE)
@@ -28,8 +26,6 @@
\item{raster}{ A \code{RasterLayer} object }
\item{values}{ Data values to associate with the RasterLayer object}
\item{filename}{ filename, can be blank }
- \item{datatype}{ the type of data ('numeric' or 'integer' that will be written to disk }
- \item{datasize}{ The size, in number of bytes, that wil be written to disk. typically 4 for integer, and 8 for numeric datatype }
\item{nrows}{ the new number of rows for the raster }
\item{ncols}{ the new number of cols for the raster }
\item{xres}{ the new x resolution}
@@ -41,6 +37,8 @@
\details{
setRaster copies the parameters of a RasterLayer object to a new object, but does not copy the filename nor the data associated with the original raster.
Use it when creating new RasterLayer objects from existing objects.
+
+While you could access the slots of the object directly, you would do that at your own peril because the value of one raster property can affect values in other properties, and changing slot values may thus break the integrity of the objects. Using slots directly may also lead to code to break in the future if underlying class definitions change.
}
\value{
@@ -54,8 +52,6 @@
r <- setRowCol(r, nrows=18, ncols=36)
r <- setRes(r, xres=1/120)
r <- setProjection(r, "+proj=longlat +datum=WGS84")
- r <- setDatatype(r, datatype="integer", datasize=4)
- r <- setDatatype(r, datatype="numeric", datasize=8)
}
\keyword{ spatial }
Added: pkg/raster/man/setDatatype.Rd
===================================================================
--- pkg/raster/man/setDatatype.Rd (rev 0)
+++ pkg/raster/man/setDatatype.Rd 2009-01-30 15:18:58 UTC (rev 222)
@@ -0,0 +1,67 @@
+\name{set}
+\alias{setDatatype}
+
+\title{ Set data type }
+
+\description{
+Use these functions to set the datatype properties of a RasterLayer object. The datatype determines how values are written to disk.
+}
+
+\usage{
+setDatatype(raster, datatype, datasize=4, signed=TRUE)
+}
+
+\arguments{
+ \item{raster}{ A \code{RasterLayer} object }
+ \item{datatype}{ the type of data ('numeric' or 'integer' that will be written to disk }
+ \item{datasize}{ The size, in number of bytes, that wil be written to disk. typically 4 for integer, and 8 for numeric datatype }
+ \item{signed}{ logical}
+}
+
+\details{
+While you can access the slots of the object directly, you would do that at your own peril because the value of one raster property can affect values in other properties, and changing slot values may thus break the integrity of the objects. Using slots directly may also lead to code to break in the future if underlying class definitions change.
+
+datatype, size, signed: range of possible values
+
+'boolean', 1: FALSE (0) to TRUE (1)
+
+'integer', 1, signed: -127 to 127
+
+'integer', 1, unsigned: 0 to 255
+
+'integer', 2, signed: -32,767 to 32,767
+
+'integer', 2, unsigned: 0 to 65,534
+
+'integer', 4, signed: -2,147,483,647 to 2,147,483,647
+
+'integer', 4, unsigned: 0 to 4,294,967,294
+
+'integer', 8, signed: -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807
+
+'integer', 8, unsigned: 0 to 18,446,744,073,709,551,614
+
+
+
+}
+
+\value{
+ a Raster* object
+}
+\author{ Robert J. Hijmans \email{r.hijmans at gmail.com} }
+
+\examples{
+ r <- raster()
+# 2 byte signed integer between -32,768 to +32,767
+ r <- setDatatype(r, datatype="integer", datasize=2)
+# 2 byte unsigned integer between 0 to +65,535
+ r <- setDatatype(r, datatype="integer", datasize=2, signed=FALSE)
+# very large integers
+ r <- setDatatype(r, datatype="numeric", datasize=8)
+# save byte values between 0 and 255
+ r <- setDatatype(r, datatype="integer", datasize=1, signed=FALSE)
+
+}
+
+\keyword{ spatial }
+
More information about the Raster-commits
mailing list