<div dir="ltr"><div dir="ltr">I am trying to learn and work with PyQGIS 3.<br><br>It is a very challenging task cause documentation is really [limited and out of date][1].<br><br>What I am trying to do is to:<br><br>Â 1. create a project<br>Â 2. add a layer<br>Â 3. save the project<br>Â 4. export it as a png<br><br>I have done the first 3 steps (see code below).<br><br>Â Â Â import sys<br>Â Â Â import qgis<br>Â Â Â from qgis.core import QgsVectorLayer<br>Â Â Â from qgis.core import QgsApplication<br>Â Â Â from qgis.core import QgsProject<br>Â Â Â from qgis.core import QgsMapRendererJob, QgsMapSettings<br>Â Â Â from qgis.gui import QgsMapCanvas<br>Â Â Â from PyQt5.QtGui import QImage, QColor, QPainter<br>Â Â Â from PyQt5.QtCore import QSize<br>Â Â Â <br>Â Â Â # PYTHON APPLICATIONS<br>Â Â Â <br>Â Â Â # prefix path: the location where qgis is installed in the system<br>Â Â Â # the easiest way to find the prefix path to run the following commaand from the python console of qgis: QgsApplication.prefixPath()<br>Â Â Â <br>Â Â Â #1. CREATE THE APPLICATION<br>Â Â Â QgsApplication.setPrefixPath('/usr', True)<br>Â Â Â # second parameter into false disables the gui<br>Â Â Â qgs = QgsApplication([], False)<br>Â Â Â #load providers<br>Â Â Â qgs.initQgis()<br>Â Â Â <br>Â Â Â #2. CREATE THE PROJECT<br>Â Â Â # create project<br>Â Â Â project_name = '/home/dkar/workspaces/qgis/data/test_project_2.qgz'<br>Â Â Â project = QgsProject.instance()<br>Â Â Â new_project = project.write(project_name)<br>Â Â Â <br>Â Â Â #3. READ/OPEN THE PROJECT<br>Â Â Â # modify the project e.g. adding more layers and save it.<br>Â Â Â new_project = project.read(project.fileName())<br>Â Â Â <br>Â Â Â <br>Â Â Â #4. ADD A VECTORLAYER<br>Â Â Â # add a layer in the QgsProviderRegistry<br>Â Â Â layer=QgsVectorLayer("/home/dkar/workspaces/qgis/data/pakistan_1.shp", "pakistan", "ogr")<br>Â Â Â <br>Â Â Â if not layer.isValid():<br>Â Â Â Â Â Â Â print("Layer failed")<br>Â Â Â <br>Â Â Â #5. ADD LAYER TO THE REGISTRY<br>Â Â Â project.addMapLayer(layer, True)<br>Â Â Â project.write('/home/dkar/workspaces/qgis/data/test_project_2.qgz')<br>Â Â Â <br>Â Â Â #6. SAVE THE PROJECT<br>Â Â Â all_layers = QgsProject.instance().mapLayers()<br>Â Â Â <br><br>Â Â Â img = QImage(QSize (800, 600), QImage.Format_ARGB32_Premultiplied)<br>Â Â Â # set image's backgroud color<br>Â Â Â color = QColor(255, 255, 255)<br>Â Â Â img.fill(color.rgb())<br>Â Â Â <br>Â Â Â #create painter<br>Â Â Â p = QPainter()<br>Â Â Â p.begin(img)<br>Â Â Â p.setRenderHint(QPainter.Antialiasing)<br><br>Â Â Â # THIS IS WHERE THE ISSUE APPEARS<br>Â Â Â # THIS IS WHERE THE ISSUE APPEARS<br>Â Â Â render = QgsMapRendererJob() # THIS IS WHERE THE ISSUE APPEARS<br>Â Â Â <br>Â Â Â # set layer set (am I using here the prohect?)<br>Â Â Â lst = [<a href="http://layer.id">layer.id</a>()] # cause "layer" is the name of the variable<br>Â Â Â render.setLayerSet(lst)<br>Â Â Â <br>Â Â Â # to remove the provider and layer registries from memory<br>Â Â Â qgs.exitQgis()<br><br><br><br>But when I try to do the last part, following the instructions from the existing documentation. I get issues because the specific function (`QgsMapRenderer`) doesn't exist anymore in QGIS 3.<br><br>I am not sure how to solve the issue.<br><br>I see in the documentation that this function: <br><br>Â Â Â QgsMapRenderer<br><br>was replaced by<br><br>Â Â Â QgsMapRendererJob<br><br>But then when I try to import and use it in the code as:<br><br>Â Â Â from qgis.core import QgsMapRendererJob, QgsMapSettings<br>Â Â Â Â Â Â Â render = QgsMapRendererJob()<br><br>I get an error message:<br><br>Â Â Â TypeError: qgis._core.QgsMapRendererJob represents a C++ abstract class and cannot be instantiated<br><br>Any idea how to proceed with this?<br><br>Â [1]: <a href="https://docs.qgis.org/testing/pdf/en/QGIS-testing-PyQGISDeveloperCookbook-en.pdf">https://docs.qgis.org/testing/pdf/en/QGIS-testing-PyQGISDeveloperCookbook-en.pdf</a><br class="gmail-Apple-interchange-newline"></div></div>