I have made a python script that loads several KML files and I'm gonna render them with a QPainter on a QImage. I set the extent to the QgsMapSettings.fullExtent(), when all my layers are part of the QgsMapSettings and added via QgsMapSettings.setLayers(layers). I only extent the scale of the view by 1.1 or 1.2 to just have a better view of the data with

rect = QgsRectangle(ms.fullExtent())

This works all great and I gonna save the image with the QImage.save function. The only problem I have is, that I have a XYZ Tiles layer, based on OpenStreetMap and I'm not able to add it to my Image.

I tried picking the layer with QgsProject.instance().mapLayersByName("OpenStreetMap")and adding it to my layers list and finally add it to QgsMapSettings with the QgsMapSettings.setLayers(layers) method, but all that happens is that it shows the geo-coordinates as points of the KML files, but not the XYZ layer.

When I try to add the layer after my KML layers, just with QgsMapSettings.setLayers(osm_layer), then my image only shows the lowest zoom level, without any data on it, which makes sense, because all the layers, which I have added before, are gone.

So what exactly I'm doing wrong?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.