[R-sig-Geo] The step before interfacing to GRASS
Roger Bivand
Roger.Bivand at nhh.no
Fri Jul 3 18:55:10 CEST 2009
On Fri, 3 Jul 2009, Javi Hidalgo wrote:
>
> Dear R-experts,
>
> A very basic terrain calculated as a matrix from Spatial Points Patterns:
>
> #interpolate using the akima package
> library(akima)
> terrain=interp(ppoints$x,ppoints$y,ppoints$marks,xo=x0,yo=y0, linear=F)
>
>> class(terrain)
> [1] "list"
>> class(terrain$x) #these are the x-coord i.e: [1...1000]
> [1] "numeric"
>> class(terrain$y)#these are the y-coord i.e: [1...1000]
> [1] "numeric"
>> class(terrain$z)#these are the height of the points
> [1] "matrix"
>
> I would like to export this "terrain" (list object) to GRASS.
> Reading the documentation that I found for interfacing between GRASS 6 and R (library (spgrass6)). I understood the following (I already managed to configured properly the mapset and so on):
>
> 1. I have to create a SpatialGridDataFrame object before to write into a Raster file.
> 2. In order to create a SpatialGridDataFrame I need a GridTopology.
> 3. After doing it, I am allow to write the file into GRASS using the function writeRAST6, like: writeRAST6 (spterrain, "maps.dem").
>
> How to create the SpatialGridDataFrame and/or the GridTopology? I am
> doing something wrong.
Use image2Grid() in sp in the output of interp(). You may need to take
care in your choice of x0 and x1 to match the GRASS region.
For example:
library(sp)
data(meuse)
coordinates(meuse) <- c("x", "y")
library(akima)
terrain <- interp(coordinates(meuse)[,1], coordinates(meuse)[,2],
meuse$elev, linear=FALSE)
terrain_SGDF <- image2Grid(terrain)
summary(terrain_SGDF)
image(terrain_SGDF, col=terrain.colors(10))
points(meuse)
Hope this helps,
Roger
>
> Thanks a lot,
>
> Javier Hidalgo.
> _________________________________________________________________
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list