I want to print the minimum and maximum pixel values of a raster.

When I load the raster Pioneertown.row1.asc in Layers Panel in QGIS, it is showing minimum value = 'nan' and maximum value = '1' .

ds = gdal.Open("E:/Sreeraj/Task Global Data CONVERSION/Split/output/Pioneertown_Agriculture/Pioneertown_row1.asc")
stats =   ds.GetRasterBand(1).GetStatistics(0,1)
print stats
[1.0, 1.0, 1.0, 0.0]

According to this Python program in Python Console in QGIS, I am getting minimum value = '1.0', maximum value = '1.0', mean value = '1.0' and standard deviation = '0.0'.

But, I want to get minimum value = 'nan' or '0.0' or '-999' (no data value).

For that, what should I do ?

  • Can you load the .xml file in a text editor and check the statistics stored in the metadata to see if they match with the values shown in the console? Your code works fine (tested on .asc files).
    – Joseph
    Commented Jan 24, 2018 at 10:50
  • 1
    @Joseph I have checked the .xml file and it is showing that the minimum value = 1. But, when I load the .asc file in QGIS, in layers panel it is showing that the minimum value = 'nan'. When I checked for other data, the minimum and maximum values shown in the .xml document are different from the .asc data loaded in QGIS layers panel. So, which is actually correct ?
    – Sreeraj
    Commented Jan 24, 2018 at 11:56

1 Answer 1


QGIS Layers Panel might be showing the range of your data differently.

This is a test using a small constant grid (integer) with all cell value is set to 1.

When the raster is loaded, QGIS Layers Panel shows nan for minimum. enter image description here

On the layer properties, QGIS default settings will looks like this (1) and (2). enter image description here

(3) Please change its setting to Min/max (and Accuracy - Actual) and click on Load button.

enter image description here

Then the value seen on the Layers Panel can change. Its actual value depends on your dataset.

  • 1
    Is there any way to permanently change the settings to ''Min/max'' (and Accuracy to ''Actual'') as you described in (3) ? Now, every raster data which I open in QGIS is having settings as you described in (2). Eventhough when I change the settings to (3) for a raster data once, but when I load the same raster data in QGIS next time, the settings is getting changed to (2) automatically. But, I want to permanently change the settings as you described in (3). How can I do this ? Please suggest the solution for this.
    – Sreeraj
    Commented Jan 29, 2018 at 9:12
  • @Sreeraj um, sorry I really don't know how to change its default settings.
    – Kazuhito
    Commented Jan 29, 2018 at 9:39
  • 1
    @Sreeraj One possibility: Settings | Options | Rendering (tab) where you can find Rasters. There is an option Limits (minimum/maximum) which default would be set to Cumulative pixel count cut. Please change it to Minimum / maximum and see if it works.
    – Kazuhito
    Commented Feb 13, 2018 at 5:45

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.