[Qgis-developer] Feature count don't increase

Alexander Bruy voltron at ua.fm
Mon Oct 6 10:18:02 EDT 2008


Hi, all!
After learning sources of some Python plugins I'm a bit understood with process of adding new features to the vector layer. Here is my code

lstFeatures = []
lstLayers = []
self.layermap = QgsMapLayerRegistry.instance().mapLayers()
for (name, layer) in self.layermap.iteritems():
	lstLayers.append(name)
vLayer = self.layermap[lstLayers[0]]
# for debug: show feature count before adding
#QMessageBox.information(self.iface.getMainWindow(), "Debug", str(vLayer.featureCount()))
provider = vLayer.getDataProvider()
provider.reset()
ft = QgsFeature()
geom = QgsGeometry.fromPloygon([lstCoord])
ft.setGeometry(geom)
lstFeatures.append(ft)
# commit changes
provider.addFeatures(lstFeatures)
self.iface.getMapCanvas.refresh()
# for debug: show feature count after adding
#QMessageBox.information(self.iface.getMainWindow(), "Debug", str(vLayer.featureCount()))

It's work fine for me - features appears on map and in attribute table. But exists two problems:
1. After adding, feature count don't changes. Why? I do something wrong or skip something?
2. After adding I want see all features (old and new), so it's nessesary update "overview" window and zoom to full extent of working layer. But
 
self.iface.getMapCanvas.updateOverview()
self.iface.getMapCanvas.updateFullExtent()

don't work. As far as i understood this is result of previous problem. If feature count has no changes, so extent also don't change. What i need to do for solve this problems?

Best regards,
 Alexander Bruy

voltron at ua.fm

-- реклама -----------------------------------------------------------
http://FREEhost.com.ua - доступный хостинг, домен в подарок



More information about the Qgis-developer mailing list