[Raster-commits] r404 - in pkg/raster: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Apr 14 08:50:11 CEST 2009
Author: rhijmans
Date: 2009-04-14 08:50:10 +0200 (Tue, 14 Apr 2009)
New Revision: 404
Modified:
pkg/raster/R/aggregate.R
pkg/raster/R/copyRaster.R
pkg/raster/R/disaggregate.R
pkg/raster/R/setValues.R
pkg/raster/man/copyRasterFile.Rd
pkg/raster/man/setValues.Rd
Log:
Modified: pkg/raster/R/aggregate.R
===================================================================
--- pkg/raster/R/aggregate.R 2009-04-13 05:53:17 UTC (rev 403)
+++ pkg/raster/R/aggregate.R 2009-04-14 06:50:10 UTC (rev 404)
@@ -72,7 +72,7 @@
}
} else if ( dataSource(x) == 'disk') {
- if (!canProcessInMemory(x, 3) && filename == '') {
+ if (!canProcessInMemory(x, 2) && filename == '') {
filename <- tempfile()
filename(outraster) <- filename
if (options('verbose')[[1]]) { cat('writing raster to:', filename(raster)) }
Modified: pkg/raster/R/copyRaster.R
===================================================================
--- pkg/raster/R/copyRaster.R 2009-04-13 05:53:17 UTC (rev 403)
+++ pkg/raster/R/copyRaster.R 2009-04-14 06:50:10 UTC (rev 404)
@@ -46,3 +46,48 @@
+removeFile <- function(raster) {
+ raster <- closeConnection(raster)
+ fname <- filename(raster)
+ fileext <- toupper(ext(fname))
+ if (fileext == ".GRD") {
+ fgrd <- fname
+ ext(fgrd) <- '.grd'
+ fgri <- fname
+ ext(fgri) <- '.gri'
+ if (!file.exists(fgrd) | !file.exists(fgri)) {
+ stop('file does not exist')
+ }
+ res <- file.remove(fgrd)
+ if (!res) { stop('could not remove grd file') }
+ res <- file.remove(fgri)
+ if (!res) { stop('could not remove gri file') }
+ } else {
+ stop('only implemented for raster format files')
+ }
+ filename(raster) <- ''
+ return(raster)
+}
+
+
+
+removeRasterFile <- function(filename) {
+ fname <- trim(filename)
+ fileext <- toupper(ext(fname))
+ if (fileext == ".GRD") {
+ fgrd <- fname
+ ext(fgrd) <- '.grd'
+ fgri <- fname
+ ext(fgri) <- '.gri'
+ if (!file.exists(fgrd) | !file.exists(fgri)) {
+ stop('file does not exist')
+ }
+ res <- file.remove(fgrd)
+ if (!res) { stop('could not remove grd file') }
+ res <- file.remove(fgri)
+ if (!res) { stop('could not remove gri file') }
+ } else {
+ stop('only implemented for raster format files')
+ }
+}
+
Modified: pkg/raster/R/disaggregate.R
===================================================================
--- pkg/raster/R/disaggregate.R 2009-04-13 05:53:17 UTC (rev 403)
+++ pkg/raster/R/disaggregate.R 2009-04-14 06:50:10 UTC (rev 404)
@@ -35,7 +35,8 @@
}
} else if ( dataSource(raster) == 'disk') {
- if (!canProcessInMemory(raster, 3) && filename == '') {
+
+ if (!canProcessInMemory(raster, 2 + xfact * yfact) && filename == '') {
filename <- tempfile()
filename(outraster) <- filename
if (options('verbose')[[1]]) { cat('writing raster to:', filename(raster)) }
Modified: pkg/raster/R/setValues.R
===================================================================
--- pkg/raster/R/setValues.R 2009-04-13 05:53:17 UTC (rev 403)
+++ pkg/raster/R/setValues.R 2009-04-14 06:50:10 UTC (rev 404)
@@ -5,22 +5,19 @@
# Licence GPL v3
-setValuesRows <- function(object, values, startrow, endrow) {
+setValuesRows <- function(object, values, firstcell, lastcell) {
if (!is.vector(values)) {stop('values must be a vector')}
if (!(is.numeric(values) | is.integer(values) | is.logical(values))) {
- stop('values must be numeric, integer or logical.') }
- startow <- round(start)
- endrow <- round(endrow)
- if (startrow > endrow) {stop()}
- if (startrow < 1 | startrow > nrow(object)) {
- stop(paste("rownumber out of bounds"))
+ stop('values must be numeric, integer or logical.')
}
+ if (firstcell > lastcell) {stop()}
+ if (firstcell < 1 | lastcell > ncell(object)) {
+ stop(paste("indices out of bounds"))
+ }
object at data@values <- values
- object at data@content <- 'row'
- firstcell <- cellFromRowCol(object, rownr=startrow, colnr=1)
- lastcell <- cellFromRowCol(object, rownr=endrow, colnr=ncol(object))
+ object at data@content <- 'rows'
object at data@indices <- c(firstcell, lastcell)
- if (length(values) != (lastcell-firstcell) + 1) {stop('wrong length')}
+ if (length(values) != (lastcell-firstcell + 1)) {stop('wrong length')}
return(object)
}
Modified: pkg/raster/man/copyRasterFile.Rd
===================================================================
--- pkg/raster/man/copyRasterFile.Rd 2009-04-13 05:53:17 UTC (rev 403)
+++ pkg/raster/man/copyRasterFile.Rd 2009-04-14 06:50:10 UTC (rev 404)
@@ -2,22 +2,27 @@
\alias{moveRasterFile}
\alias{copyRasterFile}
+\alias{removeRasterFile}
+\alias{removeFile}
+
\title{move or copy a raster file}
\description{
-Move or copy a raster file to a different location (filename).
+Move, copy or remove 'raster' format files. removeRaster removes the files on disk that are associated with the RasterLayer object.
}
\usage{
- moveRasterFile(raster, filename, overwrite=FALSE)
- copyRasterFile(raster, filename, overwrite=FALSE)
+moveRasterFile(raster, filename, overwrite=FALSE)
+copyRasterFile(raster, filename, overwrite=FALSE)
+removeRasterFile(filename)
+removeFile(raster)
}
\arguments{
- \item{raster}{RasterLayer object that is associated with a file on disk}
- \item{filename}{output filename}
- \item{overwrite}{Logical. If \code{TRUE} existing files are overwritten}
+\item{raster}{RasterLayer object that is associated with a file on disk}
+\item{filename}{Output filename}
+\item{overwrite}{Logical. If \code{TRUE} existing files are overwritten}
}
Modified: pkg/raster/man/setValues.Rd
===================================================================
--- pkg/raster/man/setValues.Rd 2009-04-13 05:53:17 UTC (rev 403)
+++ pkg/raster/man/setValues.Rd 2009-04-14 06:50:10 UTC (rev 404)
@@ -17,25 +17,23 @@
\usage{
setValues(object, values, rownr=-1, layer=-1)
-setValuesRows(object, values, startrow, endrow)
+setValuesRows(object, values, firstcell, lastcell)
setValuesBlock(raster, blockvalues, firstcell, lastcell)
setValuesSparse(raster, sparsevalues, cellnumbers)
clearValues(object)
}
\arguments{
- \item{raster}{ A \code{RasterLayer} object }
- \item{object}{ A \code{RasterLayer} or \code{RasterStack} object }
- \item{values}{ Data values to associate with the RasterLayer object. There should be values for all cells or for a single row}
- \item{layer}{ layer number (only relevant for RasterStack objects) }
- \item{rownr}{ row number, between 1 and nrow(raster) }
- \item{blockvalues}{ Data values to associate with the RasterLayer object for a block of data, i.e. a rectangular area within the entire raster }
- \item{startrow}{ first row}
- \item{endrow}{ last row}
- \item{firstcell}{ first cell (upper left corner) of the block values }
- \item{lastcell}{ last cell (upper left corner) of the block values }
- \item{sparsevalues}{ not implemented yet -- sparse data values. I.e. values for a number of raster cells }
- \item{cellnumbers}{ the cell numbers corresponding to the sparse data }
+ \item{raster}{A \code{RasterLayer} object }
+ \item{object}{A \code{RasterLayer} or \code{RasterStack} object }
+ \item{values}{Data values to associate with the RasterLayer object. There should be values for all cells or for a single row}
+ \item{layer}{Layer number (only relevant for RasterStack objects) }
+ \item{rownr}{Row number, between 1 and nrow(raster) }
+ \item{blockvalues}{Data values to associate with the RasterLayer object for a block of data, i.e. a rectangular area within the entire raster }
+ \item{firstcell}{First cell (upper left corner) of the block values }
+ \item{lastcell}{Last cell (upper left corner) of the block values }
+ \item{sparsevalues}{Not implemented yet -- sparse data values. I.e. values for a number of raster cells }
+ \item{cellnumbers}{The cell numbers corresponding to the sparse data}
}
More information about the Raster-commits
mailing list