18

I have downloaded several imagery Zip files (content of each is jp2, jpg, jpw, xml, htm, and .dbf, .prj, .sbn, .sbx, .shp, .shx) and would like to quickly add this imagery to my working project in QGIS 2.6.1. I am trying to avoid having to navigate to and add each file separately. Because each file is in a different folder, I have not been able to find a way to add multiple files at once.

2
  • So you have zip files in you folders or you have already extracted the zip files' content? I'm elaborating an answer for the latter case. I'm afraid the former case would require a bit of (Python) scripting. Commented Mar 19, 2015 at 23:46
  • I have already extracted content.
    – reevesii
    Commented Mar 19, 2015 at 23:51

4 Answers 4

34

What you need is the QGIS plugin Load Them All. Apart from loading files from several directories at once, you can:

  • Reflect the directory structure in the QGIS Layer Tree / Table of Contents (by means of nested layer groups).
  • Apply alphanumeric filters so that you just load layers that match your filter (think of regular expressions).
  • Load only certain geometry or raster type (e.g., only polygon vectors or Multiband rasters).
  • Load only certain file extensions (e.g., only .shp files).
  • Load only layers that lie inside or that intersect a given bounding box.

and more. Have a look at https://github.com/gacarrillor/loadthemall for more details.

Note the plugin can search for / filter sublayers (e.g., inside a GeoPackage file).

enter image description here

3
  • @Germán Carrillo It seems like the perfect plugin for my needs, yet when I try to load the files I get the error: "There are no KML files to load fromt he base directory with this filter. Change those parameters and try again". I'm using QGIS 2.14.2, all filters are turned off and the map I selected contains two maps with one kml file each (just to test, I have a larger dataset to import). Commented Jan 3, 2017 at 13:48
  • @HannesLedegen Did you try with the 'Interesects' filter instead of 'Contains'? If that doesn't work, please open a new issue in the GitHub page of the project, describing everything in detail. Commented Jan 3, 2017 at 14:14
  • Doesn't seem to work for delimited text files. Commented Jul 31, 2023 at 23:33
4

As an alternative to using a plugin, you can give the Add Layer command a semicolon-delimited list of files. You can create such a list in the following manner:

cd /d <Path_to_the_directory_where_your_files_are>
dir *.shp /s /b >All.txt

This gives you a file named All.txt, which contains the paths to all the files with a specific extension (you can use a different mask depending on the files you have), where each file is on a new line.

D:\Data\01\data01_1.shp
D:\Data\01\data01_2.shp
D:\Data\02\data02_1.shp
D:\Data\02\data02_2.shp

Then simply replace all newlines with ; using a text editor (like Notepad++) and paste the result in the Add Vector Layer... dialog.

For Notepad++ you need to change the replace mode to Extended and replace \r\n with ;. You would get a file that looks like this:

D:\Data\01\data01_1.shp;D:\Data\01\data01_2.shp;D:\Data\02\data02_1.shp;D:\Data\02\data02_2.shp

UPDATE: Newer versions of QGIS expect a list of files where each entry is enclosed in double quotes and the entries are separated by a single space instead of a semicolon. So once you have the list of files from the first step, do the following replaces in Regular Expression mode:

Find what Replace with
^(?<file>(.+))$ "\1"
\r\n (space)

If you don't have a regex-capable editor handy, you can replace the start of your path with a double quote and the path (say, D:\Data\ with "D:\Data\) and the extension with the extension and a double quote (say, .shp with .shp").

2
  • 1
    I love this solution, but in my case (QGIS 3.14, en-US), I had to enclose each path in double quotes and use spaces instead of ;. For example: "D:\Data\01\data01_1.shp" "D:\Data\01\data01_2.shp"
    – jabellcu
    Commented Mar 14, 2021 at 21:40
  • Doesn't seem to work for delimited text files. Commented Jul 31, 2023 at 23:37
1

On Linux, you can extract a list of .shp files and feed it directly into the "Import Vector" dialog:

#on the command line
ls /home/yourpath/*/*shp|tr "\n" '@'|sed 's/@/" "/g'|sed 's/^/"/g'

enter image description here

I found this useful under QGIS Docker, beacuse for some reason the "Load Them All" plugin was not showing its dialog.

1

Another alternative would be to develop a small Python code to load the files and run it from Python Console on QGIS.

It could be a for loop in which you either have the names of the files in a list and you loop over them, or, if the filenames have a pattern, you can use this pattern to build strings with the files paths and names, and then load them.

In case the layers are rasters, you can load them (in the loop) by using

name_layer= 'name_' + number

raster_layer = QgsRasterLayer(path_to_file, name_layer)

QgsProject.instance().addMapLayers([raster_layer])

Wrap it in a loop and it should work (for rasters).

I coded a snippet to load raster layers. The snippet and a larger explanation of how to use it and adapt it to your case can be found at: https://www.luisalucchese.com/post/batch-process-load-raster-layers-qgis/

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.