[Raster-commits] r151 - in pkg/raster: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jan 18 07:47:03 CET 2009
Author: rhijmans
Date: 2009-01-18 07:47:03 +0100 (Sun, 18 Jan 2009)
New Revision: 151
Added:
pkg/raster/R/exportGDAL.R
pkg/raster/man/aggregate.Rd
pkg/raster/man/change.extent.Rd
pkg/raster/man/coerce.Rd
Removed:
pkg/raster/man/raster.change.Rd
Modified:
pkg/raster/DESCRIPTION
pkg/raster/R/aggregate.R
pkg/raster/R/group.generic.functions.R
pkg/raster/R/properties.R
pkg/raster/man/export.Rd
pkg/raster/man/properties.Rd
pkg/raster/man/raster.write.Rd
Log:
Modified: pkg/raster/DESCRIPTION
===================================================================
--- pkg/raster/DESCRIPTION 2009-01-17 14:28:50 UTC (rev 150)
+++ pkg/raster/DESCRIPTION 2009-01-18 06:47:03 UTC (rev 151)
@@ -2,7 +2,7 @@
Type: Package
Title: Raster data handling for geographic data analysis and modeling
Version: 0.8.5
-Date: 15-Jan-2009
+Date: 18-Jan-2009
Depends: methods, sp, rgdal (>= 0.5-33), R (>= 2.8.0)
Author: Robert J. Hijmans & Jacob van Etten
Maintainer: Robert J. Hijmans <r.hijmans at gmail.com>
Modified: pkg/raster/R/aggregate.R
===================================================================
--- pkg/raster/R/aggregate.R 2009-01-17 14:28:50 UTC (rev 150)
+++ pkg/raster/R/aggregate.R 2009-01-18 06:47:03 UTC (rev 151)
@@ -5,7 +5,7 @@
# Version 0,7
# Licence GPL v3
-Aggregate <- function(raster, fact = 2, fun = mean, expand = TRUE, rm.NA = TRUE, ForceIntOutput = FALSE, filename="", overwrite=FALSE) {
+Aggregate <- function(raster, fact = 2, fun = mean, expand = TRUE, rm.NA = TRUE, filename="", overwrite=FALSE, ForceIntOutput = FALSE) {
if (length(fact)==1) {
fact <- round(fact)
if (fact < 2) { stop('fact should be > 1') }
Added: pkg/raster/R/exportGDAL.R
===================================================================
--- pkg/raster/R/exportGDAL.R (rev 0)
+++ pkg/raster/R/exportGDAL.R 2009-01-18 06:47:03 UTC (rev 151)
@@ -0,0 +1,23 @@
+
+exportGDAL <- function(raster, driver="HFA", filename, overwrite=FALSE, ForceIntOutput = FALSE) {
+ if (file.exists(filename) & !overwrite) {
+ stop("filename exists; use overwrite=TRUE")
+ }
+
+ # this needs to get fancier; depending on raster and the abilties of the drivers
+ dataformat <- 'Int32'
+ if (dataType(raster) == 'numeric' & !ForceIntOutput) {
+ dataformat <- 'Float32'
+ }
+ driver <- new("GDALDriver", driver)
+ export <- new("GDALTransientDataset", driver, nrow(raster), ncol(raster), 1, dataformat)
+
+ for (r in 1:nrow(raster)) {
+ x <- putRasterData(export, values(readRow(raster, r)), 1, c((r-1), 0))
+ }
+
+ saveDataset(export, filename)
+ GDAL.close(export)
+ GDAL.close(driver)
+}
+
Modified: pkg/raster/R/group.generic.functions.R
===================================================================
--- pkg/raster/R/group.generic.functions.R 2009-01-17 14:28:50 UTC (rev 150)
+++ pkg/raster/R/group.generic.functions.R 2009-01-18 06:47:03 UTC (rev 151)
@@ -5,6 +5,11 @@
# Licence GPL v3
+# for very large rasters, use
+# filename <- tempfile()
+
+
+
setMethod('==', signature(e1='BasicRaster', e2='BasicRaster'),
function(e1,e2){
cond <- compare(c(e1, e2), bb=TRUE, rowcol=TRUE, prj=TRUE, tolerance=0.0001, stopiffalse=FALSE)
@@ -13,6 +18,7 @@
)
+
setMethod('!=', signature(e1='BasicRaster', e2='BasicRaster'),
function(e1,e2){
cond <- compare(c(e1, e2), bb=TRUE, rowcol=TRUE, prj=TRUE, tolerance=0.0001, stopiffalse=FALSE)
Modified: pkg/raster/R/properties.R
===================================================================
--- pkg/raster/R/properties.R 2009-01-17 14:28:50 UTC (rev 150)
+++ pkg/raster/R/properties.R 2009-01-18 06:47:03 UTC (rev 151)
@@ -157,6 +157,15 @@
return(object at data@source)
}
+dataType <- function(object) {
+ return(object at file@datatype)
+}
+
+
+dataSize <- function(object) {
+ return(object at file@datasize)
+}
+
.driver <- function(object) {
return(object at file@driver)
}
Added: pkg/raster/man/aggregate.Rd
===================================================================
--- pkg/raster/man/aggregate.Rd (rev 0)
+++ pkg/raster/man/aggregate.Rd 2009-01-18 06:47:03 UTC (rev 151)
@@ -0,0 +1,45 @@
+\name{aggregate}
+\alias{Aggregate}
+\alias{disaggregate}
+
+\title{Change raster database}
+\description{
+ (Dis)aggregated a raster to create a new raster
+}
+\usage{
+Aggregate(raster, fact = 2, fun = mean, expand = TRUE, rm.NA = TRUE, filename="", overwrite=FALSE, ForceIntOutput = FALSE)
+disaggregate(raster, fact=2, filename="", overwrite=FALSE)
+}
+
+\arguments{
+ \item{raster}{a RasterLayer object}
+ \item{filename}{output filename for a new raster}
+ \item{fun}{function used to Aggregate values. It should return one number. E.g. mean or max}
+ \item{fact}{degree of aggregation or disaggregation expressed as number of cells (horizontally and vertically). See details}
+ \item{expand}{if \code{expand == TRUE} grids will get larger if \code{factor} if the number of the division of the columns or rows with factor does not return an integer}
+ \item{rm.NA}{if \code{rm.NA == TRUE}, remove NA cells from calculations}
+ \item{ForceIntOutput}{logical. If \code{TRUE} the values will be rounded and stored as integer}
+ \item{overwrite}{if TRUE, "filename" will be overwritten if it exists}
+}
+
+\details{
+ In aggregation \code{fact = 2} will result in a grid with 2 x 2 = 4 times fewer cells, while in disaggregation 4 times more cells will be created.
+ In disaggregation fact can be a single integer or two integers c(x,y), in which case the first one is the horizontal disaggregation factor and y the vertical disaggreation factor
+
+
+}
+
+\value{
+ a new RasterLayer object (in the R environment) which is in some cases written to disk
+}
+\author{Robert J. Hijmans \email{r.hijmans at gmail.com}}
+
+\examples{
+ r <- newRaster()
+ r <- setValues(r, runif(ncells(r)))
+ ra <- Aggregate(r, fact=10, fun=max)
+ rd <- disaggregate(ra, 3)
+}
+
+\keyword{spatial}
+
Added: pkg/raster/man/change.extent.Rd
===================================================================
--- pkg/raster/man/change.extent.Rd (rev 0)
+++ pkg/raster/man/change.extent.Rd 2009-01-18 06:47:03 UTC (rev 151)
@@ -0,0 +1,52 @@
+\name{change extent}
+\alias{crop}
+\alias{Merge}
+\alias{expand}
+
+\title{Change raster database}
+\description{
+ Use existing raster(s) to create a new raster with different spatial extent or resolution
+}
+\usage{
+crop(raster, bndbox, filename="", overwrite=FALSE)
+expand(raster, bndbox, filename="", overwrite=FALSE)
+Merge(rasters, tolerance=0.05, filename="", overwrite=FALSE)
+}
+
+\arguments{
+ \item{raster}{a RasterLayer object}
+ \item{rasters}{a list of RasterLayer objects}
+ \item{bndbox}{bounding box used to crop a raster. Any object that is or has a bounding box (see below)}
+ \item{filename}{output filename for a new raster}
+ \item{overwrite}{if TRUE, "filename" will be overwritten if it exists}
+ \item{tolerance}{difference permissable (relative to the cell resolution) for objects to be 'equal'. See ?all.equal}
+}
+
+\details{
+ Objects that have bounding boxes include RasterLayer, and other objects descending from the Spatial class in the sp package.
+ You can check this with getBbox(object)
+ They can be created with the function newBbox
+
+}
+
+\value{
+ a new RasterLayer object (in the R environment) which is in some cases written to disk
+}
+\author{Robert J. Hijmans \email{r.hijmans at gmail.com}}
+
+\examples{
+ rs <- newRaster()
+ rs <- setValues(rs, runif(ncells(rs)))
+# map(rsa)
+ bb1 <- newBbox(-180, -150, 60, 90)
+ rsc1 <- crop(rs, bb1)
+ bb2 <- newBbox(0, 50, 0, 90)
+ rsc2 <- crop(rs, bb2)
+ rsc <- Merge(c(rsc1, rsc2))
+# map(rsc)
+# rs provides the bounding box for expand
+ rse <- expand(rsc, rs)
+}
+
+\keyword{spatial}
+
Added: pkg/raster/man/coerce.Rd
===================================================================
--- pkg/raster/man/coerce.Rd (rev 0)
+++ pkg/raster/man/coerce.Rd 2009-01-18 06:47:03 UTC (rev 151)
@@ -0,0 +1,53 @@
+\name{Coercion}
+\alias{asRasterLayer,missing,missing-method}
+\alias{asRasterLayer,character,missing-method}
+\alias{asRasterLayer,Raster,missing-method}
+\alias{asRasterLayer,RasterLayer,numeric-method}
+\alias{asRasterLayer,RasterStackBrick,numeric-method}
+\alias{asRasterLayer,SpatialPixels,missing-method}
+\alias{asRasterLayer,SpatialPixels,numeric-method}
+\alias{asRasterLayer,SpatialPixelsDataFrame,numeric-method}
+\alias{asRasterLayer,SpatialGridDataFrame,numeric-method}
+
+\alias{asRasterLayer}
+\alias{asRasterBrick}
+\alias{asSpGrid}
+
+\title{ Coercion of Raster*, SpatialGrid and SpatialPixels* objects. }
+
+\description{
+ Functions to coerce a Raster* objects into an sp SpatialGridDataFrame object and
+ to coerce a RasterLayer or RasterBrick object from a sp SpatialPixels* or SpatialGrid* object
+}
+
+\usage{
+asRasterLayer(object, index)
+asRasterBrick(spgrid)
+asSpGrid(object, type='grid')
+}
+
+\arguments{
+ \item{object}{ a Raster* type object (SpatialPixel, SpatialPixelDataFrame , SpatialGrid, or SpatialGridDataFrame }
+ \item{spgrid}{ a sp raster type object (SpatialPixel, SpatialPixelDataFrame , SpatialGrid, or SpatialGridDataFrame }
+ \item{index}{integer values >= 1 indicating the layer in the RasterStack or RasterBrick, or the column in the sp object dataframe to take the values from}
+ \item{type}{character. Indicating what type of sp object to return. Should be 'pixel' or 'grid'.}
+}
+
+\details{
+ if \code{type} is 'pixel' a SpatialPixel* object is returned. If the RasterLayer object has data a SpatialPixelDataFrame will be returned.
+ if \code{type} is 'grid' a SpatialGrid* object is returned. If the RasterLayer object has data a SpatialGridDataFrame will be returned.
+}
+
+\value{
+ a Raster or a sp object
+}
+\author{ Robert J. Hijmans \email{r.hijmans at gmail.com} }
+
+\examples{
+ rs <- newRaster()
+ rs <- setValues(rs, 1:ncells(rs))
+ sp <- asSpGrid(rs)
+ rs2 <- asRasterLayer(sp)
+}
+
+\keyword{ spatial }
Modified: pkg/raster/man/export.Rd
===================================================================
--- pkg/raster/man/export.Rd 2009-01-17 14:28:50 UTC (rev 150)
+++ pkg/raster/man/export.Rd 2009-01-18 06:47:03 UTC (rev 151)
@@ -1,53 +1,82 @@
-\name{Coercion}
-\alias{asRasterLayer,missing,missing-method}
-\alias{asRasterLayer,character,missing-method}
-\alias{asRasterLayer,Raster,missing-method}
-\alias{asRasterLayer,RasterLayer,numeric-method}
-\alias{asRasterLayer,RasterStackBrick,numeric-method}
-\alias{asRasterLayer,SpatialPixels,missing-method}
-\alias{asRasterLayer,SpatialPixels,numeric-method}
-\alias{asRasterLayer,SpatialPixelsDataFrame,numeric-method}
-\alias{asRasterLayer,SpatialGridDataFrame,numeric-method}
+\name{write}
-\alias{asRasterLayer}
-\alias{asRasterBrick}
-\alias{asSpGrid}
+\alias{export}
+\alias{exportGDAL}
+\alias{writeHeader}
+\alias{writeWorldfile}
-\title{ Coercion of Raster*, SpatialGrid and SpatialPixels* objects. }
-
-\description{
- Functions to coerce a Raster* objects into an sp SpatialGridDataFrame object and
- to coerce a RasterLayer or RasterBrick object from a sp SpatialPixels* or SpatialGrid* object
+\title{ Write raster data to a file }
+\description{
+ Write raster values to a file. Either as binary ('raster') format or Ascii (ESRI Arc Ascii) format.
+ You can also export an existing raster file to an ASCII or BIL file.
+ Or create header files associated with other formats for use in different software (use ENVI or ErdasRaw for ArcGIS).
}
-
\usage{
-asRasterLayer(object, index)
-asRasterBrick(spgrid)
-asSpGrid(object, type='grid')
+export(raster, filename="", filetype='ascii', keepGRD=TRUE, overwrite=FALSE)
+exportGDAL <- function(raster, driver, filename, overwrite=FALSE)
+writeHeader(raster, type)
+writeWorldfile(raster, extension=".wld")
}
\arguments{
- \item{object}{ a Raster* type object (SpatialPixel, SpatialPixelDataFrame , SpatialGrid, or SpatialGridDataFrame }
- \item{spgrid}{ a sp raster type object (SpatialPixel, SpatialPixelDataFrame , SpatialGrid, or SpatialGridDataFrame }
- \item{index}{integer values >= 1 indicating the layer in the RasterStack or RasterBrick, or the column in the sp object dataframe to take the values from}
- \item{type}{character. Indicating what type of sp object to return. Should be 'pixel' or 'grid'.}
+ \item{raster}{ RasterLayer object }
+ \item{overwrite}{ Logical. If \code{TRUE} existing files are overwritten }
+ \item{filename}{ The file resulting from import or export }
+ \item{filetype}{ The type of file to export to ('ascii' or 'bil')}
+ \item{driver}{ GDAL driver that can create raster datasets (see below for list)}
+ \item{keepGRD}{ Logical. If \code{FALSE} the existing raster file (internal format) will not be kept after exporting; only applied to other formats that can use the same binary format. }
+ \item{type}{ Type of header file: 'BIL', 'ENVI', 'ErdasRaw', 'raster' }
+ \item{extension}{ extension of header file. Only implemented for worldfile. }
}
\details{
- if \code{type} is 'pixel' a SpatialPixel* object is returned. If the RasterLayer object has data a SpatialPixelDataFrame will be returned.
- if \code{type} is 'grid' a SpatialGrid* object is returned. If the RasterLayer object has data a SpatialGridDataFrame will be returned.
-}
+ data in a \code{RasterLayer} object is written to a file. Small datasets can be loaded into memory manipulated,
+ and saved to disk again. For large datasets, you can read and write by row.
+ writeHeader writes an ENVI, or BIL header (.hdr) file; or an Erdas Raw (.raw) header file. This (hopefully) allows for reading the binary data ("raster.gri") in other programs such as ENVI ArcMap.
+ if format = "worldfile", the function writes an ESRI "world" file, that is sometimes used to georeference images.
+
+Supporte GDAL drivers are:
-\value{
- a Raster or a sp object
+ Driver Long name
+ ADRG ARC Digitized Raster Graphics
+ BMP MS Windows Device Independent Bitmap
+ BT VTP .bt (Binary Terrain) 1.3 Format
+ EHdr ESRI .hdr Labelled
+ ELAS ELAS
+ ENVI ENVI .hdr Labelled
+ ERS ERMapper .ers Labelled
+ GSBG Golden Software Binary Grid (.grd)
+ GTiff GeoTiff
+ HFA Erdas Imagine Images (.img)
+ IDA Image Data and Analysis
+ ILWIS ILWIS Raster Map
+ INGR Intergraph Raster
+ Leveller Leveller heightfield
+ MEM In Memory Raster
+ MFF Vexcel MFF Raster
+ MFF2 Vexcel MFF2 (HKV) Raster
+ NITF National Imagery Transmission Format
+ PAux PCI .aux Labelled
+ PCIDSK PCIDSK Database File
+ PNM Portable Pixmap Format (netpbm)
+ RMF Raster Matrix Format
+ RST Idrisi Raster A.1
+ SGI SGI Image File Format 1.0
+ Terragen Terragen heightfield
+ VRT Virtual Raster
+
}
-\author{ Robert J. Hijmans \email{r.hijmans at gmail.com} }
+\author{Robert J. Hijmans \email{r.hijmans at gmail.com}}
+
+\seealso{ \code{\link[rgdal]{rgdal}} }
\examples{
- rs <- newRaster()
- rs <- setValues(rs, 1:ncells(rs))
- sp <- asSpGrid(rs)
- rs2 <- asRasterLayer(sp)
+
+rs <- rasterFromFile(system.file("external/test.ag", package="sp"))
+rsimport <- import(rs, filename="imported", overwrite=TRUE)
+rsexport <- export(rsimport, filename="exported", filetype='ascii', overwrite=TRUE)
+writeHeader(rsexport, type="ENVI")
+
}
\keyword{ spatial }
Modified: pkg/raster/man/properties.Rd
===================================================================
--- pkg/raster/man/properties.Rd 2009-01-17 14:28:50 UTC (rev 150)
+++ pkg/raster/man/properties.Rd 2009-01-18 06:47:03 UTC (rev 151)
@@ -24,7 +24,9 @@
\alias{layers}
\alias{band}
\alias{nbands}
-
+\alias{dataType}
+\alias{dataSize}
+
\title{RasterLayer properties}
\description{
@@ -48,6 +50,8 @@
projection(object, asText=TRUE)
isLatLon(object)
origin(object)
+dataSize(object)
+dataType(object)
nlayers(object)
layers(object)
band(object)
Deleted: pkg/raster/man/raster.change.Rd
===================================================================
--- pkg/raster/man/raster.change.Rd 2009-01-17 14:28:50 UTC (rev 150)
+++ pkg/raster/man/raster.change.Rd 2009-01-18 06:47:03 UTC (rev 151)
@@ -1,67 +0,0 @@
-\name{change}
-\alias{Aggregate}
-\alias{disaggregate}
-\alias{crop}
-\alias{Merge}
-\alias{expand}
-
-\title{Change raster database}
-\description{
- Use existing raster(s) to create a new raster with different spatial extent or resolution
-}
-\usage{
-Aggregate(raster, fact = 2, fun = mean, expand = TRUE, rm.NA = TRUE, ForceIntOutput = FALSE, filename="", overwrite=FALSE)
-disaggregate(raster, fact=2, filename="", overwrite=FALSE)
-crop(raster, bndbox, filename="", overwrite=FALSE)
-expand(raster, bndbox, filename="", overwrite=FALSE)
-Merge(rasters, tolerance=0.05, filename="", overwrite=FALSE)
-}
-
-\arguments{
- \item{raster}{a RasterLayer object}
- \item{rasters}{a list of RasterLayer objects}
- \item{bndbox}{bounding box used to crop a raster. Any object that is or has a bounding box (see below)}
- \item{filename}{output filename for a new raster}
- \item{fun}{function used to Aggregate values. It should return one number. E.g. mean or max}
- \item{fact}{degree of aggregation or disaggregation expressed as number of cells (horizontally and vertically). See details}
- \item{expand}{if \code{expand == TRUE} grids will get larger if \code{factor} if the number of the division of the columns or rows with factor does not return an integer}
- \item{rm.NA}{if \code{rm.NA == TRUE}, remove NA cells from calculations}
- \item{ForceIntOutput}{logical. If \code{TRUE} the values will be rounded and stored as integer}
- \item{overwrite}{if TRUE, "filename" will be overwritten if it exists}
- \item{tolerance}{difference permissable (relative to the cell resolution) for objects to be 'equal'. See ?all.equal}
-}
-
-\details{
- Objects that have bounding boxes include RasterLayer, and other objects descending from the Spatial class in the sp package.
- You can check this with getBbox(object)
- They can be created with the function newBbox
- In aggregation \code{fact = 2} will result in a grid with 2 x 2 = 4 times fewer cells, while in disaggregation 4 times more cells will be created.
- In disaggregation fact can be a single integer or two integers c(x,y), in which case the first one is the horizontal disaggregation factor and y the vertical disaggreation factor
-
-
-}
-
-\value{
- a new RasterLayer object (in the R environment) which is in some cases written to disk
-}
-\author{Robert J. Hijmans \email{r.hijmans at gmail.com}}
-
-\examples{
- rs <- newRaster()
- rs <- setValues(rs, runif(ncells(rs)))
-# map(rs)
- rsa <- Aggregate(rs, fact=10, fun=max)
-# map(rsa)
- bb1 <- newBbox(-180, -150, 60, 90)
- rsc1 <- crop(rsa, bb1)
- bb2 <- newBbox(0, 50, 0, 90)
- rsc2 <- crop(rsa, bb2)
- rsc <- Merge(c(rsc1, rsc2))
-# map(rsc)
-# rs provides the bounding box for expand
- rse <- expand(rsc, rs)
- rsd <- disaggregate(rse, 3)
-}
-
-\keyword{spatial}
-
Modified: pkg/raster/man/raster.write.Rd
===================================================================
--- pkg/raster/man/raster.write.Rd 2009-01-17 14:28:50 UTC (rev 150)
+++ pkg/raster/man/raster.write.Rd 2009-01-18 06:47:03 UTC (rev 151)
@@ -3,9 +3,6 @@
\alias{writeRaster}
\alias{writeAscii}
\alias{import}
-\alias{export}
-\alias{writeHeader}
-\alias{writeWorldfile}
\title{ Write raster data to a file }
\description{
@@ -17,26 +14,17 @@
writeRaster(raster, overwrite=FALSE)
writeAscii(raster, filename, overwrite=FALSE)
import(raster, filename="", overwrite=FALSE)
-export(raster, filename="", filetype='ascii', keepGRD=TRUE, overwrite=FALSE)
-writeHeader(raster, type)
-writeWorldfile(raster, extension=".wld")
}
\arguments{
\item{raster}{ RasterLayer object }
\item{overwrite}{ Logical. If \code{TRUE} existing files are overwritten }
\item{filename}{ The file resulting from import or export }
- \item{filetype}{ The type of file to export to ('ascii' or 'bil')}
- \item{keepGRD}{ Logical. If \code{FALSE} the existing raster file (internal format) will not be kept after exporting; only applied to other formats that can use the same binary format. }
- \item{type}{ Type of header file: 'BIL', 'ENVI', 'ErdasRaw', 'raster' }
- \item{extension}{ extension of header file. Only implemented for worldfile. }
}
\details{
data in a \code{RasterLayer} object is written to a file. Small datasets can be loaded into memory manipulated,
and saved to disk again. For large datasets, you can read and write by row.
- writeHeader writes an ENVI, or BIL header (.hdr) file; or an Erdas Raw (.raw) header file. This (hopefully) allows for reading the binary data ("raster.gri") in other programs such as ENVI ArcMap.
- if format = "worldfile", the function writes an ESRI "world" file, that is sometimes used to georeference images.
}
\author{Robert J. Hijmans \email{r.hijmans at gmail.com}}
@@ -77,8 +65,6 @@
}
rsimport <- import(rs, filename="imported", overwrite=TRUE)
-rsexport <- export(rsimport, filename="exported", filetype='ascii', overwrite=TRUE)
-writeHeader(rsexport, type="ENVI")
}
More information about the Raster-commits
mailing list