[Qgis-developer] problem with wms legend in standalone application
Diane Peyrot
peyrotdiane at gmail.com
Wed Nov 4 05:48:52 PST 2015
Hi all,
I'm creating a standalone application (=viewer) in pyqgis with some
essentials tools like zoom, plot rasters and vectors, wms displaying and
map renderer.
When I want to create a map renderer with the componer and save it as a
.png, all the layers with the legend are visible but not the legend of the
wms layer.. And I really don't know why.
I've got another problem: I want to set the font of the composer legend
into transparency but the command doesn't work at all:
legend.setFontColor(QColor(255,255,255,0)). May be I miss something..
Is anybody has a solution, it would helps me a lot.
Thanks,
Diane
this is the snippet of my code which do the componer:
def actionComp(self):
#create composition with composer map
mapRenderer = iface.mapCanvas().mapRenderer()
myMap = QgsMapSettings()
mapRectangle = myMap.fullExtent()
myMap.setExtent(mapRectangle)
myMap.setOutputSize(QSize(1600,1200))
myComposition = QgsComposition(mapRenderer)
myComposition.setPlotStyle(QgsComposition.Print)
x,y = 0,0
w,h = myComposition.paperWidth(), myComposition.paperHeight()
composerMap = QgsComposerMap(myComposition,x,y,w,h)
composerMap.gridEnabled()
myComposition.addComposerMap(composerMap)
composerMap.setLayerSet(myMap.layers()
myComposition.addItem(composerMap)
#legend
legend = QgsComposerLegend(myComposition)
myComposition.addItem(legend)
legend.setItemPosition (0,10)
#legend.setFontColor(QColor(255,255,255,0))
legend.setScale(.3)
legend.model().setLayerSet(mapRenderer.layerSet())
# Scale bar
item = QgsComposerScaleBar(myComposition)
myComposition.addComposerScaleBar(item)
item.setStyle('Numeric')
item.setItemPosition(0,100)
item.update()
item.setComposerMap(composerMap)
myComposition.addItem(item)
output_png = "/Users/test.png"
myImage = myComposition.printPageAsRaster(0)
myImage.save(output_png)
composerLabel.setItemPosition(20, 10)
composerLabel.setItemPosition(100, 10, 100, 30)
dpi = myComposition.printResolution()
dpmm = dpi /600
width = int(dpmm * myComposition.paperWidth())
height = int(dpmm * myComposition.paperHeight())
myComposition.setPaperSize(width, height)
myComposition.setPrintResolution(dpi)
# create output image and initialize it
image = QImage(QSize(width, height), QImage.Format_ARGB32)
image.setDotsPerMeterX(dpmm * 1000)
image.setDotsPerMeterY(dpmm * 1000)
image.fill(0)
#render the composition
imagePainter = QPainter(image)
sourceArea = QRectF(0, 0, myComposition.paperWidth(),
myComposition.paperHeight())
targetArea = QRectF(0, 0, width, height)
myComposition.render(imagePainter, targetArea, sourceArea)
imagePainter.end()
image.save("/Users/test.png")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20151104/dba50e1f/attachment.html>
More information about the Qgis-developer
mailing list