In a stand-alone/external PyQGIS app that I'm developing I've noticed that wms/xyz tiles that are returned as jpegs don't render on the map canvas but those that return pngs do.

So for example the Google Maps, layer=m which returns pngs does render fine.


But the Google Satellite, layer=s which returns jpegs doesn't render, nor does the Bing layer which also returns jpegs render.


I've tried adding an image format parameter, format=image/jpeg but it doesn't make any difference.


I used Fiddler on Windows to confirm that there were no network issues with the Google Satellite requests and I can see the jpeg tiles being returned successfully. It's actually how I first noticed that the working layers were returning pngs and the non-working layers were all returning jpegs.

Is there some parameter I haven't set for the raster layer to ensure that jpeg tiles are rendered?

The same wms/xyz tile URI, and without the format parameter works fine in QGIS itself, just not in my stand-alone PyQGIS app.

I'm using QGIS 3.4.

Here is a minimal PyQGIS app demonstrating the issue:

from qgis.core import QgsApplication, QgsProject, QgsRasterLayer
from qgis.gui import QgsMapCanvas, QgsLayerTreeMapCanvasBridge

from PyQt5.QtWidgets import QMainWindow
import os

GOOGLE_MAPS_SOURCE = "type=xyz&url=https://mt1.google.com/vt?lyrs%3Dm%26x%3D%7Bx%7D%26y%3D%7By%7D%26z%3D%7Bz%7D&zmax=19&zmin=0"
GOOGLE_SATELLITE_SOURCE = "type=xyz&url=https://mt1.google.com/vt?lyrs%3Ds%26x%3D%7Bx%7D%26y%3D%7By%7D%26z%3D%7Bz%7D&zmax=19&zmin=0"

class WMSTestApp(QMainWindow):

    def __init__(self):

        self.canvas = QgsMapCanvas(self)
        self.bridge = QgsLayerTreeMapCanvasBridge(QgsProject.instance().layerTreeRoot(), self.canvas)

        layer = QgsRasterLayer(GOOGLE_SATELLITE_SOURCE, "Test WMS Layer", "wms")
        print("Raster layer is valid?:", layer.isValid())



QgsApplication.setPrefixPath(os.environ.get("QGIS_PREFIX_PATH", "C:\Program Files\QGIS 3.4\apps\qgis"), True)
qgs = QgsApplication([], True)

app = WMSTestApp()

Fiddler showing the successful transmission of the jpeg tile.

enter image description here

Your Answer

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

Browse other questions tagged or ask your own question.