[Raster-commits] r247 - in pkg/raster: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Feb 6 02:32:47 CET 2009
Author: rhijmans
Date: 2009-02-06 02:32:46 +0100 (Fri, 06 Feb 2009)
New Revision: 247
Modified:
pkg/raster/R/aggregate.R
pkg/raster/R/bounding.box.R
pkg/raster/R/click.R
pkg/raster/R/polygonToRaster.R
pkg/raster/man/PolygonsToRaster.Rd
pkg/raster/man/bbox.Rd
Log:
Modified: pkg/raster/R/aggregate.R
===================================================================
--- pkg/raster/R/aggregate.R 2009-02-05 01:33:34 UTC (rev 246)
+++ pkg/raster/R/aggregate.R 2009-02-06 01:32:46 UTC (rev 247)
@@ -48,7 +48,7 @@
if (rm.NA) { outRaster <- setValues(outRaster, as.vector(tapply(values(x), cells, function(x){fun(na.omit(x))})))
} else {outRaster <- setValues(outRaster, as.vector(tapply(values(x), cells, fun))) }
- if (filename(outRaster) != "") {writex(outRaster, overwrite=overwrite)}
+ if (filename(outRaster) != "") {writeRaster(outRaster, overwrite=overwrite)}
} else if ( dataSource(x) == 'disk') {
@@ -78,7 +78,7 @@
v <- c(v, vals)
} else {
outRaster <- setValues(outRaster, vals, r)
- outRaster <- writex(outRaster, overwrite=overwrite)
+ outRaster <- writeRaster(outRaster, overwrite=overwrite)
}
}
if (filename(outRaster) == "") {
Modified: pkg/raster/R/bounding.box.R
===================================================================
--- pkg/raster/R/bounding.box.R 2009-02-05 01:33:34 UTC (rev 246)
+++ pkg/raster/R/bounding.box.R 2009-02-06 01:32:46 UTC (rev 247)
@@ -8,7 +8,14 @@
+polygonFromBbox <- function(bndbox) {
+ bb <- getBbox(bndbox)
+ p <- rbind(c(bb at xmin, bb at ymin), c(bb at xmin, bb at ymax), c(bb at xmax, bb at ymax), c(bb at xmax, bb at ymin), c(bb at xmin, bb at ymin) )
+ pol <- SpatialPolygons(list(Polygons(list(Polygon(p)), 1)))
+ return(pol)
+}
+
newBbox <- function(xmn, xmx, ymn, ymx) {
bb <- new('BoundingBox')
bb at xmin <- xmn
Modified: pkg/raster/R/click.R
===================================================================
--- pkg/raster/R/click.R 2009-02-05 01:33:34 UTC (rev 246)
+++ pkg/raster/R/click.R 2009-02-06 01:32:46 UTC (rev 247)
@@ -6,12 +6,6 @@
# Version 0.8
# Licence GPL v3
-BboxToPolygon <- function(bbox) {
- bbox <- getBbox(bbox)
- p <- rbind(c(bbox at xmin, bbox at ymin), c(bbox at xmin, bbox at ymax), c(bbox at xmax, bbox at ymax), c(bbox at xmax, bbox at ymin), c(bbox at xmin, bbox at ymin) )
- pol <- SpatialPolygons(list(Polygons(list(Polygon(p)), 1)))
- return(pol)
-}
clickBbox <- function(show=TRUE, col="red") {
loc <- locator(n=2, type="p")
Modified: pkg/raster/R/polygonToRaster.R
===================================================================
--- pkg/raster/R/polygonToRaster.R 2009-02-05 01:33:34 UTC (rev 246)
+++ pkg/raster/R/polygonToRaster.R 2009-02-06 01:32:46 UTC (rev 247)
@@ -59,8 +59,10 @@
-polygonsToRaster <- function(spPolys, raster, field=0, filename="", overwrite=FALSE, updateRaster=FALSE, updateValue="NA", trackRows=0) {
+polygonsToRaster <- function(spPolys, raster, field=0, filename="", overwrite=FALSE, updateRaster=FALSE, updateValue="NA", trackRows=c(1,2,3,5,10*1:9,100*1:10)) {
filename <- trim(filename)
+ starttime <- proc.time()
+
if (updateRaster) {
oldraster <- raster
if (!(updateValue == 'NA' | updateValue == '!NA' | updateValue == 'all' | updateValue == 'zero')) {
@@ -106,9 +108,6 @@
rxmn <- xmin(raster) + 0.1 * xres(raster)
rxmx <- xmax(raster) - 0.1 * xres(raster)
for (r in 1:nrow(raster)) {
- if (r %in% trackRows) {
- print(paste('row', r, '---', nrow(raster)+1-r, " rows to go"))
- }
rv <- rep(NA, ncol(raster))
holes <- rep(FALSE, ncol(raster))
@@ -177,12 +176,23 @@
v <- c(v, rv)
} else {
raster <- setValues(raster, values=rv, rownr=r)
- raster <- writeRaster(raster)
+ raster <- writeRaster(raster, overwrite=overwrite)
}
+
+ if (r %in% trackRows) {
+ elapsed <- (proc.time() - starttime)[3]
+ tpr <- round((elapsed /r), digits=2)
+ print(paste('row', r, '--', tpr, 'seconds/row --', nrow(raster)+1-r, " rows to go"))
+ }
+
}
if (filename == "") {
raster <- setValues(raster, v)
}
+
+ elapsed <- (proc.time() - starttime)[3]
+ tpr <- round((elapsed /r), digits=2)
+ print(paste('finished in ', round(elapsed/60, digits=1), 'minutes, at', tpr, 'seconds/row'))
return(raster)
}
@@ -233,7 +243,7 @@
v <- c(v, vals)
} else {
raster <- setValues(raster, vals, r)
- raster <- writeRaster(raster)
+ raster <- writeRaster(raster, overwrite=overwrite)
}
}
if (filename == "") {
Modified: pkg/raster/man/PolygonsToRaster.Rd
===================================================================
--- pkg/raster/man/PolygonsToRaster.Rd 2009-02-05 01:33:34 UTC (rev 246)
+++ pkg/raster/man/PolygonsToRaster.Rd 2009-02-06 01:32:46 UTC (rev 247)
@@ -33,7 +33,7 @@
\examples{
cds1 <- rbind(c(-50,0), c(0,60), c(40,5), c(15,-45), c(-10,-25), c(-50,0))
cds2 <- rbind(c(80,20), c(140,60), c(160,0), c(140,-55), c(80,20))
-cds3 <- rbind(c(-180,-20), c(-140,-60), c(-60,-20), c(-140,55), c(-180,-20))
+cds3 <- rbind(c(-180,-20), c(-140,55), c(-60,-20), c(-140,-60), c(-180,-20))
hole <- rbind(c(-150,-20), c(-100,-10), c(-110,20), c(-150,-20))
polys <- SpatialPolygons(list(Polygons(list(Polygon(cds1)), 1), Polygons(list(Polygon(cds2)), 2), Polygons(list(Polygon(cds3)), 3), Polygons(list(Polygon(hole)), 4) ))
Modified: pkg/raster/man/bbox.Rd
===================================================================
--- pkg/raster/man/bbox.Rd 2009-02-05 01:33:34 UTC (rev 246)
+++ pkg/raster/man/bbox.Rd 2009-02-06 01:32:46 UTC (rev 247)
@@ -11,6 +11,7 @@
\alias{setBbox}
\alias{changeBbox}
\alias{cellsFromBbox}
+\alias{polygonFromBbox}
\alias{xmin<-}
\alias{xmax<-}
@@ -23,7 +24,7 @@
newBbox creates a new bounding box (as in the "Spatial" object from the SP package)
setBbox sets the bounding box of a Raster* object
changeBbox changes the bounding box of a Raster* object
-
+polygonFromBbox creates a SpatialPolygon object from a BoundingBox object (or a Raster*) object
You can also use bbox(object) to get a sp type bbox (a 2 x 2 matrix), but such an object cannot be used with the other functon described here as it returns a matrix, and not a BoundingBox object.
}
@@ -33,6 +34,7 @@
setBbox(object, bndbox, keepres=FALSE, snap=FALSE)
changeBbox(object, xmn=xmin(object), xmx=xmax(object), ymn=ymin(object), ymx = ymax(object), keepres=FALSE)
cellsFromBbox(object, bndbox)
+polygonFromBbox(bndbox)
}
\arguments{
More information about the Raster-commits
mailing list