2

I am generating png images of concentration maps, resulting from air quality modelling. Resulting files are croped and coverted to tiff files and than loaded into QGIS in Python:

rlayer = QgsRasterLayer(data_folder+parametr+'.tif',opis_txt)
projectInstance.addMapLayer(rlayer)

Then I load a pre-defiend QgsPrintoutLayout and export the results to a pdf file. Everything works fine, however by default raster is interpolated using Nearest Neighborhood which creates pixelized results.

In QGIS interface I can switch the resampling method for each layer to cubic or bilnear and this solves my problem, however I would like to do it automatically. So my question is can I do the same in Python script?

1

Thank you Joseph. Your comment solves my problem.

rlayer = QgsRasterLayer(data_folder+parametr+'.tif',opis_txt)
resampleFilter = rlayer.resampleFilter()
resampleFilter.setZoomedInResampler(QgsCubicRasterResampler())
resampleFilter.setZoomedOutResampler(QgsCubicRasterResampler())
projectInstance.addMapLayer(rlayer)

I was unable to find QgsCubicRasterResampler in the API doc, because I was searching for a clas name wich contains QgsRasterResampler

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.