rspatialgrass

Export multiple rasters from GRASS


I am using GRASS and R to analyse some hyperspectral data. I would like to export my spectral layers to one .img file that is compatible with ENVI. So far, I have used g.mlist to select the appropriate layers, and now I am using i.group to create the group from these layers that I could export with r.out.gdal.

I see that i.group takes an input parameter that is the list of raster layer names - I have about 100 of these, so I am looking for a way to avoid typing them individually!

My question essentially is, I've exported the names from g.mlist to a text file - is there a way to use this file in the input parameter?

This is probably a very basic problem, and is due to my programming inexperience.

I would like to use something like:

system("i.group group=MSP1 input=/home/Documents/MSP/list.txt")

Except that /home/Documents/MSP/list.txt is not a raster map.

Or, if anyone knows of a better way to export multiple image layers into one file, that would also be great.


Solution

  • Instead of attempting to call GRASS from within my Rscript as in my posted question, I have called i.group from a separate script, and it seems to work. So my call is now:

    Rscript MSP.R
    sh ExportENVI.sh
    

    And the ExportENVI script is:

    #!/bin/bash
    #Exports corrected layers to single image file for ENVI
    
    group_list=$(g.mlist type=rast pattern=msp* separator=,)
    echo $group_list
    i.group group=MSP1 input=$group_list
    r.out.gdal input=MSP1 output=/home/Documents/MSP/group_output.img format=HFA
    r.out.gdal input=MSP1 output=/home/Documents/MSP/group_output.img format=ENVI
    exit 0
    

    I am not certain about the correct format for ENVI, if I need to do both .img and .hdr here, but I'll keep working.