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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Mar 14 09:06:41 CET 2009


Author: rhijmans
Date: 2009-03-14 09:06:40 +0100 (Sat, 14 Mar 2009)
New Revision: 358

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


Modified: pkg/raster/R/xyValues.R
===================================================================
--- pkg/raster/R/xyValues.R	2009-03-14 07:53:23 UTC (rev 357)
+++ pkg/raster/R/xyValues.R	2009-03-14 08:06:40 UTC (rev 358)
@@ -10,6 +10,25 @@
 	setGeneric("xyValues", function(object, xyCoords, ...)
 		standardGeneric("xyValues"))
 }	
+
+
+setMethod("xyValues", signature(object='Raster', xyCoords='SpatialPoints'), 
+	function(object, xyCoords, method='simple') { 
+		xyCoords <- coordinates(xyCoords)
+		callNextMethod(object, xyCoords, method=method)
+	}	
+)
+
+
+setMethod("xyValues", signature(object='Raster', xyCoords='vector'), 
+	function(object, xyCoords, method='simple') { 
+		if (length(xyCoords) != 2) {
+			stop('xyCoords should be a two column matrix or a vector of length 2')
+		}
+		xyCoords <- matrix(xyCoords, ncol=2)
+		callNextMethod(object, xyCoords, method=method)
+	}
+)
 	
 setMethod("xyValues", signature(object='RasterLayer', xyCoords='matrix'), 
 	function(object, xyCoords, method='simple') { 
@@ -18,9 +37,11 @@
 		}
 		if (method=='bilinear') {
 			return(.bilinearValue(object, xyCoords))
-		} else {
+		} else if (method=='simple') {
 			cells <- cellFromXY(object, xyCoords)
 			return(.rasterReadCells(object, cells))
+		} else {
+			stop('invalid method argument. Should be simple or bilinear.')
 		}
 	}	
 )	
@@ -35,7 +56,8 @@
 
 		if (method == 'bilinear') {
 			for (i in seq(nlayers(object))) {
-				v <- .bilinearValue(object, xyCoords)
+				r <- asRasterLayer(object, i)
+				v <- .bilinearValue(r, xyCoords)
 				if (i == 1) {
 					result <- v
 				} else {
@@ -47,27 +69,16 @@
 			}	
 			return(result)		
 	
-		} else {
+		} else if (method==simple) {
 			cells <- cellFromXY(object, xyCoords)
 			return(.stackReadCells(object, cells))
+		} else {
+			stop('invalid method argument. Should be simple or bilinear.')
 		}
+
 	}	
 )
 
 
 
-setMethod("xyValues", signature(object='RasterLayer', xyCoords='SpatialPoints'), 
-	function(object, xyCoords, method='simple') { 
-		xyCoords <- coordinates(xyCoords)
-		callNextMethod(object, xyCoords, method)
-	}	
-)
 
-
-setMethod("xyValues", signature(object='RasterStack', xyCoords='SpatialPoints'), 
-	function(object, xyCoords, method='simple') { 
-		xyCoords <- coordinates(xyCoords)
-		callNextMethod(object, xyCoords, method)
-	}	
-)
-

Modified: pkg/raster/man/xyValues.Rd
===================================================================
--- pkg/raster/man/xyValues.Rd	2009-03-14 07:53:23 UTC (rev 357)
+++ pkg/raster/man/xyValues.Rd	2009-03-14 08:06:40 UTC (rev 358)
@@ -2,9 +2,11 @@
 \docType{methods}
 
 \alias{xyValues}
+\alias{xyValues,Raster,vector-method}
+\alias{xyValues,Raster,SpatialPoints-method}
 \alias{xyValues,RasterLayer,matrix-method}
 \alias{xyValues,RasterStack,matrix-method}
-\alias{xyValues,RasterLayer,SpatialPoints-method}
+
 \alias{xyValues,RasterStack,SpatialPoints-method}
 
 \title{ values at xy coordinates }



More information about the Raster-commits mailing list