[Raster-commits] r478 - in pkg/raster: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Sep 5 06:56:25 CEST 2009
Author: rhijmans
Date: 2009-09-05 06:56:24 +0200 (Sat, 05 Sep 2009)
New Revision: 478
Modified:
pkg/raster/R/raster.R
pkg/raster/R/rasterFromNetCDF.R
pkg/raster/man/raster.Rd
Log:
Modified: pkg/raster/R/raster.R
===================================================================
--- pkg/raster/R/raster.R 2009-09-05 04:19:38 UTC (rev 477)
+++ pkg/raster/R/raster.R 2009-09-05 04:56:24 UTC (rev 478)
@@ -63,8 +63,9 @@
} else if (file.exists( x )){
if (fileext == '.NC') {
r <- rasterCDF(x, ...)
+ } else {
+ r <- .rasterFromGDAL(x, band)
}
- r <- .rasterFromGDAL(x, band)
} else {
stop(paste('file', x, 'does not exist'))
}
Modified: pkg/raster/R/rasterFromNetCDF.R
===================================================================
--- pkg/raster/R/rasterFromNetCDF.R 2009-09-05 04:19:38 UTC (rev 477)
+++ pkg/raster/R/rasterFromNetCDF.R 2009-09-05 04:56:24 UTC (rev 478)
@@ -44,6 +44,7 @@
return(r)
}
+
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() }
@@ -57,8 +58,16 @@
zvar <- .getzvar(zvar, vars)
r <- .getraster(nc, xvar, yvar, zvar)
d <- var.get.nc(nc, zvar)
- d <- d[,,time]
close.nc(nc)
+
+ dims <- dim(d)
+
+ if (length(dims)== 2) {
+ d <- as.vector(d)
+ } else if (length(dims)== 3) {
+ d <- as.vector(d[,,time])
+ } else { stop(paste('data has an unexpected number of dimensions', dims)) }
+
# y needs to go from big to small
d <- matrix(d, ncol=ncol(r), nrow=nrow(r), byrow=TRUE)
d <- as.vector( t( d[nrow(r):1,] ) )
@@ -68,7 +77,6 @@
-
stackCDF <- 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() }
@@ -91,7 +99,7 @@
} else if (length(dims)== 3) { tsteps <- 1
} else if (length(dims)== 2) {
return(stack(rasterCDF(filename, xvar, yvar, zvar)))
- } else { stop('data has unexpected dimensions') }
+ } else { stop(paste('data has an unexpected number of dimensions', dims)) }
for (i in 1:tsteps) {
Modified: pkg/raster/man/raster.Rd
===================================================================
--- pkg/raster/man/raster.Rd 2009-09-05 04:19:38 UTC (rev 477)
+++ pkg/raster/man/raster.Rd 2009-09-05 04:56:24 UTC (rev 478)
@@ -21,8 +21,8 @@
\arguments{
- \item{x}{a filename, BoundingBox, Raster*, SpatialPixels*, SpatialGrid* object, or missing}
- \item{...}{ additional argumens }
+ \item{x}{a filename, BoundingBox, Raster*, SpatialPixels*, SpatialGrid* object, matrix, or missing}
+ \item{...}{ additional argumens, see below }
}
\usage{
@@ -38,17 +38,20 @@
\tabular{rll}{
-\tab \code{x} \tab character. name of raster file \cr
+\tab \code{x} \tab character. Name of raster file \cr
\tab \code{values} \tab logical. If \code{TRUE}, RasterLayer values are read into memory with \code{\link[raster]{readAll}} \cr
-\tab \code{band} \tab band number in case of a file of multiple bands, default = 1 \cr
-\tab \code{projs} \tab Character. PROJ4 type description of a Coordinate Reference System (map projection). If NULL, the value stored on disk (if any and recognised) is used \cr
+\tab \code{band} \tab integer. Band number in case of a file of multiple bands, default = 1 \cr
+\tab \code{projs} \tab character. PROJ4 type description of a Coordinate Reference System (map projection). If NULL, the value stored on disk (if any and recognised) is used \cr
+\tab \code{xvar} \tab character. For netCDF files only: identify the x variable (e.g. 'longitude' or 'x') \cr
+\tab \code{yvar} \tab character. For netCDF files only: identify the y variable (e.g. 'latitude' or 'y')\cr
+\tab \code{zvar} \tab character. For netCDF files only: identify the z variable (e.g. 'altitide' or 'precipitation')\cr
+\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.
+'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}}
-
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")}
More information about the Raster-commits
mailing list