[Qgis-developer] WMS uncorrect rendering using "Simple Rendering" method
Luigi Pirelli
luipir at gmail.com
Thu Aug 14 05:02:53 PDT 2014
created a simple script isolating the rendering phase reveal that the
problem seems internal to the plugin
thank you
Luigi Pirelli (luigi.pirelli at faunalia.it - luipir at gmail.com)
---- this script works ----
from PyQt4.QtCore import *
from PyQt4.QtGui import *
wms=QgsRasterLayer("crs=EPSG:3003&format=image/png&layers=rt_ofc.10k13&styles=&url=http://www502.regione.toscana.it/wmsraster/com.rt.wms.RTmap/wms?map%3Dwmsofc%26",
"nome", "wms")
QgsMapLayerRegistry.instance().addMapLayers([wms])
# create image
size = QSize(800,600)
img = QPixmap(size)
img.fill(QColor(255, 255, 255, 255))
mainCanvas = iface.mapCanvas()
extent = mainCanvas.extent()
mainRenderer = mainCanvas.mapRenderer()
mapRenderer = QgsMapRenderer()
mapRenderer.setOutputSize( size, img.logicalDpiX() )
mapRenderer.setDestinationCrs( mainRenderer.destinationCrs() )
mapRenderer.setMapUnits( mainRenderer.mapUnits() )
mapRenderer.setProjectionsEnabled( mainRenderer.hasCrsTransformEnabled() )
layerIds = [wms.id()]
# set layer set
mapRenderer.setLayerSet(layerIds)
mapRenderer.setExtent(extent)
extent.scale( float(1000) / mapRenderer.scale() )
render.setExtent(extent)
# create painter
p = QPainter()
p.begin(img)
# do the rendering
mapRenderer.render(p)
p.end()
del p
mapRenderer.deleteLater()
del mapRenderer
# save image
img.save("/tmp/render.png","png")
On 13 August 2014 19:22, Luigi Pirelli <luipir at gmail.com> wrote:
> Hi
>
> I've a problem rendering WMS usign "simple rendering" as in:
> http://docs.qgis.org/2.2/en/docs/pyqgis_developer_cookbook/composer.html#simple-rendering
>
> I noticed that WMS calls during rendering add an uncorrect dpi
> resolution parameter set to 0
> and this value is set by this call:
> https://github.com/qgis/QGIS/blob/master/src/core/raster/qgsrasterlayerrenderer.cpp#L158
>
> commenting that line rendering is correct, but in this moment I don't
> know If this call is wrong or I'm wrong forgetting to set something in
> the renderContext.
>
> my code is here:
> https://github.com/faunalia/rt_omero/blob/2.0/SchedaEdificio.py#L315
>
> dpi value is set correctly here:
> https://github.com/faunalia/rt_omero/blob/2.0/SchedaEdificio.py#L326
>
> but its' value is overridden with 0 during rendering all the layers.
>
> Please help me to understand if it's a bug or my fault
>
> Thank you, Luigi Pirelli (luigi.pirelli at faunalia.it - luipir at gmail.com)
>
> NOTE:
> render is ok using saveAsImage method in mapCanvas as in:
> https://github.com/faunalia/rt_omero/blob/2.0/SchedaEdificio.py#L227
>
> p.s I added Martin Dobias in cc because is the author of:
> https://github.com/qgis/QGIS/blob/master/src/core/raster/qgsrasterlayerrenderer.cpp#L158
More information about the Qgis-developer
mailing list