[QGIS-Developer] PyQGIS WMS tiles don't load on Windows

Erik Polzin eriktpol at gmail.com
Tue Apr 9 00:54:03 PDT 2019


I'm busy developing an app using the QGIS Python api, PyQGIS, and am
noticing some strange behaviour when loading WMS tiles: Running the python
script on Linux Mint loads xyz layers from Google Maps and Google Satellite
just fine. On Windows, only the Google Maps layer loads.

Here is a test script I wrote to demonstrate the problem:

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):
        super().__init__()

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

        layer = QgsRasterLayer(GOOGLE_SATELLITE_SOURCE, "Test WMS Layer",
"wms")

        QgsProject.instance().addMapLayer(layer)
        self.canvas.setLayers([layer])

        self.setCentralWidget(self.canvas)


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

app = WMSTestApp()
app.show()
qgs.exec_()
qgs.exitQgis()

Interestingly, the layers (from the same sources!) both load from the
Windows QGIS app.
So I did some digging and noticed that the default Google Maps url returns
PNG files, while the Satellite url returns JPEGs. I tested a couple of
other links, and it seems like only PNG tile servers have any effect on
windows systems.

Have tested this on Windows 7 and 10, with the same results.

Does PyQgis need to be reconfigured in some way to get this to work? Or is
it a known issue with the version (3.4) I'm using?

Cheers and thanks,
Erik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190409/0ff05fa7/attachment.html>


More information about the QGIS-Developer mailing list