[Raster-commits] r407 - in pkg/raster: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Apr 15 07:05:23 CEST 2009
Author: rhijmans
Date: 2009-04-15 07:05:23 +0200 (Wed, 15 Apr 2009)
New Revision: 407
Added:
pkg/raster/man/cellFrom.Rd
pkg/raster/man/rowFromCell.Rd
Removed:
pkg/raster/man/getRowColCell.Rd
Modified:
pkg/raster/R/crop.R
pkg/raster/R/disaggregate.R
pkg/raster/R/rasterFromCells.R
Log:
Modified: pkg/raster/R/crop.R
===================================================================
--- pkg/raster/R/crop.R 2009-04-15 04:00:14 UTC (rev 406)
+++ pkg/raster/R/crop.R 2009-04-15 05:05:23 UTC (rev 407)
@@ -28,6 +28,13 @@
}
} else if ( dataSource(raster) == 'disk') {
+
+ if (!canProcessInMemory(outraster, 2) && filename == '') {
+ filename <- tempfile()
+ filename(outraster) <- filename
+ if (options('verbose')[[1]]) { cat('writing raster to:', filename(outraster)) }
+ }
+
starttime <- proc.time()
first_col <- colFromX(raster, xmin(outraster) + 0.5 * xres(outraster))
Modified: pkg/raster/R/disaggregate.R
===================================================================
--- pkg/raster/R/disaggregate.R 2009-04-15 04:00:14 UTC (rev 406)
+++ pkg/raster/R/disaggregate.R 2009-04-15 05:05:23 UTC (rev 407)
@@ -36,10 +36,10 @@
} else if ( dataSource(raster) == 'disk') {
- if (!canProcessInMemory(raster, 2 + xfact * yfact) && filename == '') {
+ if (!canProcessInMemory(outraster) && filename == '') {
filename <- tempfile()
filename(outraster) <- filename
- if (options('verbose')[[1]]) { cat('writing raster to:', filename(raster)) }
+ if (options('verbose')[[1]]) { cat('writing raster to:', filename) }
}
starttime <- proc.time()
Modified: pkg/raster/R/rasterFromCells.R
===================================================================
--- pkg/raster/R/rasterFromCells.R 2009-04-15 04:00:14 UTC (rev 406)
+++ pkg/raster/R/rasterFromCells.R 2009-04-15 05:05:23 UTC (rev 407)
@@ -5,19 +5,19 @@
# Licence GPL v3
-rasterFromCells <- function(raster, cells) {
+rasterFromCells <- function(object, cells) {
x <- unique(cells)
- cols <- colFromCell(raster, x)
- rows <- rowFromCell(raster, x)
- res <- resolution(raster)
- x1 <- xFromCol(raster, min(cols)) - 0.5 * res[1]
- x2 <- xFromCol(raster, max(cols)) + 0.5 * res[1]
- y1 <- yFromRow(raster, max(rows)) - 0.5 * res[2]
- y2 <- yFromRow(raster, min(rows)) + 0.5 * res[2]
+ cols <- colFromCell(object, x)
+ rows <- rowFromCell(object, x)
+ res <- resolution(object)
+ x1 <- xFromCol(object, min(cols)) - 0.5 * res[1]
+ x2 <- xFromCol(object, max(cols)) + 0.5 * res[1]
+ y1 <- yFromRow(object, max(rows)) - 0.5 * res[2]
+ y2 <- yFromRow(object, min(rows)) + 0.5 * res[2]
bb <- newBbox(x1, x2, y1, y2)
- raster <- clearValues(raster)
- cells2 <- cellsFromBbox(raster, bb)
- r <- crop(raster, bb)
+ object <- clearValues(object)
+ cells2 <- cellsFromBbox(object, bb)
+ r <- crop(object, bb)
r[] <- cells2
return(r)
}
Added: pkg/raster/man/cellFrom.Rd
===================================================================
--- pkg/raster/man/cellFrom.Rd (rev 0)
+++ pkg/raster/man/cellFrom.Rd 2009-04-15 05:05:23 UTC (rev 407)
@@ -0,0 +1,44 @@
+\name{rasterFromCells}
+
+\alias{rasterFromCells}
+
+
+\title{Subset a raster by cell numbers}
+
+\description{
+This function returns a new raster based on an existing raster and cell numbers for that raster.
+The new raster is cropped to the cellnumbers provided, and has values that are the cell numbers of the original raster.
+}
+
+\usage{
+rasterFromCells(object, cells)
+}
+
+\arguments{
+ \item{object}{Raster* object (or a SpatialPixels* or SpatialGrid* object)}
+ \item{cells}{vector of cell numbers}
+}
+
+\details{
+Cell numbers start at 1 in the upper left corner, and increase from left to right, and then from top to bottom
+The last cell number equals the number of cells of the Raster* object.
+
+}
+
+\value{
+A RasterLayer
+}
+
+\seealso{ \code{\link[raster]{rowFromCell}} }
+
+
+\author{Robert J. Hijmans }
+
+\examples{
+r <- raster(ncols=100, nrows=100)
+cells <- c(3:5, 210)
+r <- rasterFromCells(r, cells)
+cbind(1:ncell(r), values(r))
+}
+
+\keyword{spatial}
Deleted: pkg/raster/man/getRowColCell.Rd
===================================================================
--- pkg/raster/man/getRowColCell.Rd 2009-04-15 04:00:14 UTC (rev 406)
+++ pkg/raster/man/getRowColCell.Rd 2009-04-15 05:05:23 UTC (rev 407)
@@ -1,60 +0,0 @@
-\name{getRowColCell}
-
-\alias{colFromCell}
-\alias{rowFromCell}
-\alias{cellFromRowCol}
-\alias{cellFromRowColCombine}
-\alias{cellFromRow}
-\alias{cellFromCol}
-
-
-\title{Get row, column, or cell number}
-
-\description{
-These functions get the row or column number from a cell number of a Raster* object, or vice versa)
-}
-
-\usage{
-colFromCell(object, cell)
-rowFromCell(object, cell)
-cellFromRowCol(object, rownr, colnr)
-cellFromRowColCombine(object, rownr, colnr)
-cellFromRow(object, rownr)
-cellFromCol(object, colnr)
-}
-
-\arguments{
- \item{object}{Raster* object (or a SpatialPixels* or SpatialGrid* object)}
- \item{cell}{cell number(s)}
- \item{colnr}{column number; or vector of column numbers}
- \item{rownr}{row number; or vector of row numbers}
-}
-
-\details{
- The colFromCell and similar functions accept a single value (or x, y pair), or a vector or list of these values,
- Cell numbers start at 1 in the upper left corner, and increase from left to right, and then from top to bottom
- The last cell number equals the number of cells of the Raster* object.
-
- In \code{cellFromRowCol}, \code{rownr} and \code{colnr} should have the same length.
- This is not the case for \code{cellFromRowColCombine}. This function returns the cell numbers obtained by the combination of row and column numbers.
-
-}
-
-\value{
- row, col or cell number(s)
-}
-\author{Robert J. Hijmans }
-
-\examples{
-r <- raster(ncols=10, nrows=10)
-colFromCell(r, c(5,15))
-rowFromCell(r, c(5,15))
-cellFromRowCol(r, 5, 5)
-cellFromRowCol(r, 1:2, 1:2)
-cellFromRowColCombine(r, 1:3, 1:2)
-cellFromCol(r, 1)
-cellFromRow(r, 1)
-
-}
-
-\keyword{spatial}
Added: pkg/raster/man/rowFromCell.Rd
===================================================================
--- pkg/raster/man/rowFromCell.Rd (rev 0)
+++ pkg/raster/man/rowFromCell.Rd 2009-04-15 05:05:23 UTC (rev 407)
@@ -0,0 +1,44 @@
+\name{rowFromCell}
+
+\alias{colFromCell}
+\alias{rowFromCell}
+
+
+\title{Row or column number from a cell number}
+
+\description{
+These functions get the row or column number from a cell number of a Raster* object)
+}
+
+\usage{
+colFromCell(object, cell)
+rowFromCell(object, cell)
+}
+
+\arguments{
+ \item{object}{Raster* object (or a SpatialPixels* or SpatialGrid* object)}
+ \item{cell}{cell number(s)}
+}
+
+\details{
+ The colFromCell and similar functions accept a single value, or a vector or list of these values,
+ Cell numbers start at 1 in the upper left corner, and increase from left to right, and then from top to bottom
+ The last cell number equals the number of cells of the Raster* object.
+}
+
+\value{
+ row of column number(s)
+}
+
+\seealso{ \code{\link[raster]{cellFrom}} }
+
+
+\author{Robert J. Hijmans }
+
+\examples{
+r <- raster(ncols=10, nrows=10)
+colFromCell(r, c(5,15))
+rowFromCell(r, c(5,15))
+}
+
+\keyword{spatial}
More information about the Raster-commits
mailing list