<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>