[Raster-commits] r481 - in pkg/raster: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Sep 8 21:05:56 CEST 2009
Author: rhijmans
Date: 2009-09-08 21:05:55 +0200 (Tue, 08 Sep 2009)
New Revision: 481
Added:
pkg/raster/man/intersectExtent.Rd
pkg/raster/man/newExtent.Rd
Removed:
pkg/raster/man/CDF.Rd
pkg/raster/man/intersectBbox.Rd
pkg/raster/man/newBbox.Rd
pkg/raster/man/rasterCDF.Rd
Modified:
pkg/raster/R/raster.R
pkg/raster/R/rasterFromNetCDF.R
pkg/raster/R/rasterToNetCDF.R
pkg/raster/R/stack.R
pkg/raster/R/write.R
pkg/raster/man/RasterLayer-class.Rd
pkg/raster/man/aggregate.Rd
pkg/raster/man/distance.Rd
pkg/raster/man/merge.Rd
pkg/raster/man/raster.Rd
pkg/raster/man/writeRaster.Rd
pkg/raster/man/writeStack.Rd
Log:
Modified: pkg/raster/R/raster.R
===================================================================
--- pkg/raster/R/raster.R 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/R/raster.R 2009-09-08 19:05:55 UTC (rev 481)
@@ -1,6 +1,6 @@
- # Author: Robert J. Hijmans, r.hijmans at gmail.com
-# Date : August 2008
-# Version 0.8
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# Date : September 2008
+# Version 0.9
# Licence GPL v3
if (!isGeneric("raster")) {
@@ -48,7 +48,7 @@
w <- readBin(fcon, what='character', n=1)
close(fcon)
if (substr(w, 1, 3) == "CDF") {
- r <- rasterCDF(x, ...)
+ r <- .rasterCDF(x, ...)
} else {
# perhaps a surfer grid...
r <- .rasterFromGDAL(x, band)
@@ -63,7 +63,7 @@
}
} else if (file.exists( x )){
if (fileext == '.NC') {
- r <- rasterCDF(x, ...)
+ r <- .rasterCDF(x, ...)
} else {
r <- .rasterFromGDAL(x, band)
}
Modified: pkg/raster/R/rasterFromNetCDF.R
===================================================================
--- pkg/raster/R/rasterFromNetCDF.R 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/R/rasterFromNetCDF.R 2009-09-08 19:05:55 UTC (rev 481)
@@ -1,6 +1,6 @@
# Author: Robert J. Hijmans, r.hijmans at gmail.com
# Date: Aug 2009
-# Version 0.8
+# Version 0.9
# Licence GPL v3
.getxvar <- function(xvar, vars) {
@@ -45,7 +45,7 @@
}
-rasterCDF <- function(filename, xvar='', yvar='', zvar='', time=1) {
+.rasterCDF <- function(filename, xvar='', yvar='', zvar='', time=1) {
# to be improved for large files (i.e. do not read all data from file...)
if (!require(RNetCDF)) { stop() }
nc <- open.nc(filename)
@@ -76,7 +76,7 @@
-stackCDF <- function(filename, xvar='', yvar='', zvar='', time=1) {
+.stackCDF <- function(filename, xvar='', yvar='', zvar='', time='') {
# to be improved for large files (i.e. do not read all data from file...)
if (!require(RNetCDF)) { stop() }
nc <- open.nc(filename)
@@ -93,14 +93,19 @@
close.nc(nc)
dims <- dim(dd)
- if (length(dims)== 3) { tsteps <- dims[3]
+ if (length(dims)== 3) {
+ if (is.numeric(time)) {
+ tsteps <- time
+ } else {
+ tsteps <- 1:dims[3]
+ }
} else if (length(dims)== 3) { tsteps <- 1
} else if (length(dims)== 2) {
- return(stack(rasterCDF(filename, xvar, yvar, zvar)))
+ return(stack(.rasterCDF(filename, xvar, yvar, zvar)))
} else { stop(paste('data has an unexpected number of dimensions', dims)) }
- for (i in 1:tsteps) {
+ for (i in tsteps) {
d <- dd[,,i]
# y needs to go from big to small
d <- matrix(d, ncol=ncol(r), nrow=nrow(r), byrow=TRUE)
Modified: pkg/raster/R/rasterToNetCDF.R
===================================================================
--- pkg/raster/R/rasterToNetCDF.R 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/R/rasterToNetCDF.R 2009-09-08 19:05:55 UTC (rev 481)
@@ -1,21 +1,13 @@
# Author: Robert J. Hijmans, r.hijmans at gmail.com
-# Date: Aug 2009
-# Version 0.8
+# Date: September 2009
+# Version 0.9
# Licence GPL v3
+.writeRasterCDF <- function(x, overwrite=FALSE){
-if (!isGeneric("CDF")) {
- setGeneric("CDF", function(x, y, ...)
- standardGeneric("CDF"))
-}
-
-
-setMethod('CDF', signature(x='RasterLayer', y='character'),
- function(x, y){
- overwrite <- TRUE
-
if (!require(RNetCDF)) { stop() }
+
xvar <- (xmin(x) + 1:ncol(x) * xres(x)) - 0.5 * xres(x)
yvar <- (ymin(x) + 1:nrow(x) * yres(x)) - 0.5 * yres(x)
if (dataContent(x) != 'all') {
@@ -27,40 +19,38 @@
} else {
dtype <- 'NC_INT'
}
- zvar <- t(matrix(zvar, ncol=ncol(x), nrow=nrow(x)))
+
+ zvar <- matrix(zvar, ncol=ncol(x), nrow=nrow(x), byrow=TRUE)
zvar <- t(zvar[nrow(zvar):1, ])
- nc <- create.nc(y, clobber=overwrite)
+
+ nc <- create.nc(filename(x), clobber=overwrite)
dim.def.nc(nc, "x", ncol(x))
dim.def.nc(nc, "y", nrow(x))
var.def.nc(nc, "x", 'NC_DOUBLE', 0)
var.def.nc(nc, "y", 'NC_DOUBLE', 1)
- var.def.nc(nc, "z", 'NC_DOUBLE', c(1,0))
+ var.def.nc(nc, "z", 'NC_DOUBLE', c(0,1))
- var.put.nc(nc, "x", xvar)
- var.put.nc(nc, "y", yvar)
- var.put.nc(nc, "z", zvar)
-
att.put.nc(nc, "z", "missing_value", "NC_DOUBLE", NAvalue(x))
att.put.nc(nc, "z", "long_name", "NC_CHAR", layerNames(x))
att.put.nc(nc, "NC_GLOBAL", "title", "NC_CHAR", "Data from the R raster package")
att.put.nc(nc, "NC_GLOBAL", "history", "NC_CHAR", paste("Created on", date()))
+ var.put.nc(nc, "x", xvar)
+ var.put.nc(nc, "y", yvar)
+ var.put.nc(nc, "z", zvar)
+
+
close.nc(nc)
- }
-)
+}
- #CDF(r, 'c:/test.nc')
- #y <- raster('c:/test.nc')
- #plot(y)
-setMethod('CDF', signature(x='RasterStack', y='character'),
- function(x, y){
+.writeStackCDF <- function(x, y){
if (!require(RNetCDF)) { stop() }
-
- }
-)
+ stop('not implemented yet')
+}
+
Modified: pkg/raster/R/stack.R
===================================================================
--- pkg/raster/R/stack.R 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/R/stack.R 2009-09-08 19:05:55 UTC (rev 481)
@@ -1,7 +1,6 @@
# Author: Robert J. Hijmans, r.hijmans at gmail.com
-# International Rice Research Institute
-# Date : June 2008
-# Version 0.8
+# Date : September 2008
+# Version 0.9
# Licence GPL v3
@@ -34,9 +33,13 @@
setMethod("stack", signature(x='character'),
-function(x, ..., bands=NULL) {
- rlist <- c(x, list(...))
- return(stack(rlist, bands))
+function(x, ..., bands=NULL, xvar='', yvar='', zvar='', time='') {
+ if (xvar != '' | yvar != '' | zvar != '' | is.numeric(time)) {
+ return(.stackCDF(x, xvar, yvar, zvar, time))
+ } else {
+ rlist <- c(x, list(...))
+ return(stack(rlist, bands))
+ }
} )
Modified: pkg/raster/R/write.R
===================================================================
--- pkg/raster/R/write.R 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/R/write.R 2009-09-08 19:05:55 UTC (rev 481)
@@ -1,14 +1,22 @@
# Author: Robert J. Hijmans, r.hijmans at gmail.com
-# International Rice Research Institute
-# Date : June 2008
-# Version 0.8
+# Date : September 2009
+# Version 0.9
# Licence GPL v3
-writeRaster <- function(raster, filetype='raster', overwrite=FALSE, assign=FALSE) {
- if (assign){ raster_name <- deparse(substitute(raster))}
+writeRaster <- function(raster, filetype='raster', filename='', overwrite=FALSE, assign=FALSE) {
+ if (assign){
+ raster_name <- deparse(substitute(raster))
+ }
+ if (filename != '') {
+ filename(raster) <- filename
+ }
+ if (filename(raster) == '') {
+ stop('RasterLayer has no filename; and no filename specified as argument to writeRaster')
+ }
+
if (! dataContent(raster) %in% c('row', 'rows', 'all', 'sparse') ) {
stop('No usable data available for writing.')
}
@@ -21,6 +29,10 @@
}
} else if (filetype=='ascii') {
raster <- .writeAscii(raster, overwrite=overwrite)
+
+ } else if (filetype=='CDF') {
+ raster <- .writeRasterCDF(raster, overwrite=overwrite)
+
} else {
.isSupportedGDALFormat(filetype)
if (dataContent(raster) == 'row' ) {
Deleted: pkg/raster/man/CDF.Rd
===================================================================
--- pkg/raster/man/CDF.Rd 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/man/CDF.Rd 2009-09-08 19:05:55 UTC (rev 481)
@@ -1,47 +0,0 @@
-\name{CDF}
-\docType{methods}
-
-\alias{CDF}
-\alias{CDF,RasterLayer,character-method}
-\alias{CDF,RasterStack,character-method}
-
-\title{Write a RasterLayer or RasterStack to a netCDF file}
-
-\description{
-Read the contents of a netCDF file into a RasterLayer or RasterStack object. Currently all the data are loaded into memory (
-unlike with other formats), but this will likely change in the future.
-}
-
-\usage{
-CDF(x, y, ...)
-}
-
-\arguments{
-\item{x}{Raster* object}
-\item{y}{filename}
-\item{...}{}
-}
-
-\value{
-Nothing. Function is used for the side effect of creating a netCDF file.
-}
-
-\details{
- For this function to work, the RNetCDF package needs to have been installed.
-}
-
-\author{Robert J. Hijmans}
-
-\seealso{ \code{\link[raster]{rasterCDF} } }
-
-\examples{
- fn <- 'test.nc'
- r <- raster(nrow=18, ncol=36)
- r[] <- 1:ncell(r)
- CDF(r, fn)
- r2 <- raster(fn)
-}
-
-\keyword{methods}
-\keyword{spatial}
-
Modified: pkg/raster/man/RasterLayer-class.Rd
===================================================================
--- pkg/raster/man/RasterLayer-class.Rd 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/man/RasterLayer-class.Rd 2009-09-08 19:05:55 UTC (rev 481)
@@ -80,7 +80,7 @@
\item{show}{\code{signature(object = "RasterLayer")}: ... }
\item{summary}{\code{signature(object = "RasterLayer")}: ... }
- \item{asRasterLayer}{\code{signature(object = "RasterStack")}: ... }
+ \item{raster}{\code{signature(object = "RasterStack")}: ... }
\item{show}{\code{signature(object = "RasterStack")}: ... }
\item{summary}{\code{signature(object = "RasterStack")}: ... }
Modified: pkg/raster/man/aggregate.Rd
===================================================================
--- pkg/raster/man/aggregate.Rd 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/man/aggregate.Rd 2009-09-08 19:05:55 UTC (rev 481)
@@ -38,7 +38,7 @@
\tab \code{na.rm} \tab logical. If \code{TRUE}, remove NA cells from calculations \cr
\tab \code{filename} \tab character. output filename \cr
\tab \code{overwrite} \tab logical. If \code{TRUE}, "filename" will be overwritten if it exists \cr
-\tab \code{filetype} \tab character. output file type. Either 'raster', 'ascii' or a supported GDAL 'driver' name see \code{\link[raster]{rasterFormats}} \cr
+\tab \code{filetype} \tab character. output file type. Either 'raster', 'ascii' or a supported GDAL 'driver' name see \code{\link[raster]{writeFormats}} \cr
\tab \code{datatype} \tab character. output data type; see \code{\link[raster]{dataType}} \cr
\tab \code{track} \tab vector of row numbers for which the function will report that they have been processed \cr
}
Modified: pkg/raster/man/distance.Rd
===================================================================
--- pkg/raster/man/distance.Rd 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/man/distance.Rd 2009-09-08 19:05:55 UTC (rev 481)
@@ -26,7 +26,7 @@
\item{object}{a RasterLayer object}
\item{filename}{character. output filename}
\item{overwrite}{logical. If \code{TRUE}, "filename" will be overwritten if it exists}
-\item{filetype}{character. output file type. Either 'raster', 'ascii' or a supported GDAL 'driver' name see \code{\link[raster]{rasterFormats}}}
+\item{filetype}{character. output file type. Either 'raster', 'ascii' or a supported GDAL 'driver' name see \code{\link[raster]{writeFormats}}}
\item{datatype}{character. output data type; see \code{\link[raster]{dataType}}}
\item{track}{vector of row numbers for which the function will report that they have been processed}
}
Deleted: pkg/raster/man/intersectBbox.Rd
===================================================================
--- pkg/raster/man/intersectBbox.Rd 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/man/intersectBbox.Rd 2009-09-08 19:05:55 UTC (rev 481)
@@ -1,35 +0,0 @@
-\name{intersectExtent}
-
-\alias{intersectExtent}
-
-\title{BoundingExtent intersection}
-
-\description{
-intersectExtent returns the instersection of multiple bounding boxes
-}
-
-\usage{
-intersectExtent(x, ...)
-}
-
-\arguments{
- \item{x}{A BoundingBox or Raster* object }
- \item{...}{ additional BoundingBox or Raster* objects }
-}
-
-\value{
-a BoundingBox object
-}
-
-\author{Robert J. Hijmans}
-
-\seealso{ \code{\link[raster]{unionExtent}}, \code{\link[raster]{getBoungingBox}}, \code{\link[raster]{setBoungingBox}} }
-
-\examples{
-r <- raster()
-b1 <- newExtent(-10, 10, -20, 20)
-b2 <- newExtent(0, 20, -40, 5)
-i <- intersectExtent(b1, b2)
-}
-
-\keyword{spatial}
Added: pkg/raster/man/intersectExtent.Rd
===================================================================
--- pkg/raster/man/intersectExtent.Rd (rev 0)
+++ pkg/raster/man/intersectExtent.Rd 2009-09-08 19:05:55 UTC (rev 481)
@@ -0,0 +1,35 @@
+\name{intersectExtent}
+
+\alias{intersectExtent}
+
+\title{BoundingExtent intersection}
+
+\description{
+intersectExtent returns the instersection of multiple bounding boxes
+}
+
+\usage{
+intersectExtent(x, ...)
+}
+
+\arguments{
+ \item{x}{A BoundingBox or Raster* object }
+ \item{...}{ additional BoundingBox or Raster* objects }
+}
+
+\value{
+a BoundingBox object
+}
+
+\author{Robert J. Hijmans}
+
+\seealso{ \code{\link[raster]{unionExtent}}, \code{\link[raster]{extent}}, \code{\link[raster]{setExtent}} }
+
+\examples{
+r <- raster()
+b1 <- newExtent(-10, 10, -20, 20)
+b2 <- newExtent(0, 20, -40, 5)
+i <- intersectExtent(b1, b2)
+}
+
+\keyword{spatial}
Modified: pkg/raster/man/merge.Rd
===================================================================
--- pkg/raster/man/merge.Rd 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/man/merge.Rd 2009-09-08 19:05:55 UTC (rev 481)
@@ -37,7 +37,7 @@
\item{\code{tolerance}}{difference permissable (relative to the cell resolution) for objects to be 'equal'. See ?all.equal}
\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{filetype}}{character. output file type. Either 'raster', 'ascii' or a supported GDAL 'driver' name see \code{\link[raster]{writeFormats}}}
\item{\code{datatype}}{character. output data type; see \code{\link[raster]{dataType}}}
\item{\code{track}}{vector of row numbers for which the function will report that they have been processed}
}
Deleted: pkg/raster/man/newBbox.Rd
===================================================================
--- pkg/raster/man/newBbox.Rd 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/man/newBbox.Rd 2009-09-08 19:05:55 UTC (rev 481)
@@ -1,47 +0,0 @@
-\name{newExtent}
-
-\alias{newExtent}
-\alias{alignBbox}
-
-\title{create or align an Extent}
-
-\description{
-
-newExtent creates a new Extent object
-
-alignBbox aligns a bounding box with the cells of a Raster* object
-}
-
-\usage{
-newExtent(xmn, xmx, ymn, ymx)
-alignBbox(bndbox, object)
-}
-
-\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{bndbox}{An object of class BoundingBox (which you can create with newExtent() )}
- \item{object}{A Raster* object}
-}
-
-\value{
-a BoundingBox object
-}
-
-\author{Robert J. Hijmans}
-
-\seealso{ \code{\link[raster]{getBoungingBox}}, \code{\link[raster]{BoungingBox-class}}, \code{\link[raster]{clickBbox}} }
-
-\examples{
-r <- raster()
-bb <- newExtent(-10.1, 10.1, -20.1, 20.1)
-bba <- alignBbox(bb, r)
-bb
-extent(r)
-bba
-
-}
-
-\keyword{spatial}
Added: pkg/raster/man/newExtent.Rd
===================================================================
--- pkg/raster/man/newExtent.Rd (rev 0)
+++ pkg/raster/man/newExtent.Rd 2009-09-08 19:05:55 UTC (rev 481)
@@ -0,0 +1,47 @@
+\name{newExtent}
+
+\alias{newExtent}
+\alias{alignBbox}
+
+\title{create or align an Extent}
+
+\description{
+
+newExtent creates a new Extent object
+
+alignBbox aligns a bounding box with the cells of a Raster* object
+}
+
+\usage{
+newExtent(xmn, xmx, ymn, ymx)
+alignBbox(bndbox, object)
+}
+
+\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{bndbox}{An object of class BoundingBox (which you can create with newExtent() )}
+ \item{object}{A Raster* object}
+}
+
+\value{
+a BoundingBox object
+}
+
+\author{Robert J. Hijmans}
+
+\seealso{ \code{\link[raster]{extent}}, \code{\link[raster]{drawBox}}, \code{\link[raster]{BoungingBox-class}} }
+
+\examples{
+r <- raster()
+bb <- newExtent(-10.1, 10.1, -20.1, 20.1)
+bba <- alignBbox(bb, r)
+bb
+extent(r)
+bba
+
+}
+
+\keyword{spatial}
Modified: pkg/raster/man/raster.Rd
===================================================================
--- pkg/raster/man/raster.Rd 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/man/raster.Rd 2009-09-08 19:05:55 UTC (rev 481)
@@ -48,10 +48,11 @@
\tab \code{time} \tab integer > 0. For netCDF files only: identify which of the time variables you want (default=1)\cr
}
-If \code{x} is a character value, it should be a filename of a file that the raster package can read. Supported file types are the
-'native' raster package format and those that can be read via rgdal. See \code{\link[rgdal]{readGDAL}} help for supported file types. For netCDF files, see \code{\link[raster]{rasterCDF}}
+If \code{x} is a character value, it should be a filename of a file that the raster package can read. Supported file types are the 'native' raster package format and those that can be read via rgdal. See \code{\link[rgdal]{readGDAL}} help for supported file types.
+For netCDF files, the function will try to guess values for the \code{xvar}, \code{yvar}, and \code{zvar} if they are not supplied. For this function to work, the RNetCDF package needs to have been installed. Note that currently, a raster object made from a netCDF file will load all values from file at creation (unlike other raster objects), and that 'read' functions are therefore not applicable.
+
2) Create a RasterLayer object from scratch
\code{raster(nrows=180, ncols=360, xmn=-180, xmx=180, ymn=-90, ymx=90, projs="+proj=longlat +datum=WGS84")}
Deleted: pkg/raster/man/rasterCDF.Rd
===================================================================
--- pkg/raster/man/rasterCDF.Rd 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/man/rasterCDF.Rd 2009-09-08 19:05:55 UTC (rev 481)
@@ -1,41 +0,0 @@
-\name{rasterCDF}
-
-\alias{rasterCDF}
-\alias{stackCDF}
-
-\title{Read a netCDF file}
-
-\description{Read the contents of a netCDF file into a RasterLayer or RasterStack object. Currently all the data are loaded into memory (unlike with other formats), but this will likely change in the future.
-}
-
-\usage{
-rasterCDF(filename, xvar='', yvar='', zvar='', time=1)
-}
-
-\arguments{
-\item{filename}{filename}
-\item{xvar}{x variable in the file (e.g. 'longitude')}
-\item{yvar}{y variable in the file (e.g. 'latitude')}
-\item{zvar}{z variable in the file (e.g. 'altitude', or 'precipitation)}
-\item{time}{numer of time steps in the file (default is 1)}
-}
-
-\value{
-a Raster* object
-}
-
-\details{
- The function will try to guess values for the xvar, yvar, and zvar if they are not supplied.
-
- For this function to work, the RNetCDF package needs to have been installed.
-}
-
-\author{Robert J. Hijmans}
-
-\seealso{ \code{\link[raster]{raster}, \link[raster]{stack} } }
-
-\examples{
-}
-
-\keyword{spatial}
-
Modified: pkg/raster/man/writeRaster.Rd
===================================================================
--- pkg/raster/man/writeRaster.Rd 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/man/writeRaster.Rd 2009-09-08 19:05:55 UTC (rev 481)
@@ -10,12 +10,13 @@
}
\usage{
-writeRaster(raster, filetype='raster', overwrite=FALSE, assign=FALSE)
+writeRaster(raster, filetype='raster', filename='', overwrite=FALSE, assign=FALSE)
}
\arguments{
\item{raster}{RasterLayer object}
\item{filetype}{either 'raster', 'ascii' or a supported GDAL 'driver' name (see below)}
+ \item{filename}{Character. If omitted, the filename of the RasterLayer object is used (if it has one)}
\item{overwrite}{Logical. If \code{TRUE} existing files are overwritten}
\item{assign}{Logical. If \code{TRUE} the function does not return a new object but overwrites the existing object}
}
@@ -24,7 +25,7 @@
Values in a \code{RasterLayer} object are written to a file. Relatively small datasets can be loaded into memory, manipulated, and saved to disk in their entirety.
Large datasets can be read and written row by row.
When writing by row, you must write all rows, and you must write them in sequence. Start at row=1, and end at row=nrow(raster). You cannot overwrite a single row in an existing raster file.
-See \code{writeFormats} for supported file types ("formats", "drivers").
+See \code{writeFormats} for supported file types ("formats", "drivers"); the rgdal package is needed for this function, exxcept for the 'raster', ascii, and 'CDF' formats.
Supported file types include:
@@ -32,6 +33,7 @@
\tab \bold{file type} \tab \bold{Long name} \cr
\tab \code{raster} \tab 'Native' raster package format \cr
\tab \code{ascii} \tab ESRI Ascii \cr
+ \tab \code{CDF} \tab netCDF (requires RNetCDF)\cr
\tab \code{ENVI} \tab ENVI .hdr Labelled \cr
\tab \code{EHdr} \tab ESRI .hdr Labelled \cr
\tab \code{ERS} \tab ERMapper .ers Labelled \cr
@@ -82,7 +84,8 @@
# read and write row by row; write to ascii file
rst <- raster(system.file("external/test.ag", package="sp"))
-ascras <- raster(rst, filename="ascrow.asc")
+ascras <- raster(rst)
+filename(ascras) <- "ascrow.asc"
for (r in 1:nrow(rst)) {
rst <- readRow(rst, r)
v <- values(rst) * 10
@@ -99,13 +102,20 @@
}
# read and write row by row; write to GeoTiff binary file
-binras <- raster(rst, filename="binbyrow2.tif")
+binras <- raster(rst)
+filename(binras) <- "binbyrow2.tif"
for (r in 1:nrow(rst)) {
rst <- readRow(rst, r)
binras <- setValues(binras, values(rst), r)
binras <- writeRaster(binras, filetype="GTiff", overwrite=TRUE)
}
+# write to netcdf
+if (require(RNetCDF)) {
+ rst <- readAll(rst)
+ writeRaster(rst, filetype="CDF", filename="netCDF.nc", overwrite=TRUE)
}
+}
+
\keyword{ spatial }
Modified: pkg/raster/man/writeStack.Rd
===================================================================
--- pkg/raster/man/writeStack.Rd 2009-09-08 05:28:49 UTC (rev 480)
+++ pkg/raster/man/writeStack.Rd 2009-09-08 19:05:55 UTC (rev 481)
@@ -20,7 +20,7 @@
\item{bandorder}{BIL, BIP, or BSQ}
\item{filename}{character. output filename}
\item{overwrite}{logical. If \code{TRUE}, "filename" will be overwritten if it exists}
-\item{filetype}{character. output file type. Either 'raster', 'ascii' or a supported GDAL 'driver' name see \code{\link[raster]{rasterFormats}}}
+\item{filetype}{character. output file type. Either 'raster', 'ascii' or a supported GDAL 'driver' name see \code{\link[raster]{writeFormats}}}
\item{datatype}{character. output data type; see \code{\link[raster]{dataType}}}
}
More information about the Raster-commits
mailing list