4

Background:

I have six adjacent DEMs (NED 1/3 arc-second .img files from The National Map). The min-max values among the six range from:

90.4 - 2100.0

Problem:

Using the 3.6.2 Raster > Miscellaneous > Build Virtual Raster tool, the resulting VRT's values range from:

105.7 - 1886.49

I expected the VRT's min-max value range to match the min-max range among the six rasters.

I then created a VRT from a single input raster, and again, the resulting VRT values did not match the source raster.

Varying the resample method made no difference.

Since the VRT is a "snapshot" of the input rasters, I would expect its min-max values to equal the min-max values of the its source rasters.

What am I missing?

2
+500

Following up on @Mat's answer, consider that the range shown by default in the "Simbology" tab of your original tiles (90.4 - 2100.0) is also an estimate, because QGIS defaults to using the "faster" method to estimate the value range of a raster file.

From "Raster->Miscellaneous->Raster information..." you can see both the actual and the statistic value range of each layer (both physical and virtual):

Just make sure to check the "Force computation of the actual min/max values for each band":

Raster information dialogue

then hit Run, and observe the output in the log tab:

Raster information output

you will see that the computed (actual) and statistics value are different from each other.

Somewhat confusingly, the "computed" values are the one that you see in the "Properties" window, labelled "STATISICS MINIMUM/MAXIMUM":

Properties-Information

Proofing the difference

Out of curiosity, I mapped the color gradient to be black under my "Estimated/faster" maximum, and ramp up to my "Actual/slower" maximum.

Color ramp extents

This resulted into a visual highlight of the areas where the values where between the "Estimated" and the "Actual" values.

Using the "Info tool" and clicking in one of the white pixel, the reported value (2168) was actually higher than the Estimated maximum (2118). Proof that the estimated min/max are just a rough approximation.

enter image description here

This is what you might want want to do in case of doubt ;)

Also, you can change the default cutoff values (2% and 98% respectively) and/or play around with some values under the advanced options dialogue:

advanced options

  • Nicely done, @RafDouglas! More than just a simple answer, you provided useful background info. However, I'm still puzzled WHY an estimated min-max would ever be used, since it's next to impossible to know if what you're reading is calculated or estimated, plus there's no documentation indicating what formula was used to create the estimated values. – Stu Smith May 8 at 4:29
  • I think that the "faster" approach only samples a given number of pixels to determine the range, while the "slower" necessarily has to read every single pixel. In small maps the difference is not noticeable, but for very large raster that can make a difference. Anyway, I found out where to tinker (see edited answer above) with default options. Give that a try! – RafDouglas May 8 at 6:53
  • Here, line 154 you can see that the default option for StatAccuracy mAccuracy is "Estimated" instead of "Exact". That explains the default behavior. If you are into it, you could change that line to have a customized version of QGIS (but I am not advocating this ;) ) – RafDouglas May 8 at 7:00
  • Or you could add setStatAccuracy(self, accuracy: QgsRasterMinMaxOrigin.StatAccuracy) to startup.py – RafDouglas May 8 at 7:21
  • 1
    Above options can also be changed Rendering tab, Rasters without having to be careful :) but it does not affect Estimated/Actual setting! I guess changing qgsrasterminmaxorigin.h would but i agree with @rafdouglas about custumizing QGIS. Also, i think setting "Actual" as default is bad idea in general. – Mat May 8 at 7:26
4

You are probably looking at estimated values. Check under layer properties, Symbology tab if Actual Accuracy is selected:

enter image description here

Virtual raster is basically just list of rasters, when creating it original data does not get altered, just referenced.

  • Thanks, @Mat. Straight to the point. I need to find out how to make "Actual" the default setting. – Stu Smith May 8 at 4:12
  • 1
    Especially when working with VRTs you dont want "slower" option by default, because it can be really slow when working with larger sets. Id say it is safer to keep "faster" as default and only when for some reason you need exact, change it. Keep in mind these values are for displaying purposes only, not for any calculations you might do with the data. – Mat May 8 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.