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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri May 8 16:55:24 CEST 2009


Author: rhijmans
Date: 2009-05-08 16:55:24 +0200 (Fri, 08 May 2009)
New Revision: 446

Modified:
   pkg/raster/R/projectRaster.R
   pkg/raster/R/rasterTmpFile.R
   pkg/raster/man/xyValues.Rd
Log:


Modified: pkg/raster/R/projectRaster.R
===================================================================
--- pkg/raster/R/projectRaster.R	2009-05-08 14:04:24 UTC (rev 445)
+++ pkg/raster/R/projectRaster.R	2009-05-08 14:55:24 UTC (rev 446)
@@ -5,21 +5,6 @@
 # Licence GPL v3
 
 
-.xyTransform <- function(crds, projfrom, projto) {
-# May 2009. This function was extracted from function "spTransform.SpatialPoints" in the rgdal package
-# Copyright (c) 2003-8 by Barry Rowlingson, Roger Bivand, and Edzer Pebesma
-	res <- .Call("transform", projfrom, projto, nrow(crds), as.double(crds[,1]), as.double(crds[,2]), PACKAGE="rgdal")
-	if (any(!is.finite(res[[1]])) || any(!is.finite(res[[2]]))) {
-		k <- which(!is.finite(res[[1]]) || !is.finite(res[[2]]))
-		cat("non finite transformation detected:\n")
-		print(cbind(crds, res[[1]], res[[2]])[k,])
-		stop(paste("failure in points", paste(k, collapse=":")))
-	}
-	return(cbind(res[[1]], res[[2]]))
-}
-
-
-
 projectBbox <- function(object, projs) {
 	validObject(projection(object, asText=FALSE))
 	validObject(projection(projs, asText=FALSE))
@@ -27,7 +12,11 @@
 	projto <- projection(projs)
 	b <- extent(object)
 	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))
-	p <- .xyTransform(xy, projfrom, projto)	
+	res <- .Call("transform", projfrom, projto, nrow(xy), xy[,1], xy[,2], PACKAGE="rgdal")
+	p <- cbind(res[[1]], res[[2]])
+	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
 	return(obj)
@@ -35,6 +24,8 @@
 
 
 projectRaster <- function(from, to, method="ngb", filename="", filetype='raster', datatype='FLT4S', overwrite=FALSE, track=-1)  {
+	if (dataContent(from) != 'all' & dataSource(from) == 'ram') { stop('no vales for "from". Nothing to do') }
+
 	validObject(to)
 	validObject(projection(from, asText=FALSE))
 	validObject(projection(to, asText=FALSE))
@@ -50,6 +41,7 @@
 	if (!method %in% c('bilinear', 'ngb')) { stop('invalid method') }
 	filename <- trim(filename)
 	to <- raster(to)
+
 	filename(to) <- filename
 	dataType(to) <- datatype
 
@@ -73,7 +65,8 @@
 	for (r in 1:nrow(to)) {
 		cells <- rowCells + (r-1) * ncol(to)
 		xy <- xyFromCell(to, cells)
-		unProjXY <- .xyTransform(xy, projto, projfrom)
+		res <- .Call("transform", projfrom, projto, nrow(xy), xy[,1], xy[,2], PACKAGE="rgdal")
+		unProjXY <- cbind(res[[1]], res[[2]])
 		vals <- xyValues(from, unProjXY, method=xymethod)
 		if (inMemory) {
 			v[,r] <- vals
@@ -89,3 +82,4 @@
 	return(to)
 }
 
+

Modified: pkg/raster/R/rasterTmpFile.R
===================================================================
--- pkg/raster/R/rasterTmpFile.R	2009-05-08 14:04:24 UTC (rev 445)
+++ pkg/raster/R/rasterTmpFile.R	2009-05-08 14:55:24 UTC (rev 446)
@@ -3,8 +3,6 @@
 # Version 0.8
 # Licence GPL v3
 
-
-
 setTmpDir <- function(d=NULL) {
 	if (!is.null(d)) {
 		res <- file.exists(d)

Modified: pkg/raster/man/xyValues.Rd
===================================================================
--- pkg/raster/man/xyValues.Rd	2009-05-08 14:04:24 UTC (rev 445)
+++ pkg/raster/man/xyValues.Rd	2009-05-08 14:55:24 UTC (rev 446)
@@ -13,11 +13,10 @@
 \title{ values at xy coordinates }
 
 \description{
- These methods return the values of a RasterLayer or RasterStack for a set of xy coordinates (points).
- The xy coordinates can be passed as a vector of length 2; a n*2 matrix or data.frame; or a SpatialPoints object.
- 
- Values can be extracted using bilnear interpolation of values of the four cells nearest to a point.
- 
+These methods return the values of a RasterLayer or RasterStack for a set of xy coordinates (points).
+The xy coordinates can be passed as a vector of length 2; a n*2 matrix or data.frame; or a SpatialPoints object.
+
+Values can be extracted using bilnear interpolation of values of the four cells nearest to a point.
 }
 
 \usage{
@@ -32,15 +31,21 @@
 
 \section{Methods}{
 \describe{
-\code{xyCoords} can be a  \code{n*2} matrix or dataframe with the first column having the x values, and the second column has the y values.
-It can also be a \code{SpatialPoints*} object.
+A full call: 
 
-if \code{raster} is a \code{RasterLayer} object, the additional argument \code{method='bilinear'} can be used. In the case, the returned values
-are interpolated from the (centers of the) four nearest raster cells.
+\code{xyValues(object, xyCoords, method='simple')}
+
+\tabular{rll}{
+\tab \code{object} \tab a Raster* object \cr
+\tab \code{xyCoords} \tab a  \code{n*2} matrix or dataframe with the first column having the x values, and the second column has the y values.
+It can also be a \code{SpatialPoints*} object \cr
+\tab \code{method} \tab character. \code{'simple'} or \code{'bilinear'}. In the case of \code{'bilinear'}, the returned values
+are interpolated from the (centers of the) four nearest raster cells. \cr
 }
+
 }
+}
 
-
 \value{
 a vector (object is a RasterLayer) or a matrix (object is a RasterStack)
 }



More information about the Raster-commits mailing list