In QGIS I am trying to read raster band data from a specific layer in my Python plug in.
I can easily get access to the layer from the console with something like this.
and I can easily get access to a single random pixel value with something like this.
but what I want to do is grab the whole band matrix of values. something akin to this.
ds = gdal.Open(iface.mapCanvas().layers().source()) band1 = np.array(ds.GetRasterBand(1).ReadAsArray())
but without having to open up the file again.
I assume since the band data is attached to the layer that I must be able to access it somehow, but I've now spent hours reading documentation trying to figure it out only to come up short.
Is there a way to read band data from a raster layer into a numpy array in pyQGIS once I get access to the layer I care about? or is the "open a file using the layer source with GDAL" my best option?