[GIS] How to batch import GDAL supported raster files into GRASS

grassimportqgisraster

I am trying to import some GDAL supported raster files into a binary raster map layer using the r.in.gdal module from QGis Grass tool.

As I have multiple files to import, I would like to batch import them.

Is is possible or should do I have to repeat the same operation for every single file?

I work with QGis 1.8.0 Lisboa.

Best Answer

You can easily do this using QGIS python console. To get Python Console

QGIS 1.8.0 Lisboa -> Plugins -> Python Console

Find the attached screenshot which loads all files(vector - shape) from a specific directory QGIS bactch load layers

Below is the code for loading vectors.

shp_path="C:\\Users\\rashad\\Documents\\kerala"
shps = glob.glob(os.path.join(shp_path,"*.shp"))
for shp in shps:
    (shpdir, shpfile) = os.path.split(shp)
    qgis.utils.iface.addVectorLayer(shp, shpfile, 'ogr' )

For your purpose you need to modify a bit

raster_path="C:\\Users\\rashad\\Documents\\all_raster_maps"

#you can say other extension or *.*
rasts = glob.glob(os.path.join(raster_path,"*.tif")) 
for rast in rasts:
    (rastdir, rastfile) = os.path.split(rast)
    qgis.utils.iface.addRasterLayer(rastfile, "raster")

Hope that helps

Related Question