[Raster-commits] r377 - in pkg/raster: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Mar 20 10:41:41 CET 2009
Author: rhijmans
Date: 2009-03-20 10:41:38 +0100 (Fri, 20 Mar 2009)
New Revision: 377
Added:
pkg/raster/R/saveAs.R
Modified:
pkg/raster/R/Artith.R
pkg/raster/R/Compare_Logical.R
pkg/raster/R/Math.R
pkg/raster/R/Merge.R
pkg/raster/R/aggregate.R
pkg/raster/R/calc.R
pkg/raster/R/calcStack.R
pkg/raster/R/copyRaster.R
pkg/raster/R/cover.R
pkg/raster/R/crop.R
pkg/raster/R/disaggregate.R
pkg/raster/R/distance.R
pkg/raster/R/expand.R
pkg/raster/R/init.R
pkg/raster/R/linesToRaster.R
pkg/raster/R/neighborhood.R
pkg/raster/R/overlayList.R
pkg/raster/R/pointsToRaster.R
pkg/raster/R/polygonToRaster.R
pkg/raster/R/project.R
pkg/raster/R/reclass.R
pkg/raster/R/resample.R
pkg/raster/R/summary.R
pkg/raster/R/write.R
pkg/raster/man/saveAs.Rd
pkg/raster/man/writeRaster.Rd
Log:
Modified: pkg/raster/R/Artith.R
===================================================================
--- pkg/raster/R/Artith.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/Artith.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -15,7 +15,7 @@
raster <- raster(e1, filename=tempfile())
for (r in 1:nrow(e1)) {
raster <- setValues(raster, callGeneric( as.numeric(.getRowValues(e1, r)), .getRowValues(e2, r) ), r)
- writeRaster(raster)
+ raster <- writeRaster(raster)
}
if (options('verbose')[[1]]) {
cat('values were written to:', raster at file@name)
@@ -35,7 +35,7 @@
raster <- raster(e1, filename=tempfile())
for (r in 1:nrow(e1)) {
raster <- setValues(raster, callGeneric( as.numeric(.getRowValues(e1, r)), e2) , r)
- writeRaster(raster)
+ raster <- writeRaster(raster)
}
if (options('verbose')[[1]]) {
cat('values were written to:', filename(raster))
@@ -53,7 +53,7 @@
raster <- raster(e2, filename=tempfile())
for (r in 1:nrow(e2)) {
raster <- setValues(raster, callGeneric(as.numeric(e1), .getRowValues(e2, r)) , r)
- writeRaster(raster)
+ raster <- writeRaster(raster)
}
if (options('verbose')[[1]]) {
cat('values were written to:', filename(raster))
Modified: pkg/raster/R/Compare_Logical.R
===================================================================
--- pkg/raster/R/Compare_Logical.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/Compare_Logical.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -49,7 +49,7 @@
dataType(rst) <- 'LOG1S'
for (r in 1:nrow(x)) {
rst <- setValues(rst, !.getRowValues(x, r), r)
- writeRaster(rst)
+ rst <- writeRaster(rst)
}
return(rst)
}
@@ -72,7 +72,7 @@
rowrep <- rep(e2, ncol(e1))
for (r in 1:nrow(e1)) {
rst <- setValues(rst, callGeneric( .getRowValues(e1, r), rowrep ), r)
- writeRaster(rst)
+ rst <- writeRaster(rst)
}
}
return(rst)
@@ -96,7 +96,7 @@
rowrep <- rep(e1, ncol(e2))
for (r in 1:nrow(e2)) {
rst <- setValues(rst, callGeneric( .getRowValues(e2, r), rowrep ), r)
- writeRaster(rst)
+ rst <- writeRaster(rst)
}
}
return(rst)
@@ -117,7 +117,7 @@
filename(rst) <- tempfile()
for (r in 1:nrow(e1)) {
rst <- setValues(rst, callGeneric( .getRowValues(e1, r), .getRowValues(e2, r) ), r)
- writeRaster(rst)
+ rst <- writeRaster(rst)
}
}
return(rst)
@@ -139,7 +139,7 @@
filename(rst) <- tempfile()
for (r in 1:nrow(e1)) {
rst <- setValues(rst, callGeneric( .getLogicalRowValues(e1, r), .getLogicalRowValues(e2, r) ), r)
- writeRaster(rst)
+ rst <- writeRaster(rst)
}
}
return(rst)
Modified: pkg/raster/R/Math.R
===================================================================
--- pkg/raster/R/Math.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/Math.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -22,7 +22,7 @@
}
for (r in 1:nrow(x)) {
rst <- setValues(rst, callGeneric( .getRowValues(x, r) ), r)
- writeRaster(rst)
+ rst <- writeRaster(rst)
}
if (options('verbose')[[1]]) {
cat('values were written to:', filename(raster))
@@ -49,7 +49,7 @@
}
for (r in 1:nrow(x)) {
rst <- setValues(rst, callGeneric(.getRowValues(x, r), digits), r)
- writeRaster(rst)
+ rst <- writeRaster(rst)
}
return(rst)
}
Modified: pkg/raster/R/Merge.R
===================================================================
--- pkg/raster/R/Merge.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/Merge.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -78,7 +78,7 @@
if (outraster at file@name != '') {
outraster <- setValues(outraster, rd, r)
- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
+ outraster <- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
} else {
v <- c(v, rd)
}
Modified: pkg/raster/R/aggregate.R
===================================================================
--- pkg/raster/R/aggregate.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/aggregate.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -55,7 +55,7 @@
outRaster <- setValues(outRaster, as.vector(tapply(values(x), cells, fun)))
}
if (outRaster at file@name != "") {
- writeRaster(outRaster, overwrite=overwrite, filetype=filetype)
+ outRaster <- writeRaster(outRaster, overwrite=overwrite, filetype=filetype)
}
} else if ( dataSource(x) == 'disk') {
@@ -94,7 +94,7 @@
v <- c(v, vals)
} else {
outRaster <- setValues(outRaster, vals, r)
- writeRaster(outRaster, overwrite=overwrite, filetype=filetype)
+ outRaster <- writeRaster(outRaster, overwrite=overwrite, filetype=filetype)
}
if (r %in% track) { .showTrack(r, outRaster at nrows, track, starttime) }
Modified: pkg/raster/R/calc.R
===================================================================
--- pkg/raster/R/calc.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/calc.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -27,12 +27,12 @@
if ( dataContent(x) == 'all') {
outraster <- setValues(outraster, fun(values(x)))
if (outraster at file@name != "") {
- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
+ outraster <- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
}
} else if ( dataContent(x) == 'sparse') {
outraster <- setValuesSparse(outraster, fun(values(x)), dataIndices(x))
if (outraster at file@name != "") {
- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
+ outraster <- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
}
} else if (dataSource(x) == 'disk') {
if (!canProcessInMemory(x, 3) & filename == '') {
@@ -48,7 +48,7 @@
v <- c(v, fun(values(x)))
} else {
outraster <- setValues(outraster, fun(values(x)), r)
- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
+ outraster <- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
}
if (r %in% track) { .showTrack(r, outraster at nrows, track, starttime) }
Modified: pkg/raster/R/calcStack.R
===================================================================
--- pkg/raster/R/calcStack.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/calcStack.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -21,7 +21,7 @@
if (dataContent(x) == "all") {
outraster <- setValues(outraster, apply(values(x), 1, fun))
if (filename != "") {
- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
+ outraster <- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
}
} else {
starttime <- proc.time()
@@ -36,7 +36,7 @@
v <- c(v, apply(values(x), 1, fun))
} else {
outraster <- setValues(outraster, apply(values(x), 1, fun), r)
- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
+ outraster <- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
}
if (r %in% track) { .showTrack(r, outraster at nrows, track, starttime) }
Modified: pkg/raster/R/copyRaster.R
===================================================================
--- pkg/raster/R/copyRaster.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/copyRaster.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -5,32 +5,6 @@
# Licence GPL v3
-saveAs <- function(raster, filename, filetype='raster', datatype='FLT4S', overwrite=FALSE) {
-
- if (dataContent(raster) == 'all') {
- dataType(raster) <- datatype
- filename(raster) <- filename
- writeRaster(raster, filetype=filetype, overwrite=overwrite)
- return(raster)
- }
-
- if ( trim(filename(raster)) == trim(filename) ) {
- stop('filenames should be different')
- }
-
-# if filetype and datatype are the same, then use copyRasterfile
-
- newr <- raster(raster, filename)
- dataType(newr) <- datatype
- for (r in 1:nrow(newr)) {
- raster <- readRow(raster, r)
- newr <- setValues(newr, values(raster), r)
- writeRaster(newr, filetype=filetype, overwrite=overwrite)
- }
- return(newr)
-}
-
-
moveRasterFile <- function(raster, filename, overwrite=FALSE) {
r <- copyRasterFile(raster, filename, overwrite)
f <- trim(filename(raster))
Modified: pkg/raster/R/cover.R
===================================================================
--- pkg/raster/R/cover.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/cover.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -25,7 +25,7 @@
rm(y)
outRaster <- setValues(outRaster, values(x))
if (outRaster at file@name != "") {
- writeRaster(outRaster, filetype=filetype, overwrite=overwrite)
+ outRaster <- writeRaster(outRaster, filetype=filetype, overwrite=overwrite)
}
} else {
if (dataContent(x) == 'nodata' & dataSource(x) == 'ram' ) {
@@ -52,7 +52,7 @@
v <- c(v, vals)
} else {
outRaster <- setValues(outRaster, vals, r)
- writeRaster(outRaster, filetype=filetype, overwrite=overwrite)
+ outRaster <- writeRaster(outRaster, filetype=filetype, overwrite=overwrite)
}
if (r %in% track) { .showTrack(r, outRaster at nrows, track, starttime) }
Modified: pkg/raster/R/crop.R
===================================================================
--- pkg/raster/R/crop.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/crop.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -24,7 +24,7 @@
outraster <- setValues(outraster, values(raster)[selected_cells])
outraster <- setMinMax(outraster)
if (outraster at file@name != "") {
- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
+ outraster <- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
}
} else if ( dataSource(raster) == 'disk') {
@@ -41,7 +41,7 @@
v <- c(v, values(raster))
} else {
outraster <- setValues(outraster, values(raster), rownr)
- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
+ outraster <- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
}
rownr <- rownr + 1
Modified: pkg/raster/R/disaggregate.R
===================================================================
--- pkg/raster/R/disaggregate.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/disaggregate.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -31,7 +31,7 @@
cells <- cellFromRowCol(raster, rows, cols)
outraster <- setValues(outraster, values(raster)[cells])
if (outraster at file@name != "") {
- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
+ outraster <- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
}
} else if ( dataSource(raster) == 'disk') {
@@ -47,7 +47,7 @@
v <- c(v, values(raster)[cols])
} else {
outraster <- setValues(outraster, values(raster)[cols], (r-1) * xfact + i)
- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
+ outraster <- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
}
}
}
Modified: pkg/raster/R/distance.R
===================================================================
--- pkg/raster/R/distance.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/distance.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -64,7 +64,7 @@
outRowValues <- rep(Inf,times=ncols)
outRowValues[is.na(rowValues)] <- 0
outRaster <- setValues(outRaster, outRowValues, r)
- writeRaster(outRaster, overwrite=TRUE)
+ outRaster <- writeRaster(outRaster, overwrite=TRUE)
}
if(isLatLon(object)){
remainingCells <- TRUE
@@ -91,7 +91,7 @@
rowWindow[index]
# startRow is undefined
# outRaster <- setValues(outRaster, rowValues, startRow)
- writeRaster(outRaster, overwrite=TRUE)
+ outRaster <- writeRaster(outRaster, overwrite=TRUE)
if(r > 1){
rowWindow <- rowWindow[-1:ncols]
}
@@ -126,7 +126,7 @@
rowWindow[index]
# startRow is undefined
#outRaster <- setValues(outRaster, rowValues, startRow)
- writeRaster(outRaster, overwrite=TRUE)
+ outRaster <- writeRaster(outRaster, overwrite=TRUE)
if(r > 1){
rowWindow <- rowWindow[-1:ncols]
}
Modified: pkg/raster/R/expand.R
===================================================================
--- pkg/raster/R/expand.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/expand.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -41,7 +41,7 @@
d[startcell:(startcell+ncol(raster)-1)] <- vals
outraster <- setValues(outraster, d)
if (outraster at file@name != "") {
- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
+ outraster <- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
}
}
@@ -65,7 +65,7 @@
if (outraster at file@name != '') {
outraster <- setValues(outraster, d, r)
- outraster <- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
+ outraster <- outraster <- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
} else {
v <- c(v, d)
}
Modified: pkg/raster/R/init.R
===================================================================
--- pkg/raster/R/init.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/init.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -14,7 +14,7 @@
n <- ncell(raster)
outraster <- setValues(outraster, fun(n))
if (outraster at file@name != "") {
- writeRaster(outraster, overwrite=overwrite)
+ outraster <- writeRaster(outraster, overwrite=overwrite)
}
} else if (dataSource(raster) == 'disk') {
@@ -28,7 +28,7 @@
v <- c(v, fun(n))
} else {
outraster <- setValues(outraster, fun(n), r)
- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
+ outraster <- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
}
if (r %in% track) { .showTrack(r, outraster at nrows, track, starttime) }
Modified: pkg/raster/R/linesToRaster.R
===================================================================
--- pkg/raster/R/linesToRaster.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/linesToRaster.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -195,7 +195,7 @@
v <- c(v, rv)
} else {
raster <- setValues(raster, values=rv, rownr=r)
- writeRaster(raster, filetype=filetype)
+ raster <- writeRaster(raster, filetype=filetype)
}
if (r %in% track) { .showTrack(r, raster at nrows, track, starttime) }
Modified: pkg/raster/R/neighborhood.R
===================================================================
--- pkg/raster/R/neighborhood.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/neighborhood.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -70,7 +70,7 @@
ngbvals <- .calc.ngb(ngbdata, ngb, fun, keepdata)
if (filename != "") {
ngbgrid <- setValues(ngbgrid, ngbvals, rr)
- writeRaster(ngbgrid, overwrite=overwrite, filetype=filetype)
+ ngbgrid <- writeRaster(ngbgrid, overwrite=overwrite, filetype=filetype)
} else {
v <- c(v, ngbvals)
}
@@ -87,7 +87,7 @@
ngbvals <- .calc.ngb(ngbdata, ngb, fun, keepdata)
if (filename != "") {
ngbgrid <- setValues(ngbgrid, ngbvals, rr)
- writeRaster(ngbgrid, overwrite=overwrite, filetype=filetype)
+ ngbgrid <- writeRaster(ngbgrid, overwrite=overwrite, filetype=filetype)
} else {
v <- c(v, ngbvals)
}
Modified: pkg/raster/R/overlayList.R
===================================================================
--- pkg/raster/R/overlayList.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/overlayList.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -30,7 +30,7 @@
outraster <- setValues(outraster, vals)
if (outraster at file@name != "") {
- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
+ outraster <- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
}
} else {
@@ -66,7 +66,7 @@
v[startcells[r]:endcells[r]] <- vals
} else {
outraster <- setValues(outraster, vals, r)
- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
+ outraster <- writeRaster(outraster, filetype=filetype, overwrite=overwrite)
}
if (r %in% track) { .showTrack(r, outraster at nrows, track, starttime) }
Modified: pkg/raster/R/pointsToRaster.R
===================================================================
--- pkg/raster/R/pointsToRaster.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/pointsToRaster.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -38,7 +38,7 @@
}
if (filename != "") {
rs <- setValues(rs, d, r)
- writeRaster(rs, overwrite=overwrite, filetype=filetype)
+ rs <- writeRaster(rs, overwrite=overwrite, filetype=filetype)
} else {
v <- c(v, d)
}
Modified: pkg/raster/R/polygonToRaster.R
===================================================================
--- pkg/raster/R/polygonToRaster.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/polygonToRaster.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -205,7 +205,7 @@
v <- c(v, rv)
} else {
raster <- setValues(raster, values=rv, rownr=r)
- writeRaster(raster, overwrite=overwrite, filetype=filetype)
+ raster <- writeRaster(raster, overwrite=overwrite, filetype=filetype)
}
if (r %in% track) { .showTrack(r, raster at nrows, track, starttime) }
@@ -269,7 +269,7 @@
v <- c(v, vals)
} else {
raster <- setValues(raster, vals, r)
- writeRaster(raster, overwrite=overwrite)
+ raster <- writeRaster(raster, overwrite=overwrite)
}
}
if (filename == "") {
Modified: pkg/raster/R/project.R
===================================================================
--- pkg/raster/R/project.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/project.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -83,7 +83,7 @@
v <- c(v, vals)
} else {
to <- setValues(to, vals, r)
- writeRaster(to, overwrite=overwrite)
+ to <- writeRaster(to, overwrite=overwrite)
}
if (r %in% track) { .showTrack(r, to at nrows, track, starttime) }
@@ -92,7 +92,7 @@
if (inMemory) {
to <- setValues(to, v)
if (to at file@name != "") {
- writeRaster(to, overwrite=overwrite)
+ to <- writeRaster(to, overwrite=overwrite)
}
}
return(to)
Modified: pkg/raster/R/reclass.R
===================================================================
--- pkg/raster/R/reclass.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/reclass.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -42,7 +42,7 @@
outraster <- setValues(outraster, res, dataIndices(raster))
}
if (outraster at file@name != "" ) {
- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
+ outraster <- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
}
} else {
@@ -59,7 +59,7 @@
}
}
outraster <- setValues(outraster, res, r)
- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
+ outraster <- writeRaster(outraster, overwrite=overwrite, filetype=filetype)
}
if (r %in% track) { .showTrack(r, outraster at nrows, track, starttime) }
}
Modified: pkg/raster/R/resample.R
===================================================================
--- pkg/raster/R/resample.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/resample.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -38,7 +38,7 @@
v <- c(v, vals)
} else {
to <- setValues(to, vals, r)
- writeRaster(to, overwrite=overwrite, filetype=filetype)
+ to <- writeRaster(to, overwrite=overwrite, filetype=filetype)
}
if (r %in% track) { .showTrack(r, to at nrows, track, starttime) }
Added: pkg/raster/R/saveAs.R
===================================================================
--- pkg/raster/R/saveAs.R (rev 0)
+++ pkg/raster/R/saveAs.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -0,0 +1,35 @@
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# International Rice Research Institute
+# Date : February 2009
+# Version 0.8
+# Licence GPL v3
+
+
+saveAs <- function(raster, filename, filetype='raster', datatype='FLT4S', overwrite=FALSE, result=TRUE) {
+
+ if (dataContent(raster) == 'all') {
+ dataType(raster) <- datatype
+ filename(raster) <- filename
+ raster <- writeRaster(raster, filetype=filetype, overwrite=overwrite)
+ return(raster)
+ }
+
+ if ( trim(filename(raster)) == trim(filename) ) {
+ stop('filenames should be different')
+ }
+
+# if filetype and datatype are the same, then use copyRasterfile
+ newr <- raster(raster, filename)
+ dataType(newr) <- datatype
+ for (r in 1:nrow(newr)) {
+ raster <- readRow(raster, r)
+ newr <- setValues(newr, values(raster), r)
+ newr <- writeRaster(newr, filetype=filetype, overwrite=overwrite)
+ }
+ if (result) {
+ return(newr)
+ } else {
+ return(invisible())
+ }
+}
+
Modified: pkg/raster/R/summary.R
===================================================================
--- pkg/raster/R/summary.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/summary.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -48,7 +48,7 @@
v <- c(v, vv)
} else {
raster <- setValues(raster, vv, r)
- writeRaster(raster)
+ raster <- writeRaster(raster)
}
}
if (filename == "") {
Modified: pkg/raster/R/write.R
===================================================================
--- pkg/raster/R/write.R 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/R/write.R 2009-03-20 09:41:38 UTC (rev 377)
@@ -1,8 +1,7 @@
-
# Author: Robert J. Hijmans, r.hijmans at gmail.com
# International Rice Research Institute
# Date : June 2008
-# Version 0,1
+# Version 0.8
# Licence GPL v3
@@ -18,8 +17,8 @@
-writeRaster <- function(raster, filetype='raster', overwrite=FALSE) {
- raster_name <- deparse(substitute(raster))
+writeRaster <- function(raster, filetype='raster', overwrite=FALSE, assign=FALSE) {
+ if (assign){ raster_name <- deparse(substitute(raster))}
if (dataContent(raster) != 'row' & dataContent(raster) != 'all' & dataContent(raster) != 'sparse' ) {
stop('No usable data available for writing. First use setValues()')
@@ -41,9 +40,12 @@
raster <- .writeGDALall(raster, gdalfiletype=filetype, overwrite=overwrite, mvFlag=NA, options=NULL)
}
}
- assign(raster_name, raster, envir=parent.frame())
-# return(invisible())
- return(raster)
+ if (assign) {
+ assign(raster_name, raster, envir=parent.frame())
+ return(invisible())
+ } else {
+ return(raster)
+ }
}
Modified: pkg/raster/man/saveAs.Rd
===================================================================
--- pkg/raster/man/saveAs.Rd 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/man/saveAs.Rd 2009-03-20 09:41:38 UTC (rev 377)
@@ -5,11 +5,11 @@
\title{Save a raster file to a different format}
\description{
- Save a raster file (on disk) to another format.
+Save a raster file to a file of another type (format).
}
\usage{
- saveAs(raster, filename, filetype='raster', datatype='FLT4S', overwrite=FALSE)
+saveAs(raster, filename, filetype='raster', datatype='FLT4S', overwrite=FALSE, result=TRUE)
}
\arguments{
@@ -18,8 +18,13 @@
\item{filetype}{either 'raster', 'ascii' or a supported GDAL 'driver' name (see below)}
\item{datatype}{output data type; see below}
\item{overwrite}{Logical. If \code{TRUE} existing files are overwritten}
+ \item{result}{Logical. If \code{TRUE} a new RasterLayer object is returned, else the function returns nothing}
}
+\value{
+A RasterLayer object or nothing \code{result=FALSE}. This function is used for its side-effect of writing a file to disk.
+}
+
\details{
Supported datatypes include:
Modified: pkg/raster/man/writeRaster.Rd
===================================================================
--- pkg/raster/man/writeRaster.Rd 2009-03-20 08:19:16 UTC (rev 376)
+++ pkg/raster/man/writeRaster.Rd 2009-03-20 09:41:38 UTC (rev 377)
@@ -10,13 +10,14 @@
}
\usage{
-writeRaster(raster, filetype='raster', overwrite=FALSE)
+writeRaster(raster, filetype='raster', overwrite=FALSE, assign=FALSE)
}
\arguments{
\item{raster}{RasterLayer object}
\item{filetype}{either 'raster', 'ascii' or a supported GDAL 'driver' name (see below)}
\item{overwrite}{Logical. If \code{TRUE} existing files are overwritten}
+ \item{assign}{Logical. If \code{TRUE} the function does not return a new object but overwrites the existing object}
}
\details{
@@ -59,21 +60,25 @@
# write all to a new binary file
filename(rst) <- "binall.grd"
-writeRaster(rst, overwrite=TRUE)
+rst <- writeRaster(rst, overwrite=TRUE)
+# equivalent to:
+writeRaster(rst, overwrite=TRUE, assign=TRUE)
+
+
# write all to a new ERDAS .img file
filename(rst) <- "binall.img"
-writeRaster(rst, filetype="HFA", overwrite=TRUE)
+rst <- writeRaster(rst, filetype="HFA", overwrite=TRUE)
# write all to an integer binary file
filename(rst) <- "binallint.grd"
dataType(rst) <- "INT4S"
-writeRaster(rst, overwrite=TRUE)
+rst <- writeRaster(rst, overwrite=TRUE)
# write all to ascii file
filename(rst) <- "ascall.asc"
-writeRaster(rst, filetype='ascii', overwrite=TRUE)
+rst <- writeRaster(rst, filetype='ascii', overwrite=TRUE)
# read and write row by row; write to ascii file
rst <- raster(system.file("external/test.ag", package="sp"))
@@ -82,7 +87,7 @@
rst <- readRow(rst, r)
v <- values(rst) * 10
ascras <- setValues(ascras, v, r)
- writeRaster(ascras, filetype='ascii', overwrite=TRUE)
+ ascras <- writeRaster(ascras, filetype='ascii', overwrite=TRUE)
}
# read and write row by row; write to binary file
@@ -90,7 +95,7 @@
for (r in 1:nrow(rst)) {
rst <- readRow(rst, r)
binras <- setValues(binras, values(rst), r)
- writeRaster(binras, overwrite=TRUE)
+ binras <- writeRaster(binras, overwrite=TRUE)
}
# read and write row by row; write to GeoTiff binary file
@@ -98,7 +103,7 @@
for (r in 1:nrow(rst)) {
rst <- readRow(rst, r)
binras <- setValues(binras, values(rst), r)
- writeRaster(binras, filetype="GTiff", overwrite=TRUE)
+ binras <- writeRaster(binras, filetype="GTiff", overwrite=TRUE)
}
}
More information about the Raster-commits
mailing list