qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.38k stars 2.98k forks source link

Raster file order is reversed when building virtual rasters #39731

Open klakar opened 3 years ago

klakar commented 3 years ago

Describe the bug This affects sets of raster files that overlap, and when you want to control the order they appear in the virtual raster. (related to #32403 ?)

Skärmbild från 2020-11-01 10-43-24

When you select layers in the dialogue the order from the start is not necessarily in the same order as in the QGIS layer list (alphabetical order?), but the layers can be rearranged by drag and drop.

However, the "top" layer in the list will be drawn first in the resulting virtual layer, which place it at the bottom.

Skärmbild från 2020-11-01 10-15-38

One issue with rearranging the order is that one layer will be duplicated in the resulting virtual layer. As far as I have found it is the last layer in each band section that is a duplicate and it can be manually removed from the vrt textfile.

How to Reproduce

I have been using Sentinell 2 imagery that have a natural overlap between scenes, and there are scenes with partial coverage that are interesting to combine with other scenes to build a nice looking mosaic.

Mostly tested *.jp2 files with multiple bands, so it's not clear if this issue is limited to only that type of rasters (shouldn't be).

Any set of rasters should reproduce this issue.

QGIS and OS versions

QGIS version 3.16.0-Hannover QGIS code revision 43b64b13f3
Compiled against Qt 5.12.8 Running against Qt 5.12.8
Compiled against GDAL/OGR 3.0.4 Running against GDAL/OGR 3.0.4
Compiled against GEOS 3.8.0-CAPI-1.13.1 Running against GEOS 3.8.0-CAPI-1.13.1
Compiled against SQLite 3.31.1 Running against SQLite 3.31.1
PostgreSQL Client Version 12.4 (Ubuntu 12.4-0ubuntu0.20.04.1) SpatiaLite Version 4.3.0a
QWT Version 6.1.4 QScintilla2 Version 2.11.2
Compiled against PROJ 6.3.1 Running against PROJ Rel. 6.3.1, February 10th, 2020
OS Version Linux Mint 20
Active python plugins pluginbuilder3; LmOpenData; latlontools; slyr_community; MetaSearch; processing; db_manager

Additional context

The "doubble" layer I have no suggestion for, but two improvements could be:

  1. Present layers in the same order as in the QGIS Layers list.
  2. Reverse the order of the files in the file list (that the user don't normally see).
anthony-scarth commented 3 years ago

I agree that the order when mosaicing adjacent tiles can be somewhat confusing. The first file passed to gdalbuildvrt will be the first file processed and therefore will become bottom of the "stack". This could be unexpected when reordering layers in QGIS, as you say, as the top layer in the list will end up at the bottom. The same is true of GDAL Merge, I believe.

I'd like to add though that when "Place each input file into a separate band" is checked (-separate), the top file in the list will become the first band in the output, which I think would actually be expected.

So QGIS reversing the list to pass to GDAL might not be appropriate in all circumstances.

I've also noticed the "double layer" problem. I felt like it was an additional issue to the title of this card so I've made a separate report here: https://github.com/qgis/QGIS/issues/44270