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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 8 07:30:26 CET 2009


Author: rhijmans
Date: 2009-01-08 07:30:26 +0100 (Thu, 08 Jan 2009)
New Revision: 104

Modified:
   pkg/raster/R/raster.create.R
   pkg/raster/R/set.R
   pkg/raster/man/create.raster.Rd
   pkg/raster/man/export.Rd
   pkg/raster/man/set.Rd
Log:
more generic functions

Modified: pkg/raster/R/raster.create.R
===================================================================
--- pkg/raster/R/raster.create.R	2009-01-08 00:47:19 UTC (rev 103)
+++ pkg/raster/R/raster.create.R	2009-01-08 06:30:26 UTC (rev 104)
@@ -5,8 +5,8 @@
 # Licence GPL v3
 
 
-newRaster <- function(xmin=-180, xmax=180, ymin=-90, ymax=90, nrows=180, ncols=360, projstring="+proj=longlat +datum=WGS84") {
-	bb <- newBbox(xmin, xmax, ymin, ymax)
+newRaster <- function(xmn=-180, xmx=180, ymn=-90, ymx=90, nrows=180, ncols=360, projstring="+proj=longlat +datum=WGS84") {
+	bb <- newBbox(xmn, xmx, ymn, ymx)
 	return(rasterFromBbox(bb, nrows=nrows, ncols=ncols, projstring))
 }
 
@@ -61,7 +61,7 @@
 	if (yx < 0) { ndecs <- 9 } else  { ndecs <- 8 }
 	yx <- as.numeric( substr( as.character(yx), 1, ndecs) )
 
-	raster <- newRaster(ncols=nc, nrows=nr, xmin=xn, ymin=yn, xmax=xx, ymax=yx, projstring="")
+	raster <- newRaster(ncols=nc, nrows=nr, xmn=xn, ymn=yn, xmx=xx, ymx=yx, projstring="")
 	raster <- setFilename(raster, filename)
 	raster <- setDatatype(raster, "numeric")
 	
@@ -124,7 +124,7 @@
 		else if (ini[i,2] == "PROJECTION") {projstring <- ini[i,3]} 
     }  
 
-    raster <- newRaster(ncols=nc, nrows=nr, xmin=xn, ymin=yn, xmax=xx, ymax=yx, projstring=projstring)
+    raster <- newRaster(ncols=nc, nrows=nr, xmn=xn, ymn=yn, xmx=xx, ymx=yx, projstring=projstring)
 	raster <- setFilename(raster, filename)
 	raster at file@driver <- "raster"
 

Modified: pkg/raster/R/set.R
===================================================================
--- pkg/raster/R/set.R	2009-01-08 00:47:19 UTC (rev 103)
+++ pkg/raster/R/set.R	2009-01-08 06:30:26 UTC (rev 104)
@@ -17,15 +17,26 @@
 	return(raster)
 }
 
-setRaster <- function(raster, filename="") {
-	raster <- clearValues(raster)
+setRaster <- function(raster, filename="", values=NA) {
+
 	if (class(raster) == 'RasterStack') { raster <- raster at rasters[[1]] }
+	if (class(raster) == 'RasterBrick') { raster <- raster }
 	if (class(raster) != 'RasterLayer') { stop('the first argument should be a RasterLayer or a RasterStack object') }
+
+	filename <- trim(filename)
 	if (filename != "" & filename == filename(raster)) {
-		stop("is not allowed to set the filename of the output RasterLayer to that of the input RasterLayer")
+		stop("it is not allowed to set the filename of the output RasterLayer to that of the input RasterLayer")
 	}
+
+	raster <- clearValues(raster)
+	raster at data@min <- NA
+	raster at data@max <- NA
+
 	raster <- setFilename(raster, filename)
 	raster <- setDatatype(raster, 'numeric')
+	if (!is.na(values[1])) {
+		raster <- setValues(raster, values)
+	}	
 	return(raster)
 }
 

Modified: pkg/raster/man/create.raster.Rd
===================================================================
--- pkg/raster/man/create.raster.Rd	2009-01-08 00:47:19 UTC (rev 103)
+++ pkg/raster/man/create.raster.Rd	2009-01-08 06:30:26 UTC (rev 104)
@@ -10,7 +10,7 @@
   See read* and values() for access to the values
 }
 \usage{
-	newRaster(xmin = -180, xmax = 180, ymin = -90, ymax = 90, nrows = 180, ncols = 360, projstring = "+proj=longlat +datum=WGS84")
+	newRaster(xmn = -180, xmx = 180, ymn = -90, ymx = 90, nrows = 180, ncols = 360, projstring = "+proj=longlat +datum=WGS84")
 	rasterFromBbox(bndbox, nrows = 1, ncols = 1, projstring="")
 	rasterFromFile(filename, values=FALSE, band=1)
 }
@@ -18,10 +18,10 @@
 \arguments{
   \item{filename}{ name of raster data file  }
   \item{band}{ band number in case of a file of multiple bands, default = 1 }
-  \item{xmin}{ minimum x coordinate or raster (left border) }
-  \item{xmax}{ maximum x coordinate of raster (right border) }
-  \item{ymin}{ minimum y coordinate or raster (bottom border) }
-  \item{ymax}{ maximum y coordinate of raster (top border) }
+  \item{xmn}{ minimum x coordinate or raster (left border) }
+  \item{xmx}{ maximum x coordinate of raster (right border) }
+  \item{ymn}{ minimum y coordinate or raster (bottom border) }
+  \item{ymx}{ maximum y coordinate of raster (top border) }
   \item{nrows}{ number of rows on raster }
   \item{ncols}{ number of columns on raster }
   \item{projstring}{ PROJ4 type description of a map projection}

Modified: pkg/raster/man/export.Rd
===================================================================
--- pkg/raster/man/export.Rd	2009-01-08 00:47:19 UTC (rev 103)
+++ pkg/raster/man/export.Rd	2009-01-08 06:30:26 UTC (rev 104)
@@ -10,15 +10,15 @@
 }
 
 \usage{
-asRasterLayer(spgrid, getdata=TRUE, dataindex=1) 
-asRasterBrick(spgrid, getdata=TRUE) 
+asRasterLayer(object, dataindex=1) 
+asRasterBrick(spgrid) 
 asSpGrid(raster, type='grid') 
 }
 
 \arguments{
   \item{raster} { a  RasterLayer object }
+  \item{object} { a Raster* or a sp raster type object (SpatialPixel, SpatialPixelDataFrame , SpatialGrid, or SpatialGridDataFrame }
   \item{spgrid} { a sp raster type object (SpatialPixel, SpatialPixelDataFrame , SpatialGrid, or SpatialGridDataFrame }
-  \item{getdata} { logical. If \code{TRUE}, values are added to the RasterLayer object }
   \item{dataindex} {integer values >= 1 indicating the column in the sp dataframe to take the values from}
   \item{type} {character. Indicating what type of sp object to return. Should be 'pixel' or 'grid'.}
 }

Modified: pkg/raster/man/set.Rd
===================================================================
--- pkg/raster/man/set.Rd	2009-01-08 00:47:19 UTC (rev 103)
+++ pkg/raster/man/set.Rd	2009-01-08 06:30:26 UTC (rev 104)
@@ -22,7 +22,7 @@
 setProjection(object, projstring)
 setFilename(object, filename)
 clearValues(object)
-setRaster(raster, filename="")
+setRaster(raster, filename="", values=NA)
 setDatatype(raster, datatype, datasize)
 setRowCol(raster, nrows=nrow(raster), ncols=ncol(raster)) 
 setMinmax(raster)



More information about the Raster-commits mailing list