1

I want to perform a simple calculation on a raster (.tif) file in QGIS3.22, but it is generating unexpected values in the output. The image below shows the "input" layer to the calculation.
Input raster layer.

I then use the "raster calculator" and enter the following options: enter image description here

Clicking OK yields the following "temporary" layer: enter image description here

I've tried various methods without success. I also used GDAL (Python) to read the .tif file and edit it, but this is not a feasible long term solution. All the .tif files have a single band and when I query the "input" layer in the regions of study, there is "no data" under these points. As a result I think that the raster calculator is incorrectly interacting with the missing data leading to "memory overflow". I've encountered similar looking numbers when examining unallocated memory with the C programming language in the past (unrelated and integers instead of floats).

5
  • Have you considered using Grass instead of GDAL ?
    – GforGIS
    Commented Jul 31, 2023 at 5:05
  • 1
    It looks like NoData, as you expected, are being calculated also. Check that the NoData is correctly defined; I've had better success when converting GeoTIFF to ERDAS IMG format as the TIFF specification has been touched by lots of interested parties and has become a little sloppy. Commented Jul 31, 2023 at 5:38
  • 1
    @BERA, I performed this action, but it did not solve the issue. The minimum is indeed -3.4e+38, which is a pain. Thanks for the suggestion. Commented Aug 1, 2023 at 1:06
  • @MichaelStimson, I've now also tried your suggestion of using the ERDAS IMG format. I'm going to make a new question about this because the output was even more strange. Commented Aug 1, 2023 at 1:51
  • @MichaelStimson, your approach using ERDAS IMG has solved the problem. Thank you. I'm not a hundred percent sure how stack exchange works but if you want to post an answer I will approve it. Commented Aug 1, 2023 at 4:13

2 Answers 2

1

I have been persistently having the same issue. When using the raster calculator with the below formula to select only values greater than or equal to 0.75 I expect a raster where pixels are either 0 or 1 in value. My raster is a .tif file. Tried this operation in both QGIS 3.28 and 3.36 with the same results.

input raster (.tif) is of NDVI values: all values fall between 0 and 1 raster calculator formula: "NDVI-Raster@1" >= 0.75

At least half the time I attempt this the result is a raster with extremely large max and extremely small min (ie. -3.40282e+38 to 3.40282e+38). If I repeat the attempt once or twice more I will typically get a 'correct' result (a raster with values of 0 and 1 that appears to match the expected result.

As suggested by Michal Stimson above using the ERDAS IMG format rather than GeoTiff seems to solve this specific problem for me. Thanks for the work around!

It does seem that there is something going wrong with the raster calculator and at least the .tif format although the fact that I can repeat the same operation multiple times and sometimes get wild results and sometimes get 'correct' results is confusing.

I converted my raster to the ERDAS IMG file (.img) using Raster->Convert->Translate

When I run the result as the input raster (.img) with the same formula in the raster calculator the problem appears to be eliminated.

1

I had the same problem, adding a raster offset heights to a DTM, to obtain a sort of DSM. The two raster are GeoTIFF and have the same extension and pixel resolution, both Float64 data type.

The result is a GeoTIFF that have that strange 'no data' values.

Converting the two raster data in ERDAS Imagine format didn't fixed the issue, moreover I obtained a raster with totally wrong values for the heights.

The odd thing is that adding the very same two raster in ArcMap, using raster calculator, I obtain a suitable raster data, with minimum and maximum values compatible with the added heights.

I think this odd behaviour of QGIS with raster calculator deserves a serious fix.

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Oct 4, 2023 at 21:02

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.