[Raster-commits] r479 - in pkg/raster: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Sep 6 06:40:32 CEST 2009


Author: rhijmans
Date: 2009-09-06 06:40:31 +0200 (Sun, 06 Sep 2009)
New Revision: 479

Added:
   pkg/raster/R/extent.R
   pkg/raster/R/rasterToNetCDF.R
   pkg/raster/man/CDF.Rd
Removed:
   pkg/raster/R/getBbox.R
Modified:
   pkg/raster/R/rasterFromNetCDF.R
   pkg/raster/man/NAvalue.Rd
   pkg/raster/man/rasterCDF.Rd
Log:


Added: pkg/raster/R/extent.R
===================================================================
--- pkg/raster/R/extent.R	                        (rev 0)
+++ pkg/raster/R/extent.R	2009-09-06 04:40:31 UTC (rev 479)
@@ -0,0 +1,67 @@
+# R function for the raster package
+# Author: Robert J. Hijmans
+# International Rice Research Institute. Philippines
+# contact: r.hijmans at gmail.com
+# Date : January 2009
+# Version 0.8
+# Licence GPL v3
+
+
+
+if (!isGeneric("extent")) {
+	setGeneric("extent", function(x, ...)
+		standardGeneric("extent"))
+}	
+
+setMethod('extent', signature(x='BoundingBox'), 
+	function(x){ return(x) }
+)
+
+setMethod('extent', signature(x='BasicRaster'), 
+	function(x){ return(x at bbox) }
+)
+
+setMethod('extent', signature(x='Spatial'), 
+	function(x){ 
+		bndbox <- bbox(x)
+		bb <- new('BoundingBox')
+		bb at xmin <- bndbox[1,1]
+		bb at xmax <- bndbox[1,2]
+		bb at ymin <- bndbox[2,1]
+		bb at ymax <- bndbox[2,2]
+		return(bb) 
+	}
+)
+
+setMethod('extent', signature(x='matrix'), 
+	function(x){ 
+		if (min(dim(x)) < 2) {
+			stop('matrix should have dimensions of at least 2 by 2') }		
+		bb <- new('BoundingBox')
+		bb at xmin <- x[1,1]
+		bb at xmax <- x[1,2]
+		bb at ymin <- x[2,1]
+		bb at ymax <- x[2,2]
+		return(bb)
+	}
+)
+	
+setMethod('extent', signature(x='numeric'), 
+	function(x, ...){ 
+		dots <- unlist(list(...))
+		x <- c(x, dots)
+		if (length(x) < 4) {
+			stop('insufficient number of elements (should be 4)')
+		}
+		if (length(x) > 4) {
+			warning('more elements than expected (should be 4)')
+		}
+		bb <- new('BoundingBox')
+		bb at xmin <- x[1]
+		bb at xmax <- x[2]
+		bb at ymin <- x[3]
+		bb at ymax <- x[4]
+		return(bb)
+	}	
+)
+

Deleted: pkg/raster/R/getBbox.R
===================================================================
--- pkg/raster/R/getBbox.R	2009-09-05 04:56:24 UTC (rev 478)
+++ pkg/raster/R/getBbox.R	2009-09-06 04:40:31 UTC (rev 479)
@@ -1,67 +0,0 @@
-# R function for the raster package
-# Author: Robert J. Hijmans
-# International Rice Research Institute. Philippines
-# contact: r.hijmans at gmail.com
-# Date : January 2009
-# Version 0.8
-# Licence GPL v3
-
-
-
-if (!isGeneric("extent")) {
-	setGeneric("extent", function(x, ...)
-		standardGeneric("extent"))
-}	
-
-setMethod('extent', signature(x='BoundingBox'), 
-	function(x){ return(x) }
-)
-
-setMethod('extent', signature(x='BasicRaster'), 
-	function(x){ return(x at bbox) }
-)
-
-setMethod('extent', signature(x='Spatial'), 
-	function(x){ 
-		bndbox <- bbox(x)
-		bb <- new('BoundingBox')
-		bb at xmin <- bndbox[1,1]
-		bb at xmax <- bndbox[1,2]
-		bb at ymin <- bndbox[2,1]
-		bb at ymax <- bndbox[2,2]
-		return(bb) 
-	}
-)
-
-setMethod('extent', signature(x='matrix'), 
-	function(x){ 
-		if (min(dim(x)) < 2) {
-			stop('matrix should have dimensions of at least 2 by 2') }		
-		bb <- new('BoundingBox')
-		bb at xmin <- x[1,1]
-		bb at xmax <- x[1,2]
-		bb at ymin <- x[2,1]
-		bb at ymax <- x[2,2]
-		return(bb)
-	}
-)
-	
-setMethod('extent', signature(x='numeric'), 
-	function(x, ...){ 
-		dots <- unlist(list(...))
-		x <- c(x, dots)
-		if (length(x) < 4) {
-			stop('insufficient number of elements (should be 4)')
-		}
-		if (length(x) > 4) {
-			warning('more elements than expected (should be 4)')
-		}
-		bb <- new('BoundingBox')
-		bb at xmin <- x[1]
-		bb at xmax <- x[2]
-		bb at ymin <- x[3]
-		bb at ymax <- x[4]
-		return(bb)
-	}	
-)
-

