[Qgis-developer] Feature count don't increase

Carson Farmer carson.farmer at gmail.com
Tue Oct 7 11:06:54 EDT 2008


Alexander,
> >From http://spatialserver.net:3001/ I download qgsAzimuth.zip archieve with plugin and test it: create new feature and try to zoom to full extent of the layer. New feature appears on map and in attribute table, but feature count don't increase too.
> Сan it is related to that addition takes place through "qgsDataProvider" not throught "QgsVectorLayer"? 
Possibly:

Looking back at some code of my own, I see that I have used 
vlayer.updateExtents() after using provider.addFeatures([feature_list]). 
This was for use with a vector layer based on the memory provider, but 
since it is also a QgsVector layer, it may be the same?

Although, based on the test below, this appears to be 'fixed'/not 
nessesasry in QGS 1.0.0:
 >>> mc = iface.mapCanvas()
 >>> layer = mc.getZpos(0) # Grabs the first map layer in the TOC
 >>> layer.featureCount()
88
 >>> provider = layer.dataProvider()
 >>> provider.name() # just a quick check to make sure we have a valid 
provider
ogr
 >>> fet = QgsFeature()
 >>> provider.getNextFeature(fet)
True
 >>> geom = QgsGeometry(fet.geometry()) # use this to create a valid 
QgsGeometry
 >>> feat = QgsFeature()
 >>> feat.setGeometry(geom)
 >>> provider.addFeatures([feat]) # add the feature with the 
're'-created geometry
(True, [<qgis.core.QgsFeature object at 0x98037ec>])
 >>> layer.featureCount()
89

Let me know how you get on,

Carson


More information about the Qgis-developer mailing list