[Raster-commits] r353 - in pkg/raster: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Mar 14 05:11:47 CET 2009
Author: rhijmans
Date: 2009-03-14 05:11:47 +0100 (Sat, 14 Mar 2009)
New Revision: 353
Modified:
pkg/raster/R/depracated.R
pkg/raster/R/makeProjString.R
pkg/raster/R/project.R
pkg/raster/R/raster.R
pkg/raster/R/rasterFromFile.R
pkg/raster/R/set.R
pkg/raster/man/project.Rd
pkg/raster/man/raster.Rd
pkg/raster/man/rasterFromFile.Rd
pkg/raster/man/resample.Rd
pkg/raster/man/set.Rd
pkg/raster/man/utils.Rd
Log:
Modified: pkg/raster/R/depracated.R
===================================================================
--- pkg/raster/R/depracated.R 2009-03-14 01:17:34 UTC (rev 352)
+++ pkg/raster/R/depracated.R 2009-03-14 04:11:47 UTC (rev 353)
@@ -1,5 +1,5 @@
-#newRaster <- function(xmn=-180, xmx=180, ymn=-90, ymx=90, nrows=180, ncols=360, projstring="+proj=longlat +datum=WGS84") {
+#newRaster <- function(...xmn=-180, xmx=180, ymn=-90, ymx=90, nrows=180, ncols=360, projstring="+proj=longlat +datum=WGS84") {
# stop("'newRaster' is deprecated. Use 'raster' instead")
#}
Modified: pkg/raster/R/makeProjString.R
===================================================================
--- pkg/raster/R/makeProjString.R 2009-03-14 01:17:34 UTC (rev 352)
+++ pkg/raster/R/makeProjString.R 2009-03-14 04:11:47 UTC (rev 353)
@@ -6,18 +6,18 @@
-newCRS <- function(projstring) {
- projstring <- trim(projstring)
- if (is.na(projstring) | nchar(projstring) < 3) {
- projs <- (CRS(as.character(NA)))
+newCRS <- function(projs) {
+ projs <- trim(projs)
+ if (is.na(projs) | nchar(projs) < 3) {
+ prj <- (CRS(as.character(NA)))
} else {
- projs <- try(CRS(projstring), silent = T)
- if (class(projs) == "try-error") {
- warning(paste(projstring, 'is not a valid proj4 CRS string'))
- projs <- CRS(as.character(NA))
+ prj <- try(CRS(projs), silent = T)
+ if (class(prj) == "try-error") {
+ warning(paste(projs, 'is not a valid proj4 CRS string'))
+ prj <- CRS(as.character(NA))
}
}
- return(projs)
+ return(prj)
}
Modified: pkg/raster/R/project.R
===================================================================
--- pkg/raster/R/project.R 2009-03-14 01:17:34 UTC (rev 352)
+++ pkg/raster/R/project.R 2009-03-14 04:11:47 UTC (rev 353)
@@ -7,17 +7,17 @@
-projectBbox <- function(object, projstring) {
+projectBbox <- function(object, projs) {
b <- getBbox(object)
- projstring <- projection(projstring)
+ projs <- projection(projs)
xy <- rbind(c(b at xmin, b at ymax), c(b at xmax, b at ymax), c(b at xmin, b at ymin), c(b at xmax, b at ymin))
if (isLatLon(object)) {
- p <- project(xy, projstring, inv=FALSE)
+ p <- project(xy, projs, inv=FALSE)
} else {
p <- project(xy, projection(object), inv=TRUE)
- if (!isLatLon(projstring)) {
- p <- project(p, projstring, inv=FALSE)
+ if (!isLatLon(projs)) {
+ p <- project(p, projs, inv=FALSE)
}
}
@@ -27,7 +27,7 @@
ymax <- max(p[,2])
bb <- newBbox(xmin, xmax, ymin, ymax)
obj <- setExtent(object, bb)
- obj <- setProjection(obj, projstring)
+ obj <- setProjection(obj, projs)
return(obj)
}
Modified: pkg/raster/R/raster.R
===================================================================
--- pkg/raster/R/raster.R 2009-03-14 01:17:34 UTC (rev 352)
+++ pkg/raster/R/raster.R 2009-03-14 04:11:47 UTC (rev 353)
@@ -21,29 +21,26 @@
}
setMethod('raster', signature(x='missing'),
- function(nrows=180, ncols=360, xmn=-180, xmx=180, ymn=-90, ymx=90, projstring="+proj=longlat +datum=WGS84") {
+ function(nrows=180, ncols=360, xmn=-180, xmx=180, ymn=-90, ymx=90, projs="+proj=longlat +datum=WGS84") {
bb <- newBbox(xmn, xmx, ymn, ymx)
- rs <- raster(bb, nrows=nrows, ncols=ncols)
- rs <- setProjection(rs, projstring)
- return(rs)
+ r <- raster(bb, nrows=nrows, ncols=ncols, projs=projs)
+ return(r)
}
)
setMethod('raster', signature(x='Raster'),
- function(x, filename="", values=NULL, layer=1) {
+ function(x, filename="", values=NULL) {
if (class(x) == 'RasterStack') {
-
- x <- asRasterLayer(x, layer)
+ x <- asRasterLayer(x, 1)
}
- if (class(x) != 'RasterLayer') { stop('the first argument should be a RasterLayer or a RasterStack object') }
filename <- trim(filename)
if (filename != "" & filename == filename(x)) {
stop("it is not allowed to set the filename of the output RasterLayer to that of the input RasterLayer")
}
- r <- raster(xmn = xmin(x), xmx = xmax(x), ymn = ymin(x), ymx = ymax(x), nrows=nrow(x), ncols=ncol(x), projstring=projection(x))
+ r <- raster(xmn=xmin(x), xmx=xmax(x), ymn=ymin(x), ymx=ymax(x), nrows=nrow(x), ncols=ncol(x), projs=projection(x))
r <- setFilename(r, filename)
if (!is.null(values)) {
@@ -57,32 +54,29 @@
function(x, values=FALSE, band=1) {
fileext <- toupper(fileExtension(x))
if ( fileext == ".GRD" | fileext == ".GRI" ) {
- raster <- .rasterFromRasterFile(x, band)
+ r <- .rasterFromRasterFile(x, band)
} else {
- raster <- .rasterFromGDAL(x, band)
+ r <- .rasterFromGDAL(x, band)
}
if (values) {
- raster <- readAll(raster)
+ r <- readAll(r)
}
- return(raster)
+ return(r)
}
)
setMethod('raster', signature(x='BoundingBox'),
-function(x, nrows=10, ncols=10) {
- crs <- newCRS('NA')
- try(crs <- projection(x, asText=F), silent = T)
-
+function(x, nrows=10, ncols=10, projs='NA') {
bb <- getBbox(x)
-
nr = as.integer(round(nrows))
nc = as.integer(round(ncols))
if (nc < 1) { stop("ncols should be > 0") }
if (nr < 1) { stop("nrows should be > 0") }
- raster <- new("RasterLayer", bbox = bb, crs=crs, ncols = nc, nrows = nr )
- return(raster)
+ rs <- new("RasterLayer", bbox=bb, ncols=nc, nrows=nr)
+ rs <- setProjection(rs, projs)
+ return(rs)
}
)
Modified: pkg/raster/R/rasterFromFile.R
===================================================================
--- pkg/raster/R/rasterFromFile.R 2009-03-14 01:17:34 UTC (rev 352)
+++ pkg/raster/R/rasterFromFile.R 2009-03-14 04:11:47 UTC (rev 353)
@@ -44,7 +44,7 @@
if (yx < 0) { ndecs <- 9 } else { ndecs <- 8 }
yx <- as.numeric( substr( as.character(yx), 1, ndecs) )
- raster <- raster(ncols=nc, nrows=nr, xmn=xn, ymn=yn, xmx=xx, ymx=yx, projstring="")
+ raster <- raster(ncols=nc, nrows=nr, xmn=xn, ymn=yn, xmx=xx, ymx=yx, projs="")
raster <- setFilename(raster, filename)
raster <- setDatatype(raster, "FLT4S")
@@ -113,7 +113,7 @@
else if (ini[i,2] == "PROJECTION") {projstring <- ini[i,3]}
}
- raster <- raster(ncols=nc, nrows=nr, xmn=xn, ymn=yn, xmx=xx, ymx=yx, projstring=projstring)
+ raster <- raster(ncols=nc, nrows=nr, xmn=xn, ymn=yn, xmx=xx, ymx=yx, projs=projstring)
raster <- setFilename(raster, filename)
raster at file@driver <- "raster"
Modified: pkg/raster/R/set.R
===================================================================
--- pkg/raster/R/set.R 2009-03-14 01:17:34 UTC (rev 352)
+++ pkg/raster/R/set.R 2009-03-14 04:11:47 UTC (rev 353)
@@ -58,11 +58,11 @@
-setProjection <- function(object, projstring) {
- if (class(projstring)=="CRS") {
- object at crs <- projstring
+setProjection <- function(object, projs) {
+ if (class(projs)=="CRS") {
+ object at crs <- projs
} else {
- object at crs <- newCRS(projstring)
+ object at crs <- newCRS(projs)
}
return(object)
}
Modified: pkg/raster/man/project.Rd
===================================================================
--- pkg/raster/man/project.Rd 2009-03-14 01:17:34 UTC (rev 352)
+++ pkg/raster/man/project.Rd 2009-03-14 04:11:47 UTC (rev 353)
@@ -11,7 +11,7 @@
\usage{
projectRaster(from, to, method="ngb", filename=NULL, filetype='raster', datatype='FLT4S', overwrite=FALSE, track=-1)
-projectBbox(object, projstring)
+projectBbox(object, projs)
}
\arguments{
@@ -24,7 +24,7 @@
\item{datatype}{output data type; see \code{\link[raster]{setDatatype}}}
\item{track}{vector of row numbers for which the function will report that they have been processed}
\item{object}{BoundingBox or Raster* object}
- \item{projstring}{a character string describing a projection and datum in PROJ4 format}
+ \item{projs}{a character string describing a projection and datum in PROJ4 format}
}
Modified: pkg/raster/man/raster.Rd
===================================================================
--- pkg/raster/man/raster.Rd 2009-03-14 01:17:34 UTC (rev 352)
+++ pkg/raster/man/raster.Rd 2009-03-14 04:11:47 UTC (rev 353)
@@ -26,7 +26,6 @@
}
\section{Methods}{
-
1) Create a RasterLayer object from a file
\code{raster(x, values=FALSE, band=1)}
@@ -39,39 +38,44 @@
'native' raster package format and those that can be read via rgdal. See ?readGDAL help for supported file types.
+
2) Create a RasterLayer object from scratch
-\code{raster(nrows=180, ncols=360, xmn=-180, xmx=180, ymn=-90, ymx=90, projstring="+proj=longlat +datum=WGS84")}
+\code{raster(nrows=180, ncols=360, xmn=-180, xmx=180, ymn=-90, ymx=90, projs="+proj=longlat +datum=WGS84")}
-\item{nrows}{number of rows on raster }
-\item{ncols}{number of columns on raster }
-\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{projstring}{PROJ4 type description of a map projection}
-\item{bndbox}{bounding box used to crop a raster. Any object that is a BoundingBox object or contains one (such as Raster* objects)}
+\item{\code{nrows}}{number of rows on raster }
+\item{\code{ncols}}{number of columns on raster }
+\item{\code{xmn}}{minimum x coordinate or raster (left border) }
+\item{\code{xmx}}{maximum x coordinate of raster (right border) }
+\item{\code{ymn}}{minimum y coordinate or raster (bottom border) }
+\item{\code{ymx}}{maximum y coordinate of raster (top border) }
+\item{\code{projs}}{character. PROJ4 type description of a map projection}
+\item{\code{bndbox}}{bounding box used to crop a raster. Any object that is a BoundingBox object or contains one (such as Raster* objects)}
(item \code{x} is 'missing' in this case)
+
3) Create a RasterLayer object from a BoundingBox object
-\code{raster(x, nrows=10, ncols=10)}
+\code{raster(x, nrows=10, ncols=10, projs='NA')}
-\item{x}{BoundingBox object}
-\item{nrows}{number of rows on raster }
-\item{ncols}{number of columns on raster}
+\item{\code{x}}{BoundingBox object}
+\item{\code{nrows}}{number of rows on raster }
+\item{\code{ncols}}{number of columns on raster}
+\item{\code{projs}}{PROJ4 type description of a map projection}
+
4) Create a RasterLayer object from a Raster* object. This copies the parameters of a Raster* object to a new RasterLayer,
-but does not copy the filename nor the data associated with the original raster. Use it when creating new RasterLayer objects from existing objects.
+but does not copy the filename nor the data associated with the original Raster* object.
+
\code{raster(x, filename="", values=NULL)}
\item{\code{x}}{a Raster* object}
\item{\code{filename}}{new filename for new RasterLayer }
-\item{\code{values}}{ use to set values to new object. Either pass a vector of length == ncells(x), or a single number }
+\item{\code{values}}{If not \code{NULL} it is used to set values to new object. Either pass a vector of length == ncells(x), or a single number}
}
@@ -100,12 +104,14 @@
r1 <- raster(nrows=108, ncols=21, xmn=0, xmx=10)
#from a BoundingBox
-bb <- getBbox(r1)
+bb <- getBbox(r)
r2 <- raster(bb)
r2[] <- runif(ncell(r2))
#from another Raster* object
r3 <- raster(r)
+s <- stack(r, r)
+r3 <- raster(s)
}
\keyword{methods}
Modified: pkg/raster/man/rasterFromFile.Rd
===================================================================
--- pkg/raster/man/rasterFromFile.Rd 2009-03-14 01:17:34 UTC (rev 352)
+++ pkg/raster/man/rasterFromFile.Rd 2009-03-14 04:11:47 UTC (rev 353)
@@ -1,21 +1,27 @@
\name{rasterFromFile}
\alias{rasterFromFile}
+\alias{rasterFromBbox}
-\title{RasterLayer from file}
+\title{Raster from file}
\description{
- This function has been depracated. Use \code{link[raster]{raster}} instead.
+ These function have been depracated. Use \code{link[raster]{raster}} instead.
}
\usage{
rasterFromFile(filename, values=FALSE, band=1)
+rasterFromBbox(bndbox, nrows=10, ncols=10)
+
}
\arguments{
\item{filename}{name of raster data file }
\item{band}{band number in case of a file of multiple bands, default = 1 }
\item{values}{logical. If \code{TRUE}, RasterLayer values will be read into memory with 'readAll()'}
+ \item{bndbox}{a BoundingBox object}
+ \item{nrows}{number of rows on raster }
+ \item{ncols}{number of columns on raster }
}
Modified: pkg/raster/man/resample.Rd
===================================================================
--- pkg/raster/man/resample.Rd 2009-03-14 01:17:34 UTC (rev 352)
+++ pkg/raster/man/resample.Rd 2009-03-14 04:11:47 UTC (rev 353)
@@ -6,7 +6,8 @@
\description{
Resample transfers values between non matching RasterLayers (in terms of origin and resolution).
-Avoid using this function if you can use functions like (dis)aggregate, crop and merge instead, because these functions are more accurate and much faster.
+Avoid using this function if you can use functions like (dis)aggregate, crop and merge instead, because
+these functions are more accurate and much faster.
}
\usage{
@@ -18,7 +19,7 @@
\item{to}{a Raster* object}
\item{method}{method used to compute values for the new RasterLayer}
\item{filename}{character. output filename}
- \item{overwrite}{Logical. If \code{TRUE}, the output file is overwritten if it already exists}
+ \item{overwrite}{logical. If \code{TRUE}, the output file is overwritten if it already exists}
\item{filetype}{output file type. Either 'raster', 'ascii' or a supported GDAL 'driver' name see \code{\link[raster]{writeRaster}}}
\item{datatype}{output data type; see \code{\link[raster]{setDatatype}}}
\item{track}{vector of row numbers for which the function will report that they have been processed}
@@ -29,7 +30,7 @@
}
\value{
- a new RasterLayer object, and, in some cases, the side-effect of the raster values written to disk
+ a RasterLayer object, and, in some cases, the side-effect of a file with the values of the new RasterLayer
}
\author{Robert J. Hijmans }
Modified: pkg/raster/man/set.Rd
===================================================================
--- pkg/raster/man/set.Rd 2009-03-14 01:17:34 UTC (rev 352)
+++ pkg/raster/man/set.Rd 2009-03-14 04:11:47 UTC (rev 353)
@@ -19,7 +19,7 @@
}
\usage{
-setProjection(object, projstring)
+setProjection(object, projs)
setFilename(object, filename)
setRaster(object, filename="", values=NULL)
setRowCol(raster, nrows=nrow(raster), ncols=ncol(raster))
@@ -37,7 +37,7 @@
\item{ncols}{ the new number of cols for the raster }
\item{xres}{ the new x resolution}
\item{yres}{ the new y resolution}
- \item{projstring}{a character string describing a projection and datum in PROJ4 format }
+ \item{projs}{a character string describing a projection and datum in PROJ4 format }
\item{value}{the value to be interpreted as NA; set this before reading the values from the file. Integer values are matched exactely; for decimal values files any value <= the value will be interpreted as NA}
}
Modified: pkg/raster/man/utils.Rd
===================================================================
--- pkg/raster/man/utils.Rd 2009-03-14 01:17:34 UTC (rev 352)
+++ pkg/raster/man/utils.Rd 2009-03-14 04:11:47 UTC (rev 353)
@@ -11,13 +11,13 @@
\usage{
roundCoords(object, digits=0)
-newCRS(projstring)
+newCRS(projs)
}
\arguments{
\item{object}{ a Raster* object }
\item{digits}{ integer indicating the precision to be used}
- \item{projstring}{ a PROJ4 type character string describing projection and datum}
+ \item{projs}{charater. a PROJ4 type description of a projection, its paramaters, and the datum}
}
\author{Robert J. Hijmans }
More information about the Raster-commits
mailing list