[Qgis-developer] delete feature

piko piklas at gmail.com
Fri Dec 12 07:02:38 EST 2008


hi devs

I need to create a vectorial layer with only one point feature in it, from
the x/y values of a click event
I use the 'memory' as suggested in tutorial

This is my code:

sprayerProvider = self.sprayerLayer.dataProvider()
sprayerProvider.addAttributes( { "name" : "string" } )

if self.sprayerLayer.featureCount() ==1:
   sprayerProvider.deleteFeatures([0])
   self.canvas.refresh()
			
add a feature
fet = QgsFeature()
fet.setGeometry(QgsGeometry.fromPoint(QgsPoint(p.x(),p.y())))
fet.setAttributeMap( { 0 : QVariant("sprayer")} )
sprayerProvider.addFeatures( [ fet ] )

self.sprayerLayer.updateExtents()
		
QgsMapLayerRegistry.instance().addMapLayer(self.sprayerLayer)


So the feature is created and the layer added,
but i want to delete and replace the feature each time the user click
i guess my deleteFeatures doesn't work, because each click creates a new
feature in the layer

Any ideas anyone ?

Thanks
-- 
View this message in context: http://n2.nabble.com/delete-feature-tp1647480p1647480.html
Sent from the qgis-developer mailing list archive at Nabble.com.



More information about the Qgis-developer mailing list