[STATSGRASS] importing raster from R into GRASS6

Roger Bivand Roger.Bivand at nhh.no
Fri Aug 26 05:16:22 EDT 2005


On Fri, 26 Aug 2005, Rohan Sadler wrote:

> Hello All,
> 
> This may seem like a dumb question, and I've been trying to keep an eye on 
> the developments on statsgrass, but:
> 
> Are the functions available in the spgrass6 package to export R matrices to 
> Grass6 raster files?

Yes and no. Yes, you can move data from R to GRASS 6 - the function is 
writeRast6sp() in spgrass6, but the argument it takes for the data must be 
in a 2D SpatialGridDataFrame class object defined in the sp package. So an 
arbitrary matrix will need to be converted to this form first. The 
function at present writes an Arc ASCII grid to a temporary file, read 
into GRASS with r.in.gdal. So you'll need a GridTopology object to suit 
your matrix, and will need to flatten the matrix with the rows in the 
right order, for matrix A:

> A <- matrix(1:6, 2,3)
> A
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

> GT <- GridTopology(c(1,1), c(1,1), c(3,2))
> coordinates(GT)
     s1 s2
[1,]  1  2
[2,]  2  2
[3,]  3  2
[4,]  1  1
[5,]  2  1
[6,]  3  1
> cbind(coordinates(GT), c(t(A)[, nrow(A):1]))
     s1 s2  
[1,]  1  2 2
[2,]  2  2 4
[3,]  3  2 6
[4,]  1  1 1
[5,]  2  1 3
[6,]  3  1 5

looks about right. The steps would be to define the grid with
GridTopology(), make it a SpatialGridDataFrame with
SpatialGridiDataFrame(), adding in the data vector *in the right order* as
the data= argument as for example with
data=AttributeList(myvar=c(t(A)[,nrow(A):1])). From there, the function in
spgrass6 should just work.

I'd like to have support for projections too, this will happen sometime.

> 
> I just want to say that I really appreciate all the work that has thus far 
> gone into the R-GRASS6 interface. I think amazing things are going to happen 
> with it.

It would be nice to move to binary. Category labels should also be 
transferable both ways like they were for GRASS5.

Best wishes,

Roger

> 
> Regards
> Rohan Sadler
> 
> PhD Candidate
> Ecosystems Research Group M090
> The University of Western Australia
> 35 Stirling Hwy, Crawley, 6008
> ph:       +61 8 6488 7914
> fax:      +61 8 6488 7925
> mobile: +61 0433 192 600
> email:    rsadler at cyllene.uwa.edu.au
> 
> Affiliations:
> Bushfire CRC
> School of Mathematics and Statistics, UWA 
> 
> 
> _______________________________________________
> statsgrass mailing list
> statsgrass at grass.itc.it
> http://grass.itc.it/mailman/listinfo/statsgrass
> 

-- 
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 grass-stats mailing list