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

gene martin.laloux at gmail.com
Sat Apr 30 12:31:41 PDT 2011


I forgot, i use QGIS 1.7 r15814 from Kingchaos (Mac OS X)

using only the first line (without the for...), id = 1, test="a", x= 235.0,
y = 424.0

>>> vl = QgsVectorLayer("Point", "test", "memory")
>>> pr = vl.dataProvider()
>>> pr.addAttributes( { "id" : "string" } )
True
>>> pr.addAttributes( { "test" : "string" } )
True
>>> tt= QgsFeature()
>>> tt.setGeometry(QgsGeometry.fromPoint(QgsPoint(235.0, 424.0)))
>>> tt.setAttributeMap( { 0 : QVariant("id"), 1 : QVariant("a")} )
>>> pr.addFeatures( [ tt ] )
(True, [<qgis.core.QgsFeature object at 0x12c0bacb0>])
>>> vl.updateExtents()
>>> vl.commitChanges()
False
>>> QgsMapLayerRegistry.instance().addMapLayer(vl)
<qgis.core.QgsVectorLayer object at 0x12c0bac20>

and the point is plotted but the atrribute table remain empty (the False ? )

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



More information about the Qgis-user mailing list