7

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.

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

2 Answers 2

5

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

1
  • 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
    Commented Nov 19, 2012 at 22:57
3

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 and acknowledge you have read our privacy policy.

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