I'm trying to plot one point "jumping" each second in the canvas (like a gps tracking). I need to take points from a .csv file.
This functionality is made in a QWidget of my application, so the code is the next:
class StartTrack(QWidget): def __init__(self, MapExplorer): QWidget.__init__(self) self.MapExplorer = MapExplorer # MapExplorer is my principal class def starting(self): # I call this method when push a button in the UI self.j = 0 self.addTarget() def addTarget(self): with open('C:\Users\Nacho\SkyLife\GIS4Ship\Archivos\Lex\data\Targets_com.csv') as f: self.j += 1 self.lector = csv.reader(f) for i in range(0,self.j): row = self.lector.next() x = row y = row # I have this on MapExplorer: # self.target_layer = QgsVectorLayer('Point?crs=EPSG:4326', 'points' , 'memory') # self.trackprovider = self.target_layer.dataProvider() # QgsMapLayerRegistry.instance().addMapLayer(self.target_layer) trackprovider = self.MapExplorer.trackprovider target = self.MapExplorer.target_layer features =  feature = QgsFeature() feature.setGeometry(QgsGeometry.fromWkt("POINT ("+x+" "+y+")")) features.append(feature) trackprovider.addFeatures(features) target.updateExtents() target.triggerRepaint() print(self.j, row) QTimer.singleShot(1000, self.addTarget) # Recursive call
My problem is that I can't "delete" the previous point at canvas. I really delete each feature in each iteration, because I'm redefining everything: trackprovider (QgsVectorLayer.dataProvider), target (QgsVectorLayer), features (list of feature), and feature (point).
I want to see only one point each iteration (like moving through canvas) instead of this:
I've already tried to delete feature from list and from layer too, but not results.
Am I missing something related to refreshing canvas, layer or provider?
# self.target_layer = QgsVectorLayer('Point?crs=EPSG:4326', 'points' , 'memory') # self.trackprovider = self.target_layer.dataProvider()