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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue May 12 16:55:47 CEST 2009


Author: rhijmans
Date: 2009-05-12 16:55:47 +0200 (Tue, 12 May 2009)
New Revision: 457

Modified:
   pkg/raster/R/click.R
   pkg/raster/R/clump.R
   pkg/raster/man/KML.Rd
   pkg/raster/man/click.Rd
Log:


Modified: pkg/raster/R/click.R
===================================================================
--- pkg/raster/R/click.R	2009-05-12 12:31:31 UTC (rev 456)
+++ pkg/raster/R/click.R	2009-05-12 14:55:47 UTC (rev 457)
@@ -9,37 +9,46 @@
 
 
 
-click <- function(object, n=1, xy=FALSE, type="n", ...) {
+click <- function(object, n=1, id=FALSE, xy=FALSE, type="n", ...) {
 	loc <- locator(n, type, ...)
-	xyCoords <- cbind(loc$x, loc$y)
-	if (missing(object)) {
-		return(cbind(xyCoords))
+	xy <- cbind(loc$x, loc$y)
+	if (missing(object)) { return(xy) }
+	cells <- cellFromXY(object, xy)
+	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)
+	if (id) {
+		for (i in 1:n) {
+			text(xy[i,1], xy[i,2], i)
+		}
 	}
+
 	if (dataContent(object) != 'all') {
-		value <- xyValues(object, xyCoords)
+		value <- xyValues(object, xy)
 	} else {
-		cell <- cellFromXY(object, xyCoords)
+		cell <- cellFromXY(object, xy)
 		if (class(object) == 'RasterStack') {
 			value <- values(object)[cell,]
 		} else {
 			value <- values(object)[cell]
 		}
 	}	
-	value <- t(matrix(value))
 	if (class(object) == 'RasterStack') {
-		colnames(value) <- layerNames(object)
+		value <- t(matrix(value, nrow=n))
+		rownames(value) <- layerNames(object)
 	} else {
-		if (n==1) {
-			colnames(value) <- 'value'
+		value <- t(matrix(value))
+		if (layerNames(object) == "") {
+			rownames(value) <- 'value'
 		} else {
-			colnames(value) <- paste('value', 1:n, sep="")
+			rownames(value) <- layerNames(object)
 		}
 	}
 	
 	if (xy) { 
-		value <- cbind(xyCoords, value)
-		colnames(value)[1] <- 'x'
-		colnames(value)[2] <- 'y'
+		value <- rbind(t(xy), value)
 	} 
 	return(t(value))
 	

Modified: pkg/raster/R/clump.R
===================================================================
--- pkg/raster/R/clump.R	2009-05-12 12:31:31 UTC (rev 456)
+++ pkg/raster/R/clump.R	2009-05-12 14:55:47 UTC (rev 457)
@@ -5,7 +5,7 @@
 # Licence GPL v3
 
 clump <- function(raster, filename=NULL, overwrite=FALSE, filetype='raster', datatype='INT4S', track=-1) {
-	warning('clump function has not completed yet; results are approximate')
+	warning('clump function is under development; results are approximate')
 	if (is.null(filename)) { filename <- "" }
 	if (filename != ""  & file.exists(filename) & overwrite==FALSE) {
 		stop("file exists. Use another name or 'overwrite=TRUE' if you want to overwrite it")
@@ -34,7 +34,7 @@
 		c1 <- c2
 		c2[] <- 0
 		b <- valuesRow(raster, r)
-		b <- which(b==1)
+		b <- which(b > 0)
 
 		for ( cc in b ) {
 			if (isTRUE(c2[cc-1] > 0)) { 
@@ -108,8 +108,8 @@
 		rclm <- c(0, 0, NA)
 	}
 	if (tmpfile1 == "") {
-		x1 <- reclass(x1, rclm, update=TRUE, filename=filename, datatype=datatype, overwrite=overwrite, track=track)
-		return(x1)
+		x2 <- reclass(x1, rclm, update=TRUE, filename=filename, datatype=datatype, overwrite=overwrite, track=track)
+		return(list(x1, x2, rcl1, rclm))
 	} else {
 		x2 <- reclass(x1, rclm, update=TRUE, filename=filename, datatype=datatype, overwrite=overwrite, track=track)
 		removeRasterFile(x1)

Modified: pkg/raster/man/KML.Rd
===================================================================
--- pkg/raster/man/KML.Rd	2009-05-12 12:31:31 UTC (rev 456)
+++ pkg/raster/man/KML.Rd	2009-05-12 14:55:47 UTC (rev 457)
@@ -19,8 +19,6 @@
 \item{maxdim}{sampling scheme}
 }
 
-\details{
-}
 
 \value{
 None. But two files are written to disk. 
@@ -28,7 +26,5 @@
 
 \author{adapted for the raster package by Robert J. Hijmans; based on functions in the maptools package by Duncan Golicher, David Forrest and Roger Bivand }
 
-\examples{
-}
 
 \keyword{spatial}

Modified: pkg/raster/man/click.Rd
===================================================================
--- pkg/raster/man/click.Rd	2009-05-12 12:31:31 UTC (rev 456)
+++ pkg/raster/man/click.Rd	2009-05-12 14:55:47 UTC (rev 457)
@@ -9,26 +9,34 @@
 }
 
 \usage{
-click(object, n=1, xy=FALSE, type = "n", ...)
+click(object, n=1, id=FALSE, xy=FALSE, type = "n", ...)
 }
 
-\note{
-  The plot only provides the coordinates (xy pair), the values are read from the Raster* object that is passed as an argument.
-  Thus you can extract values for a Raster* object that is not plotted, as long as it shares the coordinate system (CRS) with the layer that is plotted.
-}
 
 \arguments{
   \item{object}{RasterLayer or RasterStack object}
   \item{n}{number of clicks on the map}
-  \item{xy}{show xy coordinates}
+  \item{id}{Logical. If \code{TRUE}, a numeric ID is shown on the map that corresponds to the row number of the output}
+  \item{xy}{Logical. If \code{TRUE}, xy coordinates are included in the output}
   \item{type}{One of "n", "p", "l" or "o". If "p" or "o" the points are plotted; if "l" or "o" they are joined by lines. See ?locator}
   \item{...}{additional graphics parameters used if type != "n" for plotting the locations. See ?locator}   
  }
  
 \value{
-The value(s) of \code{object} at the point(s) clicked on; and the coordinates if \code{xy==TRUE}.
+The value(s) of \code{object} at the point(s) clicked on; and the coordinates of the center of the cell if \code{xy==TRUE}.
 } 
 
+\note{
+  The plot only provides the coordinates (xy pair), the values are read from the Raster* object that is passed as an argument.
+  Thus you can extract values for a Raster* object that is not plotted, as long as it shares the coordinate system (CRS) 
+  with the layer that is plotted.
+  
+  Unless the process is terminated prematurely values at at most \code{n} positions are determined. 
+  The identification process can be terminated by clicking the second button and selecting 'Stop' from the menu,
+  or from the 'Stop' menu on the graphics window. 
+}
+
+
 \seealso{ \code{\link[raster]{drawBox}} }
 
 \author{ Robert J. Hijmans }



More information about the Raster-commits mailing list