(The Spanish version can be found here)
A few days ago my girlfriend asked me something related to QGIS. She wanted to know whether it was possible to load several Shapefiles at the same time, even being stored in a directory structure. I didn't know how to do it with the QGIS tools but I thought it would not be so hard to write a little script using the python console with PyQGIS. So I wrote it and she said it was great, but it was not exactly what she wanted. She needed something more specific: to load several files based on a kind of alphanumeric filter, so I modified the script slightly and it worked like a charm.
So what?
Well, now it is a QGIS plugin and it has some additional filters.
It is called 'Load Them All' because it allows you to load all the files you have in a directory structure. The plugin is able to load file-based layers (GML, SHP, TIF, IMG, among others), whereas database layers are not supported due to the appropriate way in which QGIS deals with them.
Loading all layers from a directory (recursively)
Imagine you have a directory structure like this:

To get all your layers (shapefiles) loaded in QGIS you have to set a base directory from which the plugin will search and you have to choose the format you want to load, i.e. for vectors: Shapefile, Mapinfo, CSV, GML, GPX, KML, GeoJSON, GMT, e00, DXF or GeoRSS, whereas for rasters: TIF, IMG, ASC or DEM.

And click on OK.
Loading layers based on an alphanumeric filter
For the previous example, imagine you need to load only those layers who start with the word 'zona', so you should set an alphanumeric filter:

You do not need to write the usual characters to set filters, such as * or %, just use one of the 3 types of match: Starts with, In any position and Ends with.
NOTE: If you leave the filter string empty, the alphanumeric filter will not be applied.
Now click on OK.
Loading vector layers based on their geometry type
Let's forget for a while the alphanumeric filter.
Now imagine you need to load all the point layers, so you have to set a geometry type filter:

You may choose more than one geometry type to set your filter but if you choose all the possible options (Point, Line and Polygon) the geometry type filter will not be applied.
Now click on OK.
Loading raster layers based on their type
If you need to load rasters based on their type you have to set a raster type filter:

You may choose more than one raster type to set your filter but if you choose all the possible options (Gray or Undefined, Palette and Multiband) the raster type filter will not be applied.
Now click on OK.
Mixing filters
You may be wondering if it is possible to set an alphanumeric filter and a geometry (or raster) type filter at the same time. The answer is yes.
Just set each filter and click on OK.

It works either for vectors or rasters.
Configuring the plugin
You might customize a number of aspects of the Load Them All plugin:

Create groups:
Check this option to get the loaded layers organized into groups taking directories' names as a base.

Turn off the layers by default:
Check this option to get the loaded layers turned off.

Show a dialog to let you know the process is done:
Check this option to know when the loading is done by means of a dialog.

Number of layers to show a confirmation dialog before the loading:
A confirmation dialog will be shown when the number of layers to load is greater than or equal to this number. Set this to 1 if you want the dialog is always shown.

Technical issues
The Load Them All plugin was written having in mind the strategy pattern for encapsulating the range of filters that can be applied. Have a look at the design:
Ok, so, how do I install it?
You might download it from here (loadthemall.zip) and copy the extracted folder into the QGIS plugins directory:
In GNU/Linux it should be in /home/user/.qgis/python/plugins/
In Windows most likely it is in: c:/Documents and Settings/user/.qgis/python/plugins/
Restart QGIS and go to the Plugin Manager to activate it.
Contact
Feel free to report bugs, suggest improvements or say hello at geotux_tuxman [at] linuxmail [dot] org
=================================================
Update (11.03.2011): Version 1.4
These changes have been implemented:
- New option: Do not load empty vector layers.
- New vector and raster formats added.
- Now it is possible to select the option "All listed formats (*.*)" from the format filter.
=================================================
Update (29.03.2012): Version 1.5
These changes have been implemented:
- GPX format correctly handled by considering track, route and waypoints (problem reported by Arnaud LE BRETON, thanks!).










comments
Sds.
Adolfo
RSS feed for comments to this post