[Raster-commits] r155 - in pkg/raster: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jan 19 02:20:29 CET 2009
Author: rhijmans
Date: 2009-01-19 02:20:29 +0100 (Mon, 19 Jan 2009)
New Revision: 155
Modified:
pkg/raster/R/exportGDAL.R
pkg/raster/R/raster.create.R
pkg/raster/man/create.raster.Rd
Log:
Modified: pkg/raster/R/exportGDAL.R
===================================================================
--- pkg/raster/R/exportGDAL.R 2009-01-18 14:22:03 UTC (rev 154)
+++ pkg/raster/R/exportGDAL.R 2009-01-19 01:20:29 UTC (rev 155)
@@ -37,8 +37,8 @@
#.GDALDataTypes <- c('Unknown', 'Byte', 'UInt16', 'Int16', 'UInt32','Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64')
# this needs to get fancier; depending on object and the abilties of the drivers
- dataformat <- 'Int32'
- if (dataType(raster) == 'integer' | !ForceIntOutput) {
+ if (dataType(raster) == 'integer' | ForceIntOutput) {
+ dataformat <- 'Int32'
if (raster at data@haveminmax) {
if (minValue(raster) > -32768 & maxValue(raster) <= 32767) {
dataformat <- 'Int16'
@@ -61,7 +61,11 @@
if (dataContent(raster)=='all') {
# if (!is.na(mvFlag)) vals[is.na(vals)] = mvFlag
- x <- putRasterData(transient, t(values(raster, format='matrix')), band, c(0, 0))
+# This would work, but could potentially lead to memory problems (making a copy of the values before writing)
+# x <- putRasterData(transient, t(values(raster, format='matrix')), band, c(0, 0))
+ for (r in 1:nrow(raster)) {
+ x <- putRasterData(transient, valuesRow(raster, r), band, c((r-1), 0))
+ }
} else {
if (dataSource(raster)=='ram') {
stop("No data on disk, and not all values in memory. Cannot write the file")
@@ -85,7 +89,7 @@
outras <- rasterFromFile(filename)
outras at data@min <- raster at data@min
outras at data@max <- raster at data@max
- if (!is.na((outras at data@min))) { outras at data@haveminmax <- TRUE }
+ if (!is.na((outras at data@min))) { outras at data@haveminmax <- TRUE }
return(outras)
}
Modified: pkg/raster/R/raster.create.R
===================================================================
--- pkg/raster/R/raster.create.R 2009-01-18 14:22:03 UTC (rev 154)
+++ pkg/raster/R/raster.create.R 2009-01-19 01:20:29 UTC (rev 155)
@@ -4,10 +4,19 @@
# Version 0,1
# Licence GPL v3
-closeRaster <- function(raster) {
+
+closeHandle <- function(raster) {
# if handle = gdal then gdalclose the handle
+ if (.driver(raster) == "gdal") {
+ closeDataset(raster at file@gdalhandle[[1]])
+ raster at file@gdalhandle[[1]] <- list()
+ } else {
+ cr <- try(close(raster at filecon), silent = T)
+ }
+ return(raster)
}
+
newRaster <- function(xmn=-180, xmx=180, ymn=-90, ymx=90, nrows=180, ncols=360, projstring="+proj=longlat +datum=WGS84") {
bb <- newBbox(xmn, xmx, ymn, ymx)
return(rasterFromBbox(bb, nrows=nrows, ncols=ncols, projstring))
Modified: pkg/raster/man/create.raster.Rd
===================================================================
--- pkg/raster/man/create.raster.Rd 2009-01-18 14:22:03 UTC (rev 154)
+++ pkg/raster/man/create.raster.Rd 2009-01-19 01:20:29 UTC (rev 155)
@@ -2,6 +2,7 @@
\alias{newRaster}
\alias{rasterFromBbox}
\alias{rasterFromFile}
+\alias{closeHandle}
\title{ Create a new RasterLayer object }
\description{
@@ -13,6 +14,7 @@
newRaster(xmn = -180, xmx = 180, ymn = -90, ymx = 90, nrows = 180, ncols = 360, projstring = "+proj=longlat +datum=WGS84")
rasterFromBbox(bndbox, nrows = 1, ncols = 1, projstring="")
rasterFromFile(filename, values=FALSE, band=1)
+ closeHandle(raster)
}
\arguments{
@@ -27,10 +29,12 @@
\item{projstring}{ PROJ4 type description of a map projection}
\item{bndbox}{bounding box used to crop a raster. Any object that is or has a bounding box (see below) }
\item{values}{logical. If \code{TRUE}, RasterLayer values will be read into memory with 'readAll()'}
+ \item{raster}{a RasterLayer object}
}
\details{
rasterFromFile uses "GDALinfo" from the rgdal package
see the rgdal help for supported file types
+ closeHandle removes the handle to the file on disk that was established by rasterFromFile(). After the handle is closed, you can no longer read data from the file through the RasterLayer object. You probably do not need to do this; unless you get problems with files that cannot be overwritten (rm() does not immediately remove the handle; it seems).
}
\value{
@@ -40,9 +44,10 @@
\seealso{ \code{\link[gdal]{rgdal}} }
\examples{
- raster1 <- newRaster(nrows=1080, ncols=2160)
- raster1
- raster2 <- rasterFromFile(system.file("external/test.ag", package="sp"))
- raster2
+ r1 <- newRaster(nrows=1080, ncols=2160)
+ r1
+ r2 <- rasterFromFile(system.file("external/test.ag", package="sp"))
+ r2
+ logo <- rasterFromFile(system.file("pictures/Rlogo.jpg", package="rgdal"))
}
\keyword{ spatial }
More information about the Raster-commits
mailing list