[Qgis-developer] Troubles with features (QgsVectorLayer)

hubbatov hubbatov at mail.ru
Tue Nov 5 00:08:41 PST 2013


Thanks for answer. But...

QgsFeatureIds ids1;
for(int i = 0; i < 5; i++){
	layer1->startEditing();

	QgsFeature f;
	f.setGeometry(QgsGeometry::fromRect(QgsRectangle(i * 10, i * 10, (i + 1) *
10, (i + 1) * 10)));
	f.setValid(true);
	layer1->addFeature(f);
	layer1->commitChanges();

	ids1 << f.id();
}

Ids are stil negative. But if i get feature iterator after commit changes
and go to last feature - id is correct.
Like this

QgsFeature feat;
QgsFeatureIterator it = layer1->getFeatures();
while(it.nextFeature(feat)){
}
ids << feat.id();

But it is not comfortable...
Any other ways to get correct feature id after adding feature?



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Troubles-with-features-QgsVectorLayer-tp5087389p5087392.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.


More information about the Qgis-developer mailing list