[Qgis-developer] Troubles with features (QgsVectorLayer)

Matthias Kuhn matthias.kuhn at gmx.ch
Tue Nov 5 00:16:00 PST 2013


It would probably work to use
   layer->dataProvider()->addFeatures( QgsFeatureList )
instead. If you directly work on the data provider and not on the 
layer's edit buffer, no temporary id will be generated.

Matthias

On Die 05 Nov 2013 09:08:41 CET, hubbatov wrote:
> 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.
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer




More information about the Qgis-developer mailing list