readRAST6 {spgrass6}R Documentation

Read and write GRASS 6 raster files

Description

Read GRASS 6 raster files from GRASS 6 into R SpatialGridDataFrame objects, and write single columns of R SpatialGridDataFrame objects to GRASS 6. readRAST6 and writeRAST6 use temporary binary files and r.out.bin and r.in.bin rather than the temporary ASCII files used in earlier implementations. The earlier versions may still be used in a transition period.

Usage

readRAST6(vname, cat=NULL, ignore.stderr = FALSE, NODATA=NULL, plugin=NULL, mapset=NULL, useGDAL=TRUE)
writeRAST6(x, vname, zcol = 1, NODATA=NULL, ignore.stderr = FALSE, useGDAL=TRUE, overwrite=FALSE, flags=NULL)

Arguments

vname A vector of GRASS 6.0 raster file names
cat default NULL; if not NULL, must be a logical vector matching vname, stating which (CELL) rasters to return as factor
ignore.stderr default FALSE, can be set to TRUE to silence system() output to standard error; does not apply on Windows platforms
plugin default NULL does auto-detection, changes to FALSE if vname is longer than 1, and a sanity check will be run on raster and current region, and the function will revert to FALSE if mismatch is found; if TRUE, the plugin is available and the raster should be read in its original region and resolution; if the plugin is used, no further arguments other than mapset are respected
mapset default NULL, if plugin is TRUE, the mapset of the file to be imported will be autodetected; if not NULL and if plugin is TRUE, a character string overriding the autodetected mapset, otherwise ignored
useGDAL default TRUE use r.out.gdal or plugin and readGDAL if autodetected or plugin=TRUE; or for writing writeGDAL, GTiff, and r.in.gdal, if FALSE using r.out.bin or r.in.bin
x A SpatialGridDataFrame object for export to GRASS as a raster layer
zcol Attribute column number or name
NODATA by default NULL, in which case it is set to one less than floor()of the data values, otherwise an integer NODATA value (required to be integer by GRASS r.out.bin)
overwrite default FALSE, if TRUE inserts "overwrite" into the value of the flags argument if not already there to allow existing GRASS rasters to be overwritten
flags default NULL, character vector, for example "overwrite"

Value

readRAST6 returns a SpatialGridDataFrame objects with an data.frame in the data slots, and with the projection argument set. Note that the projection argument set is the the GRASS rendering of proj4, and will differ from the WKT/ESRI rendering returned by readVECT6 in form but not meaning. They are exchangeable but not textually identical, usually with the +ellps= term replaced by ellipsoid parameters verbatim.

Author(s)

Roger S. Bivand, e-mail: Roger.Bivand@nhh.no

Examples

if (nchar(Sys.getenv("GISRC")) > 0) {
  spear <- readRAST6(c("geology", "elevation.dem"), cat=c(TRUE, FALSE),
    ignore.stderr=TRUE, plugin=NULL)
  spear <- readRAST6(c("geology", "elevation.dem"), cat=c(TRUE, FALSE),
    ignore.stderr=TRUE, useGDAL=FALSE, plugin=FALSE)
  spear <- readRAST6(c("geology", "elevation.dem"), cat=c(TRUE, FALSE),
    ignore.stderr=TRUE, useGDAL=TRUE, plugin=FALSE)
  print(table(spear$geology))
  execGRASS("r.stats", flags=c("c", "l", "quiet"), 
    parameters=list(input="geology"), ignore.stderr=TRUE)
  boxplot(spear$elevation.dem ~ spear$geology)
  spear$sqdem <- sqrt(spear$elevation.dem)
  if ("GRASS" %in% gdalDrivers()$name) {
    dem1 <- readRAST6("elevation.dem", plugin=TRUE, ignore.stderr=TRUE,
      mapset="PERMANENT")
    print(summary(dem1))
  }
  writeRAST6(spear, "sqdemSP", zcol="sqdem", ignore.stderr=TRUE)
  execGRASS("r.info", parameters=list(map="sqdemSP"), ignore.stderr=TRUE)
  execGRASS("g.remove", parameters=list(rast="sqdemSP"), ignore.stderr=TRUE)
  writeRAST6(spear, "sqdemSP", zcol="sqdem", ignore.stderr=TRUE, useGDAL=TRUE)
  execGRASS("r.info", parameters=list(map="sqdemSP"), ignore.stderr=TRUE)
  execGRASS("g.remove", parameters=list(rast="sqdemSP"), ignore.stderr=TRUE)
  execGRASS("r.mapcalculator", parameters=list(outfile="quads0",
    amap="quads", formula=shQuote('A - 1')), ignore.stderr=TRUE)
  execGRASS("r.stats", flags="c", parameters=list(input="quads0"),
    ignore.stderr=TRUE)
  quads0 <- readRAST6("quads0", ignore.stderr=TRUE)
  print(table(quads0$quads0))
  quads0 <- readRAST6("quads0", ignore.stderr=TRUE, plugin=FALSE)
  print(table(quads0$quads0))
  execGRASS("g.remove", parameters=list(rast="quads0"), ignore.stderr=TRUE)
}

[Package spgrass6 version 0.6-6 Index]