More

PyQGIS export return blank .tif

PyQGIS export return blank .tif


I'm new to pyqgis and trying to bring up from the previous post with a little progress from the last (implemented debugging tool pdb) but now trying to export into a .tif file so that I can check on the vertices from the csv geometry. Unfortunately I get stuck with an blank render .tif image. The render.tif filesize is showing 1.9mb, when I download and view locally, the image only has the background with white colour and no vertices.

At the same time, I checked my csv file and also looping through the features of the layer after export the csv files. They are all good…

How can I have all the features from the vector layer to be shown on the .tif image file? Anyone please help? :/

PS: I'm on ubuntu server and using PyQGIS.

Tried withrender.fullExtent()andrender.extent(), both return blank image.tif

Inserted sample of elevp.csv

My code:-

#!/usr/bin/python import sys import qgis import PyQt4 from qgis.core import * from qgis.utils import * from qgis.gui import * from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtXml import * import pdb qgis_prefix="/usr" QgsApplication.setPrefixPath(qgis_prefix, True) QgsApplication.initQgis() app = QgsApplication([], False) uri = "/home/ubuntu/pyqgis/elevp.csv?crs=%s&delimiter=%s&xField=%s&yField=%s&elevField=%s" % ("EPSG:4326",";","x","y","elev") vlayer = QgsVectorLayer(uri, "test", "delimitedtext") QgsMapLayerRegistry.instance().addMapLayer(vlayer) # create image img = QImage(QSize(800, 600), QImage.Format_ARGB32_Premultiplied) # set image's background color color = QColor(255, 255, 255) img.fill(color.rgb()) # create painter p = QPainter() p.begin(img) p.setRenderHint(QPainter.Antialiasing) render = QgsMapRenderer() # set layer set lst = [vlayer.id()] print(lst) render.setLayerSet(lst) # set extent rect = QgsRectangle(render.fullExtent()) rect.scale(1.1) render.setExtent(rect) # set output size render.setOutputSize(img.size(), img.logicalDpiX()) # do the rendering render.render(p) p.end() # save image img.save("/home/ubuntu/pyqgis/render.tif","tif")

Sample elevp.csv:-

x;y;elev 120;960;13 360;40;52 640;840;3

Watch the video: QGIS Python PyQGIS - Create a Custom Processing Script for QGIS in the Processing Toolbox