[Qgis-developer] Adding features to empty layer
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Thu Mar 26 04:00:54 EDT 2009
[oops, meant to Reply to the list but didn't! Sorry if you get this twice!]
2009/3/26 Голубев Анатолий <golubev at nordcomp.ru>:
> Hi, list! Can someone write a simple example or algorithm to
> programmatically add features to empty vector layer?
Python or C++?
Here's some python code from one of my plugins:
http://code.google.com/p/bsrplugins/source/browse/trunk/topocolour/adjlayer.py
The 'make' function creates a new vector layer called 'vl' using the
'memory' provider. The layer has 'LineString' features (line 8). Each
feature has three attributes (lines 11-13).
Then a loop adds some features using information from the 'ig' object
passed in.
* construct a QgsGeometry object from some QPoint() objects
(QgsgeometryFromPolyline)
* set the geometry of the feature (fet.setGeometry) and add the
attributes (fet.setAttributes).
* add the feature to the layer provider (pr.addFeatures).
Once that's done you may want to add the layer to the Qgis map registry.
Translating this to C++ should be fairly simple. Hope this helps.
Barry
More information about the Qgis-developer
mailing list