[QGIS-Developer] Wrong Output GetRasterband
Nyall Dawson
nyall.dawson at gmail.com
Wed Jul 25 15:45:03 PDT 2018
On Mon, 23 Jul 2018 at 19:37, Hauer Lukas <lukas.hauer at josephinum.at> wrote:
>
> Hello!
>
>
>
> I want to output the min and max of my layer properties via a python script. If I check it manually they are „Min 0.250754“ and „Max 0.726268“.
Which QGIS version? Check under the "load min/max values" group box to
double check that you're using "min/max", and not "standard deviation"
or some other method.
> But my output via the python console is something completely different. With the GetMinimum method I receive 0.0837957039475 and with GetMaximum I receive 0.788260400295.
>
> Script:
>
> testlayer = iface.activeLayer()
>
> dataset = gdal.Open(testlayer.source(), gdal.GA_ReadOnly)
>
> band = dataset.GetRasterBand(1)
This is GDAL api, not QGIS. If you want to try the QGIS way you should use:
testlayer=iface.activeLayer()
stats = testlayer.dataProvider().bandStatistics(1)
print(stats.minimumValue)
print(stats.maximumValue)
Nyall
More information about the QGIS-Developer
mailing list