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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Feb 27 03:41:45 CET 2009


Author: rhijmans
Date: 2009-02-27 03:41:41 +0100 (Fri, 27 Feb 2009)
New Revision: 302

Added:
   pkg/raster/man/saveAs.Rd
Modified:
   pkg/raster/R/canProcessInMemory.R
   pkg/raster/R/copyRaster.R
   pkg/raster/R/filenames.R
   pkg/raster/R/group.generic.functions.R
   pkg/raster/R/properties.R
   pkg/raster/R/replacement.R
   pkg/raster/R/set.R
   pkg/raster/man/Arith-methods.Rd
   pkg/raster/man/misc.Rd
   pkg/raster/man/setDatatype.Rd
Log:


Modified: pkg/raster/R/canProcessInMemory.R
===================================================================
--- pkg/raster/R/canProcessInMemory.R	2009-02-26 09:52:20 UTC (rev 301)
+++ pkg/raster/R/canProcessInMemory.R	2009-02-27 02:41:41 UTC (rev 302)
@@ -5,16 +5,16 @@
 # Licence GPL v3
 
 
-.CanProcessInMemory <- function(raster, n=2) {
+.CanProcessInMemory <- function(raster, n=4) {
 	if (ncell(raster) > 2147483647) {
 		return(FALSE) 
 	}
 	cells <- round(1.05 * ncell(raster))
 	gc()
-	w <- options('warn')
+	w <- options('warn')[[1]]
 	options('warn'=-1) 
 	r <- try( matrix(NA, ncol=n, nrow=cells), silent=TRUE )
-	options('warn'=w[[1]]) 
+	options('warn'= w) 
 	if (class(r) == "try-error") {
 #	if (memneed > memory.size(max = T)) {
 		return( FALSE )

Modified: pkg/raster/R/copyRaster.R
===================================================================
--- pkg/raster/R/copyRaster.R	2009-02-26 09:52:20 UTC (rev 301)
+++ pkg/raster/R/copyRaster.R	2009-02-27 02:41:41 UTC (rev 302)
@@ -24,7 +24,7 @@
 	newr <- setDatatype(newr, datatype)
 	for (r in 1:nrow(newr)) {
 		raster <- readRow(raster, r)
-		newr <- setValues(newr, values(raster))
+		newr <- setValues(newr, values(raster), r)
 		newr <- writeRaster(newr, filetype=filetype, overwrite=overwrite)
 	}
 	return(newr)

Modified: pkg/raster/R/filenames.R
===================================================================
--- pkg/raster/R/filenames.R	2009-02-26 09:52:20 UTC (rev 301)
+++ pkg/raster/R/filenames.R	2009-02-27 02:41:41 UTC (rev 302)
@@ -13,7 +13,7 @@
 }  
 
 
-fileName <- function(filename) {
+shortFileName <- function(filename) {
     filename <- gsub("\\\\", "/", filename)
 	if (filename == "") {return(filename)
 	} else {
@@ -26,7 +26,7 @@
    
 filePath <- function(filename) {
     filename <- gsub("\\\\", "/", filename)
-	file <- fileName(filename)
+	file <- shortFileName(filename)
 	path <- gsub(file, '', filename)
 	return(path)
 }   

Modified: pkg/raster/R/group.generic.functions.R
===================================================================
--- pkg/raster/R/group.generic.functions.R	2009-02-26 09:52:20 UTC (rev 301)
+++ pkg/raster/R/group.generic.functions.R	2009-02-27 02:41:41 UTC (rev 302)
@@ -51,7 +51,7 @@
 
 setMethod("Math", signature(x='RasterLayer'),
     function(x){ 
-		if (.CanProcessInMemory(x, 1)) {
+		if (.CanProcessInMemory(x, 3)) {
 			raster <- setRaster(x, values=callGeneric(.getRasterValues(x)))
 		} else {
 			raster <- setRaster(x, filename=tempfile())
@@ -73,7 +73,7 @@
 setMethod("Arith", signature(e1='RasterLayer', e2='RasterLayer'),
     function(e1, e2){ 
 		if ( compare(c(e1, e2)) ) {
-			if (.CanProcessInMemory(e1, 3)) {
+			if (.CanProcessInMemory(e1, 4)) {
 				raster <- setRaster(e1, values=callGeneric( as.numeric(.getRasterValues(e1)), .getRasterValues(e2)))
 			} else {
 				raster <- setRaster(e1, filename=tempfile())
@@ -93,7 +93,7 @@
 
 setMethod("Arith", signature(e1='RasterLayer', e2='numeric'),
     function(e1, e2){ 
-		if (.CanProcessInMemory(e1, 2)) {
+		if (.CanProcessInMemory(e1, 3)) {
 			return(setRaster(e1, values=callGeneric(as.numeric(.getRasterValues(e1)), e2) ) )
 		} else {
 			raster <- setRaster(e1, filename=tempfile())
@@ -111,7 +111,7 @@
 
 setMethod("Arith", signature(e1='numeric', e2='RasterLayer'),
     function(e1, e2){ 
-		if (.CanProcessInMemory(e2, 2)) {
+		if (.CanProcessInMemory(e2, 3)) {
 			return(setRaster(e2, values=callGeneric(as.numeric(e1), .getRasterValues(e2))))
 		} else {
 			raster <- setRaster(e2, filename=tempfile())

Modified: pkg/raster/R/properties.R
===================================================================
--- pkg/raster/R/properties.R	2009-02-26 09:52:20 UTC (rev 301)
+++ pkg/raster/R/properties.R	2009-02-27 02:41:41 UTC (rev 302)
@@ -116,7 +116,7 @@
 }
 
 dataType <- function(object) {
-	return(object at file@datatype)
+	return(object at file@datanotation)
 }
 
 

Modified: pkg/raster/R/replacement.R
===================================================================
--- pkg/raster/R/replacement.R	2009-02-26 09:52:20 UTC (rev 301)
+++ pkg/raster/R/replacement.R	2009-02-27 02:41:41 UTC (rev 302)
@@ -8,6 +8,10 @@
 	return( setFilename(x, value) )
 }
 
+'datatype<-' <- function(x, value) {
+	return( setDatatype(x, value) )
+}
+
 'projection<-' <- function(x, value) {
 	return( setProjection(x, value) )
 }

Modified: pkg/raster/R/set.R
===================================================================
--- pkg/raster/R/set.R	2009-02-26 09:52:20 UTC (rev 301)
+++ pkg/raster/R/set.R	2009-02-27 02:41:41 UTC (rev 302)
@@ -1,7 +1,7 @@
 # Author: Robert J. Hijmans, r.hijmans at gmail.com
 # International Rice Research Institute
 # Date :  June 2008
-# Version 0,6
+# Version 0.8
 # Licence GPL v3
 
 .addHistory <- function(raster, message) {
@@ -59,7 +59,7 @@
 		object at file@name <- filename
 	}	
 	if (class(object)=='RasterLayer') {
-		shortname <- fileName(filename)
+		shortname <- shortFileName(filename)
 		shortname <- setFileExtension(shortname, "")
 		shortname <- gsub(" ", "_", shortname)
 		if (nbands(object) > 1) { shortname <- paste(shortname, "_", band(object)) } 

Modified: pkg/raster/man/Arith-methods.Rd
===================================================================
--- pkg/raster/man/Arith-methods.Rd	2009-02-26 09:52:20 UTC (rev 301)
+++ pkg/raster/man/Arith-methods.Rd	2009-02-27 02:41:41 UTC (rev 302)
@@ -17,7 +17,7 @@
 \examples{
 r1 <- raster(ncols=10, nrows=10)
 r1 <- setValues(r1, runif(ncell(r1)))
-r2 <- setValues(r1, 1:ncell(r1)) / ncell(r1)
+r2 <- setValues(r1, 1:ncell(r1) / ncell(r1) )
 r3 <- r1 * (r2 - 1 + r1^2 / r2)
 }
 

Modified: pkg/raster/man/misc.Rd
===================================================================
--- pkg/raster/man/misc.Rd	2009-02-26 09:52:20 UTC (rev 301)
+++ pkg/raster/man/misc.Rd	2009-02-27 02:41:41 UTC (rev 302)
@@ -1,7 +1,7 @@
 \name{miscellanous}
 \alias{setFileExtension}
 \alias{fileExtension}
-\alias{fileName}
+\alias{shortFileName}
 \alias{filePath}
 \alias{trim}
 
@@ -12,12 +12,12 @@
 \usage{
 setFileExtension(filename, newextension)
 fileExtension(filename)
-fileName(filename)
+shortFileName(filename)
 filePath(filename)
 trim(astring)
 }
 \arguments{
-  \item{filename}{A filename with or without the path}
+  \item{filename}{A file name, with or without the path}
   \item{newextension}{A file extension, e.g., ".txt" }
   \item{astring}{A string that needs to be trimmed}
 }
@@ -33,7 +33,7 @@
 	fn <- trim(fn)
 	fileExtension(fn)
 	setFileExtension(fn, ".txt")
-	fileName(fn)
+	shortFileName(fn)
 	filePath(fn)
 }
 \keyword{file}

Added: pkg/raster/man/saveAs.Rd
===================================================================
--- pkg/raster/man/saveAs.Rd	                        (rev 0)
+++ pkg/raster/man/saveAs.Rd	2009-02-27 02:41:41 UTC (rev 302)
@@ -0,0 +1,56 @@
+\name{saveAs}
+
+\alias{saveAs}
+
+\title{Save a raster file to a different format}
+
+\description{
+  Save a raster file (on disk) to another format. 
+}
+
+\usage{
+  saveAs(raster, filename, filetype='raster', datatype='FLT4S', overwrite=FALSE)
+}
+
+\arguments{
+  \item{raster}{RasterLayer object}
+  \item{filename}{output filename}  
+  \item{filetype}{either 'raster', 'ascii' or a supported GDAL 'driver' name (see below)}
+  \item{datatype}{output data type; see below}
+  \item{overwrite}{Logical. If \code{TRUE} existing files are overwritten}
+}
+
+\details{
+
+Supported datatypes include:
+
+\tabular{rll}{
+	\tab \code{\bold{format}} \tab \bold{Long name} \cr
+    \tab \code{raster} \tab 'Native' raster package format \cr
+    \tab \code{ascii}  \tab ESRI Ascii \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
+    \tab \code{GTiff}  \tab GeoTiff \cr
+    \tab \code{HFAErdas}  \tab Imagine Images (.img) \cr
+    \tab \code{ILWIS}   \tab ILWIS Raster Map \cr
+    \tab \code{PAux}   \tab PCI .aux Labelled \cr
+    \tab \code{PCIDSK}   \tab PCIDSK Database File \cr
+    \tab \code{RST}  \tab  Idrisi Raster A.1
+}
+
+see \code{rasterWriteFormats} for the complete list
+
+}
+
+\author{Robert J. Hijmans}
+
+\seealso{ \code{\link[raster]{writeRaster}} }  
+
+\examples{ 
+rs <- rasterFromFile(system.file("external/test.ag", package="sp"))
+rsa <- saveAs(rs, 'test.tif', filetype='GTiff')
+ 
+}
+
+\keyword{ spatial }

Modified: pkg/raster/man/setDatatype.Rd
===================================================================
--- pkg/raster/man/setDatatype.Rd	2009-02-26 09:52:20 UTC (rev 301)
+++ pkg/raster/man/setDatatype.Rd	2009-02-27 02:41:41 UTC (rev 302)
@@ -1,4 +1,5 @@
 \name{SetDatatype}
+\alias{datatype<-}
 \alias{setDatatype}
 
 \title{ Set data type of a RasterLayer}
@@ -64,6 +65,8 @@
 r <- raster()
 # 2 byte signed integer
 r <- setDatatype(r, "INT2S")
+# this is equivalent to 
+datatype(r) <- "INT2S"
 # 2 byte unsigned integer
 r <- setDatatype(r, "INT2U")
 # very large integers



More information about the Raster-commits mailing list