The Load Them All plugin allows you to load at the same time a number of layers stored in a directory structure, based on a variety of filters you may customize.
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.
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.
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:
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.
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.
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!).
Update (18.01.2015): Version 2.3
Thanks to Sören Gebbert, v.2.3 of Load Them All includes:
- Support for boolean operators in the alphanumeric filter. Operators like || (for boolean OR) and && (for boolean and) can be used to combine regular expressions in one string.
- Examples 1: This alpha numeric filter expression with boolean OR operator “Ae || Ar || As || B[ers]” will load all files that have at least one of the sub-strings “Ae”, “Ar”, “As”, “Be”, “Br” and “Bs” in their file names.
- Example 2: This alpha numeric filter expression with boolean AND operator: “W[ie] && city” will load all files that have the sub-strings of “Wi” or “We” and “city” in their file names. The names Wittenberg_city.shp and Wesenberg_city.shp for example will fit this criteria.
- Bounding-box filter: The bounding-box filter allows the selection of raster or vector layers that are located within or intersect a user defined spatial extent. The user defined spatial extent can be loaded from the current spatial extent of the map view or can be edited by the user directly. Two radio buttons allow the user to select the spatial topological relations intersection or contains that must be fulfilled. The implementation of this filter makes sure that it is applied after the alphanumeric and geometry filter (when enabled) for performance reasons, since the spatial extent check requires to open the pre-selected raster or vector layers and to determine their spatial extent.
- Source code structure: A new and easier way of dealing with multiple filters. In older versions it was only possible to handle up to 2 filters at once. By using a list of filters it is now possible to mix 2+ different filters.
Additionally, the following options and bug fixes have been included:
- Case insensitive option for the alphanumeric filter (Configuration tab).
- Accent insensitive option for the alphanumeric filter. This option requires the Python lib ‘unidecode’ and can be activated in the Configuration tab.
- Performance improvement in alphanumeric filter. RE patterns are compiled and reused.
- Bug fix: Similar to the bug fixed in v.2.2 related to trailing slashes, the same bug was occurring on Windows (e.g., “c:\\folder\\”).
- The source code of the plugin was migrated to GitHub: https://github.com/gacarrillor/loadthemall Feel free to improve the plugin, suggest features, etc.