I am developing a plugin for QGIS and have hit a snag that does not seem to have happened before.
After having created a point memory layer with attributes, I need to delete features. The following code was used to delete same, however, after this operation, all features disappear from the mapcanvas. The features are displayed in the browser, with the exception of the deleted ones, and the layer is still shown as an existing layer in the layer legend.
Here's snippets of the code:
def createTmpLyr(self):
uri = "Point?crs=epsg:4248&field=id:integer&field=Pt:string(20)&index=yes"
self.vl = QgsVectorLayer(uri, "temporary_points", "memory")
QgsMapLayerRegistry.instance().addMapLayer(self.vl)
more code that adds point features successfully...
Code that generates a selection of points to be deleted
self.vl.setSelectedFeatures(listOfPts)
ntBndPts=self.vl.selectedFeatures()
self.delNtBndPts(ntBndPts)
self.vl.commitChanges()
def delNtBndPts(self, pts):
print pts
with edit(self.vl):
for feature in pts:
self.vl.deleteFeatures([feature.id()])
1 Answer 1
self.vl.setSelectedFeatures(listOfPts)
ntBndPts=self.vl.selectedFeatures()
self.delNtBndPts(ntBndPts)
def delNtBndPts(self, pts):
print pts
self.vl.startEditing()
for feature in pts:
self.vl.deleteFeatures([feature.id()])
self.vl.updateExtents()
self.vl.commitChanges()
iface.mapCanvas().refresh()
)? Or the layers (iface.mapCanvas().refreshAllLayers()
)?