3

In the QGIS Python console, this block of code returned a valid object in QGIS 2.16.3 and I think 2.18.6. I could view the static image in QGIS.

>>> reg = QgsMapLayerRegistry.instance()
>>> raster = QgsRasterLayer('https://maps.googleapis.com/maps/api/staticmap?center=51,0&zoom=10&size=2550x3300', 'test')
>>> raster.isValid()
>>> reg.addMapLayer(raster)

At least since 2.18.9 (tested 2.18.15 as well), raster.isValid() returns False.

This is not specific to the Google Static Maps API. The code block also used to work if loading other PNG/JPG images.

Am I missing a required component?

2

Try using http instead of https:

reg = QgsMapLayerRegistry.instance()
raster = QgsRasterLayer('http://maps.googleapis.com/maps/api/staticmap?center=51,0&zoom=10&size=2550x3300', 'test')
raster.isValid()
reg.addMapLayer(raster)

Result


Tested on QGIS 2.18.14.

  • Does this mean SSL requests in qgis are broken? What if we need to send the request over ssl for compliance reasons? – Alexander N. Dec 22 '17 at 12:42
  • @AlexanderN. - Check this post to see how to authenticate such requests: QGIS Handling of HTTPS URL Strings. It's not something I have used regularly :) – Joseph Dec 22 '17 at 12:48
  • 1
    @Joseph thanks! Using HTTP works on Windows but seems to fail on Mac/Linux. I've posted a new question here: gis.stackexchange.com/questions/266485/… – ash Dec 28 '17 at 15:55
  • @ash - Most welcome, glad it works for Windows. Unfortunately, I don't have a Linux machine to test it on but hopefully others can provide a solution :) – Joseph Jan 4 '18 at 10:48

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.