[QGIS-Developer] PyQGIS WMS tiles don't load on Windows
Tim Sutton
tim at kartoza.com
Tue Apr 9 01:52:11 PDT 2019
I suggest taking a look at the source of the QuickMapServices plugin to see how they do it. Make sure to get the extra datasets from the plugin settings dialog.
Regards
Tim
> On 9 Apr 2019, at 08:54, Erik Polzin <eriktpol at gmail.com> wrote:
>
> 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 <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 <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
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
—
Tim Sutton
Co-founder: Kartoza
Ex Project chair: QGIS.org
Visit http://kartoza.com <http://kartoza.com/> to find out about open source:
Desktop GIS programming services
Geospatial web development
GIS Training
Consulting Services
Skype: timlinux
IRC: timlinux on #qgis at freenode.net
I'd love to connect. Here's my calendar link <https://calendly.com/timlinux> to make finding time easy.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190409/4db9ac6b/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: KartozaNewLogoThumbnail.jpg
Type: image/jpeg
Size: 6122 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190409/4db9ac6b/attachment-0001.jpg>
More information about the QGIS-Developer
mailing list