I am looking for a way to convert the values contained in a QgsRasterLayer object to a numpy array and vice versa without using any GDAL methods. To obtain the numpy array I go through QgsRasterDataProvider to QgsRasterBlock and then read the values into a numpy array through the QgsRasterBlock.value(i,j) method. This is not very elegant, but runs in an acceptable time. Analogously - after working with the numpy array - I change the values in the QgsRasterBlock through the QgsRasterBlock.setValue(i, j, value) method, which takes forever and is not acceptable for my application... so I am looking for an alternative!

I've read that handling the pixel values in the QgsRasterBlock object as QByteArrays and creating numpy arrays directly from the QByteArrays is possible and efficient (as compared to the method described above).

So my first question: Is this true?

My second question: What does the numpy function to create an array from QByteArray look like? And which function can I use to go back again?

closed as too broad by ahmadhanb, Vince, HDunn, whyzar, Jochen Schwarze Apr 17 at 8:13

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.