Modified: pkg/raster/R/rasterFromNetCDF.R
===================================================================
--- pkg/raster/R/rasterFromNetCDF.R	2009-09-05 04:56:24 UTC (rev 478)
+++ pkg/raster/R/rasterFromNetCDF.R	2009-09-06 04:40:31 UTC (rev 479)
@@ -49,7 +49,6 @@
 # to be improved for large files (i.e. do not read all data from file...)
 	if (!require(RNetCDF)) { stop() }
 	nc <- open.nc(filename)
-# should do some checks if x, y and z are present. Or perhaps lat and lon in stead of x	
 	nv <- file.inq.nc(nc)$nvars
     vars <- vector()
 	for (i in 1:nv) { vars <- c(var.inq.nc(nc,i-1)$name, vars) }
@@ -81,7 +80,6 @@
 # to be improved for large files (i.e. do not read all data from file...)
 	if (!require(RNetCDF)) { stop() }
 	nc <- open.nc(filename)
-# should do some checks if x, y and z are present. Or perhaps lat and lon in stead of x	
 
 	nv <- file.inq.nc(nc)$nvars
     vars <- vector()

Added: pkg/raster/R/rasterToNetCDF.R
===================================================================
--- pkg/raster/R/rasterToNetCDF.R	                        (rev 0)
+++ pkg/raster/R/rasterToNetCDF.R	2009-09-06 04:40:31 UTC (rev 479)
@@ -0,0 +1,66 @@
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# Date: Aug 2009
+# Version 0.8
+# Licence GPL v3
+
+
+
+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') {
+			x <- readAll(x)
+		}
+		zvar <- values(x)
+		if (class(zvar) == 'numeric') {
+			dtype <- 'NC_DOUBLE'
+		} else {
+			dtype <- 'NC_INT' 
+		}
+		zvar <- t(matrix(zvar, ncol=ncol(x), nrow=nrow(x)))
+		zvar <- t(zvar[nrow(zvar):1, ])
+		nc <- create.nc(y, 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.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()))
+
+		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){ 
+		if (!require(RNetCDF)) { stop() }	
+	
+	}
+)
+
+

Added: pkg/raster/man/CDF.Rd
===================================================================
--- pkg/raster/man/CDF.Rd	                        (rev 0)
+++ pkg/raster/man/CDF.Rd	2009-09-06 04:40:31 UTC (rev 479)
@@ -0,0 +1,47 @@
+\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/NAvalue.Rd
===================================================================
--- pkg/raster/man/NAvalue.Rd	2009-09-05 04:56:24 UTC (rev 478)
+++ pkg/raster/man/NAvalue.Rd	2009-09-06 04:40:31 UTC (rev 479)
@@ -24,7 +24,7 @@
 
 
 \value{
-a Raster* object
+Returns or set the NA value used for storage on disk.
 }
 
 

Modified: pkg/raster/man/rasterCDF.Rd
===================================================================
--- pkg/raster/man/rasterCDF.Rd	2009-09-05 04:56:24 UTC (rev 478)
+++ pkg/raster/man/rasterCDF.Rd	2009-09-06 04:40:31 UTC (rev 479)
@@ -26,6 +26,8 @@
 
 \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}
@@ -35,6 +37,5 @@
 \examples{
 }
 
-\keyword{methods}
 \keyword{spatial}
 



More information about the Raster-commits mailing list