Wednesday 28 November 2018

qgis - pyqgis add a picture


I am looking for a way to add a picture to my map using pyqgis. Are there any examples of how to do this. I know it can be done using the classQgsComposerPicture. I am not much of a programmer so I cannot decode the api documentation. Any links where I can find such examples or documentation with options.



Answer



If I want to add an icon QGIS logo (111 pixels x 111 pixels) to my composer map, the snipped code that it works is:


.
.
.


#Initialize the picture object
logo = QgsComposerPicture(c) #c is a QgsComposition object
logo.setPictureFile("/home/zeito/pyqgis_data/qgis-icon_21.png")
logo.setSceneRect(QRectF(0,0,40,40)) #Resize logo
logo. setItemPosition(20,20)
c.addItem(logo)
.
.
.


The result is:


enter image description here


With this QRectF(0,0,20,20) object I have:


enter image description here


I have to use the 'setSceneRect' method of QgsComposerPicture class.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...