Has the addFeatures function moved between QgsVectorLayer and QgsVectorDataProvider?
Do both work? Is one deprecated. The apis do not provide that info. Nor does a google search.
Which is preferred and why?
What am I misunderstanding here? What is the situation that is changing which means I may need to change this?
Answer
@MatthiasKuhn, one of the core developers of QGIS, has mentioned on his website OPENGIS.ch to avoid using dataProvider()
when adding features and instead do it directly on the layer (i.e. layer.addFeature(...)
). He lists various reasons to avoid using the data provider:
- You cannot undo them easily.
- They generate one request per call what may reduce performance.
- They do not emit internal signals for map redraws and other refreshes of the user interface.
- They do not take uncommitted changes into account so the python changes will get overwritten by the user when he commits the layer changes.
You could also ask on the QGIS Mailing List where you could get a more explicit reason.
No comments:
Post a Comment