I'm new to pyqgis and trying to bring up from the previous post with a little progress from the last (implemented pdb) but now trying to export into a .tif file so that I can check on the vertices. Unfortunately I get stuck with an empty render .tif image. The render.tif filesize is showing 1.9mb, when I download and view locally, the image only has the background white colour and no vertices.
At the same time, I checked my csv file and also looping through the features 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?
PS: I'm on ubuntu server and using PyQGIS.
My code:-
#!/usr/bin/pythonimport sysimport qgisimport PyQt4from 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 imageimg = QImage(QSize(800, 600), QImage.Format_ARGB32_Premultiplied)# set image's background colorcolor = QColor(255, 255, 255)img.fill(color.rgb())# create painterp = QPainter()p.begin(img)p.setRenderHint(QPainter.Antialiasing)render = QgsMapRenderer()# set layer setlst = [vlayer.id()]print(lst)render.setLayerSet(lst)# set extentrect = QgsRectangle(render.fullExtent())rect.scale(1.1)render.setExtent(rect)# set output sizerender.setOutputSize(img.size(), img.logicalDpiX())# do the renderingrender.render(p)p.end()# save imageimg.save("/home/ubuntu/pyqgis/render.tif","tif")
أكثر...
At the same time, I checked my csv file and also looping through the features 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?
PS: I'm on ubuntu server and using PyQGIS.
My code:-
#!/usr/bin/pythonimport sysimport qgisimport PyQt4from 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 imageimg = QImage(QSize(800, 600), QImage.Format_ARGB32_Premultiplied)# set image's background colorcolor = QColor(255, 255, 255)img.fill(color.rgb())# create painterp = QPainter()p.begin(img)p.setRenderHint(QPainter.Antialiasing)render = QgsMapRenderer()# set layer setlst = [vlayer.id()]print(lst)render.setLayerSet(lst)# set extentrect = QgsRectangle(render.fullExtent())rect.scale(1.1)render.setExtent(rect)# set output sizerender.setOutputSize(img.size(), img.logicalDpiX())# do the renderingrender.render(p)p.end()# save imageimg.save("/home/ubuntu/pyqgis/render.tif","tif")
أكثر...