[R] importing ascii grids (for gstat)
Andy Bunn
abunn at montana.edu
Tue Feb 17 17:55:32 CET 2004
If you have exported the grid from Arc using the asciigrid command then
you can read it in with scan or read.table. You can tell R to skip the
six lines of header info and to convert -9999 to NA e.g.,
$ snep.tmin <- read.table(file = "tmin.asc", sep = " ", na.strings =
"-9999", skip = 6)
Check the number of rows and columns to make sure it matches your data
(in Windows, Arc puts a space before the line rturn at the end of a row
making the resulting R object have one too manty columns.)
If so then remove it:
$ snep.tmin <- snep.tmin[,-ncol(snep.tmin)]
(If there is a work around for the read.table command that somebody else
uses then I'd love to hear it.)
For gstat, it is helpful to put the grid into a vector and attach the
coordinate information in a data.frame
>From the header information take the lower left corner and make your
coordinate columns and join it to the grid data.
e.g.,
$ xLLcorner <- -1855500
$ yLLcorner <- -944500
$ cellsize <- 1000
$
$ xURcorner <- xLLcorner + (cellsize * (ncol(snep.tmin) - 1))
$ xLRcorner <- xURcorner
$ xULcorner <- xLLcorner
$
$ yULcorner <- yLLcorner + (cellsize * (nrow(snep.tmin) - 1))
$ yURcorner <- yULcorner
$ yLRcorner <- yLLcorner
$
$ coords <- expand.grid(y = seq(yULcorner, yLRcorner, by = -1000),
+ x = seq(xULcorner, xLRcorner, by = 1000))
$
$ tmin.frame <- data.frame(coords, tmin = as.vector(c(snep.tmin,
recursive = T)))
$
$
>From there you can krige or whatever easily.
HTH, Andy
$ version
_
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 1
minor 8.1
year 2003
month 11
day 21
language R
More information about the R-help
mailing list