2

Is there a way to add multiple layers to QGIS at once from a list of paths?

I have about 150 rasters to investigate that intersect an area of interest. Their full path is collected in a text file, one image per line. I know I can open layers on the command line with qgis path\to\imageone.tif path\for\imagetwo.tif but there's too many to add that way.

I've tried redirecting qgis < in-tiff-list.txt but that doesn't work.

I can open each image in it's own session with something like for /f %a in (in-tiff-list.txt) do qgis %a but that's a lot of memory overhead and you can't compare layers to each other.

Perhaps there's a way to inject into a running instance of Qgis instead of starting a new session? e.g. for {list of paths} do run "qgis --single-instance %file-path%" (pseudo code).

I'm running QGIS 3.16 on Windows.

5
  • If the files are in the same folder, use Data Source Manager to select multiple files/the whole content of the folder at once.
    – Babel
    Commented Jul 8, 2021 at 19:30
  • 2
    Have you used the Load Them All plugin before? Depending on the file-folder structure you could configure it to load all your rasters. Commented Jul 8, 2021 at 19:43
  • 1
    Depending on what you want to do afterwards, you could run an algorithm that expects raster layers as input: run it in batch mode, where you have sophisticated possibilities to load filenames, defining certain patterns for paths and/or using QGIS expressions to defained detailed instructions what files to use. Documentation does not mention it all, it is outdated: docs.qgis.org/3.16/en/docs/training_manual/processing/…
    – Babel
    Commented Jul 8, 2021 at 20:01
  • @Babel unfortunately the files are spread all over the place and not in one or even a handful of folders. Commented Jul 8, 2021 at 20:05
  • @GermánCarrillo oh that looks interesting! ...but not for this scenario as the filenames don't have common fragments to apply search patterns to. Bookmarked for later though, thanks. Commented Jul 8, 2021 at 20:07

2 Answers 2

2

The crude I solution I went with is:

  • in a single folder build for each raster in the list file
  • drag and drop all the .vrt onto QGIS

I built the vrt files with (CMD Shell):

for /f %a in (in-tiff-list.txt) do ^
  (gdalbuildvrt staging-folder\%~na.vrt %a)

I'll have some more as yet unidentified legwork later to locate the home folder for each of the rasters but this solves the immediate visual need.

0

I'm not sure about Windows but with a POSIX subshell you could do

qgis (cat in-tiff-list.txt)

which is equivalent to qgis path\to\imageone.tif path\for\imagetwo.tif. maybe there is something similar in PowerShell

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.