Failed load delimited layer in QGIS python console

المشرف العام

Administrator
طاقم الإدارة
I'm trying to follow the map rendering section from the pyqgis cookbook. I am able render shape file using qgs vector layer, however getting error prompt while loading delimited text file through qgs vector layer.


my script is(running in QGIS python console)

from qgis.core import *from qgis.gui import *from qgis.utils import *from PyQt4.QtCore import *from PyQt4.QtGui import *from PyQt4.QtXml import *mapinstance = QgsMapLayerRegistry.instance()mapinstance.removeAllMapLayers()layer = QgsVectorLayer("f:\scripts\map\wb.shp", "wb", "ogr")if layer.isValid(): print "shape layer successfully loaded - adding to map instance" mapinstance.addMapLayer(layer)else: print "shape layer failed to load!" uri = "f:/scripts/map/points.csv?delimiter=%s&xField=%s&yField=%s" % (",", "longitude", "latitude")vlayer=QgsVectorLayer(uri,"points","delimitedtext")if vlayer.isValid(): print "point layer successfully loaded - adding to map instance" mapinstance.addMapLayer(vlayer)else: print "point layer failed to load!"print mapinstance.mapLayers()# create imageimg = QImage(QSize(800,600), QImage.Format_ARGB32_Premultiplied)# set image 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 = [ layer.id() ] # add ID of every layerrender.setLayerSet(lst)# set extentrect = QgsRectangle(render.fullExtent())#rect.scale(1.39800703)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('f:\scripts\out.png',"png")and points.csv file contains following data

longitude,latitude

88.3697222,22.5697222

87.3194986,22.3243243



أكثر...
 
أعلى