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.
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 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.
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
;. You would get a file that looks like this:
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'
I found this useful under QGIS Docker, beacuse for some reason the "Load Them All" plugin was not showing its dialog.
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/