[Qgis-user] PyQGIS: how to create a layer in the console ?

gene martin.laloux at gmail.com
Thu Apr 28 11:38:42 PDT 2011


Hello, I'm trying to directly import Excel files with the Python module xlrd
in the console:

    >>> from PyQt4.QtCore import *
    >>> import xlrd
    >>> wb = xlrd.open_workbook('testxy.xls')
    >>> sh = wb.sheet_by_index(0)
    >>> for rownum in range(sh.nrows):
    ...            print sh.row_values(rownum)
    ...
    [u'id', u'x', u'y', u'test']
    [1.0, 235.0, 424.0, u'a']
    [2.0, 245.0, 444.0, u'b']
    ....
 It gives the xy values and the attributes
So, I use the script "create layer" from 
http://www.qgis.org/wiki/Python_Bindings
http://www.qgis.org/wiki/Python_Bindings   with no problem  for adding the
layer and the points to the canvas except for the attribute table that
remains empty

The question is how to create a valid layer in the console?

Many thanks




--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/PyQGIS-how-to-create-a-layer-in-the-console-tp6314393p6314393.html
Sent from the qgis-user mailing list archive at Nabble.com.



More information about the Qgis-user mailing list