3

I'm developing a Qgis plugin to use my own raster resampling method rather than what is provided in Qgis (cubic/bilinear).

And so, I've extended the QgsRasterResampler class. However, I'm having difficulty getting resample method to work.

Based on the C++ api documentation for resample method: http://qgis.org/api/classQgsRasterResampler.html#aaffb31ed35ed12353e49458be27b06ba

The 'dstImage' arg is passed by ref and I'm not sure how return it to the calling function in python. As such, when the resampling method is applied, I get a blank image instead.

  • I've been looking around this part of the api doc too and am curious to see if you can find an answer. Sorry I'm not familiar enough with it to help out, but, I'd like to see if the same function or a similar function can be applied to improving the image quality when rendering tiles, as in this question: gis.stackexchange.com/questions/171852 – Tom Grundy Dec 2 '15 at 14:53
1

Yep, I've found a way, the main idea is to copy the data into 'dstImage' without re-instantiating a new QImage for it:

def resample(self, srcImage, dstImage):
    # process image
    temp = srcImage.scaled(dstImage.width(), dstImage.height())

    # get temp data as QByteArray
    data = QtCore.QByteArray()
    buffer = QtCore.QBuffer(data)
    buffer.open(QtCore.IODevice.WriteOnly)
    temp.save(buffer, 'png')

    # finally save it to dstImage
    dstImage.loadFromData(data, 'png')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.