2

I'm trying to import a large set of raster files into GRASS. The GUI import tool works fine for a handful of files, but it appears to require that I click the "Layer id" checkbox for each individual file that I want to import, and that doesn't work well at all for large sets of file. So my question is, how do you manage data in GRASS from the command line? I realize that this is a broad topic, so please feel free simply to direct me toward the documentation for the relevant tools.

I'd also be happy with an approach using the GUI tool in this case, but as I'd prefer a command-line approach because I'm just learning GRASS and need to script almost everything I'm doing, and have read that the Python GUI for GRASS has issues with Mac OS 10.8 (I haven't run into those issues, yet).

UPDATE: It does not appear that a GUI solution will work in this case. Having clicked the checkboxes for about 700 files that I wanted to import, the process does not appear to have succeeded due to a "to many files open" error. The tail end of the log is given below.

startupinfo, creationflags)
  File "/System/Library/Frameworks/Python.framework/Versions
/2.6/lib/python2.6/subprocess.py", line 616, in __init__

errread, errwrite) = self._get_handles(stdin, stdout,
stderr)
  File "/System/Library/Frameworks/Python.framework/Versions
/2.6/lib/python2.6/subprocess.py", line 978, in _get_handles

c2pread, c2pwrite = os.pipe()
OSError
:
[Errno 24] Too many open files
1
  • For others interested in learning about data management from the command line in grass, look up the documentation on the following commands: g.mapsets, g.mapset, g.list, g.gisenv, r.in.gdal, v.in.ogr.
    – Gregory
    Commented Mar 25, 2013 at 4:11

1 Answer 1

2

If you want to import multiple rasters into GRASS, you could use the following shell script as a basis:

for file in `ls *.tif`
do
  r.in.gdal input=$file output=${file%.tif}
done
4
  • I understand everything you've done there, except ${file%.shp}. Could you explain that for me?
    – Gregory
    Commented Mar 23, 2013 at 2:59
  • 1
    it just trims '.shp' from the filename so that it's not included in the vector filename in GRASS
    – dmci
    Commented Mar 23, 2013 at 11:01
  • Thanks for teaching me a new bash trick, I only knew how to do that with basename. Did you mean for it to trim the tif suffix (rather than .shp), since that should be the only suffix the loop sees?
    – Gregory
    Commented Mar 23, 2013 at 12:52
  • sorry, edited my answer above - it should have been %.tif
    – dmci
    Commented Mar 23, 2013 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.