8

I am trying to work with DEM rasters from the USGS using the raster calculator. I have tried to change the units from meters to feet using an expression such as:

"ned10m45111h8@1" * 3.28

However this returns NAN values for every cell. I have also tried it without the quotes around the raster name as shown in this website: http://spatialgalaxy.net/2012/01/25/using-the-qgis-raster-calculator/

Similarly, I have tried the mask code:

("ned10m45111h8@1" <= 1328.96)*"ned10m45111h8@1"

With and without quotes and get NAN returned for all values. Is there some default setting that I need to add, or some fundamental mistake I am making? I'm new to QGIS, but not to GIS and could easily do this with ARCGIS and spatial analyst.

4
  • 1
    I think I remember reading somewhere that this is an issue with projection... The raster calculator in QGIS doesn't adhere to the "project on the fly". Even though you are only using one raster in the operation, maybe try exporting it to the same projection as your QGIS document.
    – Tangnar
    Commented Jul 13, 2015 at 17:28
  • 1
    Do you mind sharing your QGIS version? If it's < 2.10, then it's worth trying with the 2.10 version. The raster calculator had a ton of fixes for 2.10, including many that sound like possible causes of this...
    – ndawson
    Commented Jul 13, 2015 at 22:30
  • Have you considered using GDAL_Calc gdal.org/gdal_calc.html Gdal_Calc.py -A ned10m45111h8 --outfile=result.tif --calc="A*3.28084" Commented Jul 14, 2015 at 5:05
  • just echoing @ndawson for anyone else stuck here. I was running 2.4 and had this problem - upgrading to 2.14 solved it immediately
    – Owen
    Commented Dec 6, 2016 at 9:56

3 Answers 3

5

This is an old post, but I came across it while having the same problem. It turns out my issue was that the extents of the calculation were set by default to the current layer extents of the first raster band on the list. I was trying to do my calc on another raster band, but the extents do not update when a different one is selected.

I had to click on the raster band I was doing the calc on and hit the "current layer extent" button. Voila.

1
  • This worked for me also. First click one of the bands you want to work, then Current Layer extent. If you do first Current Layer Extent may result in NaNs
    – DarkCygnus
    Commented Oct 3, 2017 at 17:34
2

I am hoping to help anyone else looking for answers to dealing with the QGIS raster calc returning NaN rasters. I used the GDAL raster calculator in the Processing Toolbox on QGIS 3.4.

I tried every solution I found on the stack exchange and nothing worked for my raster, shown below: screenie of raster info

I updated QGIS, set CRS from selected layer, forced QGIS to project the layer to the correct CRS, changed the file name of my raster, and changed NaN values to 0 on the raster. None of these solutions allowed me to perform any raster calc function, even a simple one like "twentysix@1" * 1.

Using the GDAL Raster Calculator solved whatever issue QGIS Raster Calculator had with the raster. Hope people can see this who need it! It vexed me for days.

screenie of GDAL calc location

0

Had the same problem, tried all of the above with no joy.

I eventually solved it by exporting the .shp as a .csv, copying and pasting the relevant fields into a new .csv which I then used to preform the interpolation!

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.