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=FALSE)
writeRAST6(x, vname, zcol = 1, NODATA=NULL, ignore.stderr = FALSE, useGDAL=FALSE, overwrite=FALSE)

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 for auto-detection, changes to FALSE if vname is longer than 1; set to TRUE if 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; if NULL, a sanity check will be run on raster and current region, and the function will revert to FALSE if mismatch is found
mapset if plugin is TRUE, the mapset of the file to be imported may be changed from the current mapset by passing a character string
useGDAL default FALSE using r.out.bin or r.in.bin, if TRUE use r.out.gdal or r.in.gdal, GTiff, and readGDAL or writeGDAL
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 to allow existing GRASS rasters to be overwritten

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, useGDAL=FALSE)
  spear <- readRAST6(c("geology", "elevation.dem"), cat=c(TRUE, FALSE),
    ignore.stderr=TRUE, useGDAL=TRUE)
  print(table(spear$geology))
  if ((Sys.getenv("OSTYPE") == "msys" || nchar(Sys.getenv("WINGISRC")) > 0) || Sys.getenv("OSTYPE") == "cygwin")
    Gver <- system("g.version.exe", intern=TRUE)
  else Gver <- system("g.version", intern=TRUE)
  if (Gver > "GRASS 6.2") {
    if ((Sys.getenv("OSTYPE") == "msys" || nchar(Sys.getenv("WINGISRC")) > 0) || Sys.getenv("OSTYPE") == "cygwin")
      system("r.stats.exe --q -cl geology")
    else system("r.stats --q -cl geology")
  } else {
    if ((Sys.getenv("OSTYPE") == "msys" || nchar(Sys.getenv("WINGISRC")) > 0) || Sys.getenv("OSTYPE") == "cygwin")
      system("r.stats.exe -q -cl geology")
    else system("r.stats -q -cl geology")
  }
  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)
  if ((Sys.getenv("OSTYPE") == "msys" || nchar(Sys.getenv("WINGISRC")) > 0) || Sys.getenv("OSTYPE") == "cygwin")
    system("r.info.exe sqdemSP", ignore.stderr=TRUE)
  else system("r.info sqdemSP", ignore.stderr=TRUE)
  if ((Sys.getenv("OSTYPE") == "msys" || nchar(Sys.getenv("WINGISRC")) > 0) || Sys.getenv("OSTYPE") == "cygwin")
    system("g.remove.exe rast=sqdemSP")
  else system("g.remove rast=sqdemSP")
  writeRAST6(spear, "sqdemSP", zcol="sqdem", ignore.stderr=TRUE, useGDAL=TRUE)
  if ((Sys.getenv("OSTYPE") == "msys" || nchar(Sys.getenv("WINGISRC")) > 0) || Sys.getenv("OSTYPE") == "cygwin")
    system("r.info.exe sqdemSP", ignore.stderr=TRUE)
  else system("r.info sqdemSP", ignore.stderr=TRUE)
  if ((Sys.getenv("OSTYPE") == "msys" || nchar(Sys.getenv("WINGISRC")) > 0) || Sys.getenv("OSTYPE") == "cygwin")
    system("g.remove.exe rast=sqdemSP")
  else system("g.remove rast=sqdemSP")
  if ((Sys.getenv("OSTYPE") == "msys" || nchar(Sys.getenv("WINGISRC")) > 0) || Sys.getenv("OSTYPE") == "cygwin")
    system("r.mapcalc.exe quads0 = quads - 1", ignore.stderr=TRUE)
  else system("r.mapcalc \'quads0 = quads - 1\'", ignore.stderr=TRUE)
  if ((Sys.getenv("OSTYPE") == "msys" || nchar(Sys.getenv("WINGISRC")) > 0) || Sys.getenv("OSTYPE") == "cygwin")
    system("r.stats.exe -c quads0", ignore.stderr=TRUE)
  else system("r.stats -c quads0", ignore.stderr=TRUE)
  quads0 <- readRAST6("quads0", ignore.stderr=TRUE)
  print(table(quads0$quads0))
  quads0 <- readRAST6("quads0", ignore.stderr=TRUE)
  print(table(quads0$quads0))
  if ((Sys.getenv("OSTYPE") == "msys" || nchar(Sys.getenv("WINGISRC")) > 0) || Sys.getenv("OSTYPE") == "cygwin")
    system("g.remove.exe rast=quads0")
  else system("g.remove rast=quads0")
}

[Package spgrass6 version 0.5-16 Index]