[Raster-commits] r449 - in pkg/raster: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri May 8 17:48:13 CEST 2009
Author: rhijmans
Date: 2009-05-08 17:48:13 +0200 (Fri, 08 May 2009)
New Revision: 449
Modified:
pkg/raster/R/projectRaster.R
pkg/raster/man/projectRaster.Rd
pkg/raster/man/roundExtent.Rd
Log:
Modified: pkg/raster/R/projectRaster.R
===================================================================
--- pkg/raster/R/projectRaster.R 2009-05-08 15:05:35 UTC (rev 448)
+++ pkg/raster/R/projectRaster.R 2009-05-08 15:48:13 UTC (rev 449)
@@ -5,7 +5,7 @@
# Licence GPL v3
-projectBbox <- function(object, projs) {
+projectExtent <- function(object, projs) {
validObject(projection(object, asText=FALSE))
validObject(projection(projs, asText=FALSE))
projfrom <- projection(object)
@@ -17,8 +17,7 @@
if (any(is.infinite(p[,1])) || any(is.infinite(p[,2]))) {
stop("non finite transformation detected")
}
- obj <- setExtent(object, newBbox(min(p[,1]), max(p[,1]), min(p[,2]), max(p[,2])))
- projection(obj) <- projs
+ obj <- raster(newBbox(min(p[,1]), max(p[,1]), min(p[,2]), max(p[,2])), nrows=nrow(object), ncols=ncol(object), proj=(projs))
return(obj)
}
@@ -34,7 +33,7 @@
if (projfrom == "NA") {stop("input projection is NA")}
if (projto == "NA") {stop("output projection is NA")}
- pbb <- projectBbox(to, projection(from))
+ pbb <- projectExtent(to, projection(from))
bb <- intersectBbox(pbb, from)
validObject(bb)
Modified: pkg/raster/man/projectRaster.Rd
===================================================================
--- pkg/raster/man/projectRaster.Rd 2009-05-08 15:05:35 UTC (rev 448)
+++ pkg/raster/man/projectRaster.Rd 2009-05-08 15:48:13 UTC (rev 449)
@@ -1,23 +1,25 @@
\name{projectRaster}
\alias{projectRaster}
-\alias{projectBbox}
+\alias{projectExtent}
\title{project a RasterLayer}
\description{
Change the projection of a RasterLayer.
+\code{projecExtent} returns a RasterLayer with a projected extent, but without any values. This RasterLayer can then
+be used as \code{'to'} RasterLayer in \code{projectRaster}. \code{projectRaster} computes values for the cells of the new RasterLayer.
}
\usage{
projectRaster(from, to, method="ngb", filename="", filetype='raster', datatype='FLT4S', overwrite=FALSE, track=-1)
-projectBbox(object, projs)
+projectExtent(object, projs)
}
\arguments{
\item{from}{a RasterLayer object}
\item{to}{a Raster* object}
- \item{method}{method used to compute values for the new RasterLayer}
+ \item{method}{method used to compute values for the new RasterLayer. Either 'ngb' (nearest neighbor) or 'bilinear' (bilinear interpolation).}
\item{filename}{character. output filename}
\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}}}
@@ -29,11 +31,11 @@
}
\details{
-First create a RasterLayer with a projected BoundingBox; also set the number of rows and columns.
+First create a template RasterLayer with a projected extent; also set the number of rows and columns (or the resolution); and perhaps adjust the extent.
Then use that object to project the input RasterLayer to.
-
-Valid values for \code{method} are \code{'ngb'} (nearest neighbor) and \code{'bilinear'} (bilinear interpolation).
+The resolution of the output RasterLayer should not be much larger of that of the input RasterLayer.
+
See \code{projInfo('proj')}, \code{projInfo('ellps')}, and \code{projInfo('datum')} for options for valid PROJ.4 strings.
You can consult this page: \url{http://www.remotesensing.org/geotiff/proj_list/} to find the parameter options and names for projections.
@@ -56,15 +58,23 @@
# proj.4 projection description
newproj <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +ellps=WGS84"
-# create a new RasterLayer with a BoundingBox with the new projection
-projras <- projectBbox(r, newproj)
+# create a new RasterLayer with a projected extent (no values are transferred)
+pr <- projectExtent(r, newproj)
# Adjust the cell size
-res(projras) <- 100000
+res(pr) <- 100000
+
# project the values of RasterLayer 'r' to the new RasterLayer 'projras'
-projras <- projectRaster(r, projras)
+pr <- projectRaster(r, pr)
# inverse projection, back to the properties of 'r'
-inverse <- projectRaster(projras, r)
+inv <- projectRaster(pr, r)
+## using a higher resolution and bilinear interpolation
+# res(pr) <- 10000
+# pr <- projectRaster(r, pr, method='bilinear')
+# inv <- projectRaster(pr, r, method='bilinear')
+# dif <- r - inv
+# plot(dif)
+
}
\keyword{spatial}
Modified: pkg/raster/man/roundExtent.Rd
===================================================================
--- pkg/raster/man/roundExtent.Rd 2009-05-08 15:05:35 UTC (rev 448)
+++ pkg/raster/man/roundExtent.Rd 2009-05-08 15:48:13 UTC (rev 449)
@@ -3,12 +3,14 @@
\alias{roundExtent}
\alias{nudgeExtent}
-\title{round ccoordinates of extent}
+\title{Round extent coordinates}
\description{
-roundCoords rounds the coordinates of the extent of a Raster* to a number of digits specified. This can be useful when dealing with small inprecision in the data.
-nudgeCoords takes the floor (lower integer) of the mimumum x and y of the exent and the ceiling (upper integer) of the maximum x and y of the extent. Thus returning a RasterLayer with an extent of rounded coordinates and that always includes the original extent.
-This can be useful when creating raster objects based on the extent of other objects.
+\code{roundCoords} rounds the coordinates of the extent of a Raster* to a number of digits specified.
+This can be useful when dealing with a small inprecision in the data (e.g. 179.9999 in stead of 180).
+nudgeCoords takes the floor (lower integer) of the mimumum x and y of the exent and the ceiling (upper integer)
+of the maximum x and y of the extent. Thus returning a RasterLayer with an extent of rounded coordinates and that
+always includes the original extent. This can be useful when creating raster objects based on the extent of other objects.
}
\usage{
@@ -23,9 +25,9 @@
\author{Robert J. Hijmans }
\examples{
- r <- raster(xmn=0.999999, xmx=10.000011, ymn=-60, ymx=60)
- r <- roundExtent(r, 2)
- r <- nudgeExtent(r)
+r <- raster(xmn=0.999999, xmx=10.000011, ymn=-60, ymx=60)
+r <- roundExtent(r, 2)
+r <- nudgeExtent(r)
}
\keyword{ spatial }
More information about the Raster-commits
mailing list