[R] importing ascii grids (for gstat)

Andy Bunn abunn at montana.edu
Thu Feb 19 23:22:07 CET 2004


No problem. I'm glad it worked. It would be pretty easy to package as a
function for gstat.
-Andy

> -----Original Message-----
> From: femke [mailto:femke at geog.umd.edu] 
> Sent: Thursday, February 19, 2004 2:54 PM
> To: Andy Bunn
> Subject: Re: [R] importing ascii grids (for gstat)
> 
> 
> 
> Thanks very much for your help on this.  Your directions 
> worked beautifully. Now if only somone would put that in a 
> standard function for a package like gstat.
> 
> If you don't mind, I'll post it to the gstat list 
> (referencing you as the source).
> 
> Cheeers,
> 
> femke
> 
> ----- Original Message ----- 
> From: "Andy Bunn" <abunn at montana.edu>
> To: "'femke'" <femke at geog.umd.edu>; <r-help at stat.math.ethz.ch>
> Sent: Tuesday, February 17, 2004 12:00 PM
> Subject: RE: [R] importing ascii grids (for gstat)
> 
> 
> > 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 return at the 
> end of a 
> > row making the resulting R object have one too many columns.)
> >
> > If that happens, 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 looks like it would be helpful to put the grid into a 
> > vector and attach the coordinate information in a data 
> frame? If so, 
> > 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))) $ $
> >
> > Watch your signs depends on the coordinate system. 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