Description Usage Arguments Value Author(s) Examples
Read GRASS 6+ raster files from GRASS 6+ into R SpatialGridDataFrame
objects, and write single columns of R SpatialGridDataFrame objects to
GRASS 6+. readRAST
and writeRAST
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.
The functions readRAST
and readRAST6
as well as writeRAST
and writeRAST6
are identical and the functions ending with
...6
are maintained only for backward compatibility and might be deprecated.
1 2 3 4 5 | readRAST(vname, cat=NULL, ignore.stderr = NULL, NODATA=NULL, plugin=NULL,
mapset=NULL, useGDAL=NULL, close_OK=TRUE, drivername="GTiff",
driverFileExt=NULL, return_SGDF=TRUE)
writeRAST(x, vname, zcol = 1, NODATA=NULL, ignore.stderr = NULL,
useGDAL=NULL, overwrite=FALSE, flags=NULL, drivername="GTiff")
|
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 NULL, taking the value set by |
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 NULL, taking the value set by |
close_OK |
default TRUE - clean up possible open connections used for reading metadata; may be set to FALSE to avoid the side-effect of other user-opened connections being broken |
drivername |
default |
driverFileExt |
default NULL; otherwise string value of required driver file name extension |
return_SGDF |
default TRUE returning a |
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 |
overwrite |
default FALSE, if TRUE inserts |
flags |
default NULL, character vector, for example |
readRAST
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 readVECT
in form but not meaning. They are exchangeable but not textually identical, usually with the +ellps= term replaced by ellipsoid parameters verbatim. If return_SGDF is FALSE, a list with a GridTopology
object, a list of bands, and a proj4string is returned, with an S3 class attribute of “gridList”.
Roger S. Bivand, e-mail: Roger.Bivand@nhh.no
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | if (nchar(Sys.getenv("GISRC")) > 0) {
require(rgdal)
ois <- get.ignore.stderrOption()
set.ignore.stderrOption(TRUE)
get.useGDALOption()
spear <- readRAST(c("geology", "elevation.dem"), cat=c(TRUE, FALSE),
useGDAL=FALSE)
spear <- readRAST(c("geology", "elevation.dem"), cat=c(TRUE, FALSE),
useGDAL=TRUE)
print(table(spear$geology))
execGRASS("r.stats", flags=c("c", "l", "quiet"), input="geology")
boxplot(spear$elevation.dem ~ spear$geology)
spear$sqdem <- sqrt(spear$elevation.dem)
if ("GRASS" %in% gdalDrivers()$name) {
execGRASS("g.region", rast="elevation.dem")
dem1 <- readRAST("elevation.dem", plugin=TRUE, mapset="PERMANENT")
print(summary(dem1))
execGRASS("g.region", rast="elevation.dem")
}
writeRAST(spear, "sqdemSP", zcol="sqdem")
execGRASS("r.info", map="sqdemSP")
execGRASS("g.remove", rast="sqdemSP")
writeRAST(spear, "sqdemSP", zcol="sqdem", useGDAL=TRUE)
execGRASS("r.info", map="sqdemSP")
print(system.time(sqdemSP <- readRAST(c("sqdemSP", "elevation.dem"),
useGDAL=TRUE, return_SGDF=FALSE)))
print(system.time(sqdemSP <- readRAST(c("sqdemSP", "elevation.dem"),
useGDAL=TRUE, return_SGDF=TRUE)))
print(system.time(sqdemSP <- readRAST(c("sqdemSP", "elevation.dem"),
useGDAL=FALSE, return_SGDF=TRUE)))
print(system.time(sqdemSP <- readRAST(c("sqdemSP", "elevation.dem"),
useGDAL=FALSE, return_SGDF=FALSE)))
str(sqdemSP)
mat <- do.call("cbind", sqdemSP$dataList)
str(mat)
print(system.time(SGDF <- SpatialGridDataFrame(grid=sqdemSP$grid,
proj4string=sqdemSP$proj4string, data=as.data.frame(sqdemSP$dataList))))
summary(SGDF)
execGRASS("g.remove", rast="sqdemSP")
if (execGRASS("g.version", intern=TRUE) > "GRASS 7") {
execGRASS("r.mapcalc", expression="quads0 = quads - 1")
} else {
execGRASS("r.mapcalculator", outfile="quads0",
amap="quads", formula='A - 1')
}
execGRASS("r.stats", flags="c", input="quads0")
quads0 <- readRAST("quads0")
print(table(quads0$quads0))
quads0 <- readRAST("quads0", plugin=FALSE)
print(table(quads0$quads0))
execGRASS("g.remove", rast="quads0")
set.ignore.stderrOption(ois)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.