"The explosive growth of the GeoWeb and geographic information has made GIS powerful media for the general public to communicate, but perhaps more importantly, GIS have also become media for constructive dialogs and interactions about social issues." - Sui & Goodchild
Objectif : comprendre le “portrayal model” portrayalogc.png par l'utilisation du moteur de rendu cartographique de QGIS3 avec sa console Python et les classes QgsMapRendererSequentialJob et QgsMapSettings.
Pour les utilisateur de QGIS2, voici le tutoriel QgsMapRenderer 2015.
# we work with the selected layer layer = iface.activeLayer() # we want to know the current map settings canvas = iface.mapCanvas() mapset = canvas.mapSettings() # we display the mandatory settings to build a map print(mapset.layerIds()) print(mapset.extent().asWktPolygon()) print(mapset.outputSize())
# set layer(s) mapset.setLayers([layer]) # set extent mapset.setExtent(QgsRectangle(530000,180000,550000,200000)) # close to Yverdon # set output size mapset.setOutputSize(QSize(800,800)) # even more, set background color mapset.setBackgroundColor(QColor(0,0,0,0)) job = QgsMapRendererSequentialJob(mapset) job.start() job.waitForFinished() img = job.renderedImage() img.save('/home/olivier/tmp/render.png', 'png') # adapt the path properly