[Raster-commits] r406 - pkg/raster/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Apr 15 06:00:14 CEST 2009
Author: rhijmans
Date: 2009-04-15 06:00:14 +0200 (Wed, 15 Apr 2009)
New Revision: 406
Added:
pkg/raster/R/rasterFromCells.R
Log:
Added: pkg/raster/R/rasterFromCells.R
===================================================================
--- pkg/raster/R/rasterFromCells.R (rev 0)
+++ pkg/raster/R/rasterFromCells.R 2009-04-15 04:00:14 UTC (rev 406)
@@ -0,0 +1,24 @@
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date : April 2009
+# Version 0.8
+# Licence GPL v3
+
+
+rasterFromCells <- function(raster, 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]
+ bb <- newBbox(x1, x2, y1, y2)
+ raster <- clearValues(raster)
+ cells2 <- cellsFromBbox(raster, bb)
+ r <- crop(raster, bb)
+ r[] <- cells2
+ return(r)
+}
+
More information about the Raster-commits
mailing list