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.

  • 1
    We assume Windows OS?
    – nickves
    Nov 16 '12 at 8:31
  • 1
    Yes, sorry, Windows 7.
    – Bap
    Nov 16 '12 at 17:29

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.

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


#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

  • I had a few problems with the Python code (probably because I had never used Python before...), so I used the GRASS interface. It works really well. Thank you!
    – Bap
    Nov 19 '12 at 22:57

Just for the record, the GRASS graphical user interface offers a convenient bulk import tool: http://grasswiki.osgeo.org/wiki/Importing_data#Bulk_data_import

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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