[Raster-commits] r218 - in pkg/raster: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jan 30 06:51:04 CET 2009
Author: rhijmans
Date: 2009-01-30 06:51:03 +0100 (Fri, 30 Jan 2009)
New Revision: 218
Added:
pkg/raster/R/makeProjString.R
Modified:
pkg/raster/man/project.Rd
Log:
Added: pkg/raster/R/makeProjString.R
===================================================================
--- pkg/raster/R/makeProjString.R (rev 0)
+++ pkg/raster/R/makeProjString.R 2009-01-30 05:51:03 UTC (rev 218)
@@ -0,0 +1,57 @@
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date : January 2009
+# Version 0.8
+# Licence GPL v3
+
+
+
+makeProj <- function(projection='longlat', ..., ellipsoid="", datum="WGS84", asText=TRUE) {
+ prj <- projInfo("proj")
+ ell <- projInfo("ellps")
+ dat <- projInfo("datum")
+ projection <- trim(projection)
+ ellipsoid <- trim(ellipsoid)
+ datum <- trim(datum)
+ if (!(projection %in% prj[,1])) {
+ stop("unknown projection. See projInfo()")
+ } else {
+ pstr <- paste('+proj=',projection, sep="")
+ projname <- as.vector(prj[which(prj[,1]==projection), 2])
+ }
+ pargs <- list(...)
+ for (i in 1:length(pargs)) {
+ pstr <- paste(pstr, ' +', pargs[[i]], sep="")
+ }
+ if (ellipsoid != "") {
+ if (!(ellipsoid %in% ell[,1])) {
+ stop("unknown ellipsoid. See projInfo('ellps')")
+ } else {
+ pstr <- paste(pstr, " +ellps=", ellipsoid, sep="")
+# ellipname <- ell[which(ell[,1]==ellipsoid), 2]
+ }
+ }
+ if (datum != "") {
+ if (!(datum %in% dat[,1])) {
+ stop("unknown datum. See projInfo('datum')")
+ } else {
+ pstr <- paste(pstr, " +datum=", datum, sep="")
+# datumname <- as.vector(dat[which(dat[,1]==datum), 2])
+ }
+ }
+
+ cat("Projection: ", projname[1], "\n")
+
+ crs <- newCRS(pstr)
+
+
+ if (asText) {
+ return(trim(crs at projargs))
+ } else {
+ return(crs)
+ }
+}
+
+ #newprj2 <- makeProj("lcc", "lat_1=48", "lat_2=33", "lon_0=-100", asText=T)
+
+
Modified: pkg/raster/man/project.Rd
===================================================================
--- pkg/raster/man/project.Rd 2009-01-30 03:31:38 UTC (rev 217)
+++ pkg/raster/man/project.Rd 2009-01-30 05:51:03 UTC (rev 218)
@@ -1,14 +1,16 @@
\name{project}
\alias{projectRaster}
\alias{projectBbox}
+\alias{makeProj}
\title{Change the projection of a RasterLayer}
\description{
- Change the projection of a RasterLayer
+ Change the projection of a RasterLayer.
}
\usage{
projectRaster(from, to, method="nngb", overwrite=FALSE)
projectBbox(object, projstring)
+makeProj(projection='longlat', ..., ellipsoid="", datum="WGS84", asText=TRUE)
}
\arguments{
@@ -18,10 +20,17 @@
\item{overwrite}{}
\item{object}{}
\item{projstring}{}
+ \item{projection}{}
+ \item{...}{parameters for the projection}
+ \item{ellipsoid}{}
+ \item{datum}{}
+ \item{asText}{logical. If \{code}{FALSE}, an object of class 'CRS' will be returned.}
}
\details{
first create projected bbox (in BasicRaster object). Then project.
+ makeProj is a helper function to create a valid PROJ.4 string or CRS object.
+ See projInfo('proj'), projInfo('ellps'), and projInfo('datum') for valud choices
}
\value{
@@ -35,6 +44,9 @@
r <- setValues(r, 1:ncell(r))
# proj.4 projection description
newproj <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100"
+# this is equivalent to
+newproj2 <- makeProj("lcc", "lat_1=48", "lat_2=33", "lon_0=-100", ellp="WGS84", datum="")
+
# create a new RasterLayer with a BoundingBox with the new projection
projras <- projectBbox(r, newproj)
# Adjust the cell size
More information about the Raster-commits
mailing list