[Raster-commits] r458 - pkg/raster/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue May 12 17:39:47 CEST 2009


Author: rhijmans
Date: 2009-05-12 17:39:46 +0200 (Tue, 12 May 2009)
New Revision: 458

Modified:
   pkg/raster/R/click.R
Log:


Modified: pkg/raster/R/click.R
===================================================================
--- pkg/raster/R/click.R	2009-05-12 14:55:47 UTC (rev 457)
+++ pkg/raster/R/click.R	2009-05-12 15:39:46 UTC (rev 458)
@@ -7,32 +7,29 @@
 # Licence GPL v3
 
 
-
-
 click <- function(object, n=1, id=FALSE, xy=FALSE, type="n", ...) {
 	loc <- locator(n, type, ...)
-	xy <- cbind(loc$x, loc$y)
-	if (missing(object)) { return(xy) }
-	cells <- cellFromXY(object, xy)
+	xyCoords <- cbind(loc$x, loc$y)
+	if (missing(object)) { return(xyCoords) }
+	cells <- cellFromXY(object, xyCoords)
 	cells <- unique(na.omit(cells))
 	if (length(cells) == 0 ) { stop('no valid cells selected') }
-	xy <- xyFromCell(object, cells)
-	colnames(xy) <- c('x', 'y')
-	n <- nrow(xy)
+	xyCoords <- xyFromCell(object, cells)
+	colnames(xyCoords) <- c('x', 'y')
+	n <- nrow(xyCoords)
 	if (id) {
 		for (i in 1:n) {
-			text(xy[i,1], xy[i,2], i)
+			text(xyCoords[i,1], xyCoords[i,2], i)
 		}
 	}
 
 	if (dataContent(object) != 'all') {
-		value <- xyValues(object, xy)
+		value <- xyValues(object, xyCoords)
 	} else {
-		cell <- cellFromXY(object, xy)
 		if (class(object) == 'RasterStack') {
-			value <- values(object)[cell,]
+			value <- values(object)[cells,]
 		} else {
-			value <- values(object)[cell]
+			value <- values(object)[cells]
 		}
 	}	
 	if (class(object) == 'RasterStack') {
@@ -48,8 +45,9 @@
 	}
 	
 	if (xy) { 
-		value <- rbind(t(xy), value)
+		value <- rbind(t(xyCoords), value)
 	} 
+	colnames(value) <- 1:n
 	return(t(value))
 	
 }



More information about the Raster-commits mailing list