[Qgis-developer] Labeling in vector layer (development on Qt)

hubbatov hubbatov at mail.ru
Sun Feb 16 23:36:00 PST 2014


Solved, but this way is not good, i think :)

layer->startEditing();
QList<QgsField> fields;
fields.append(QgsField("XCoordinate", QVariant::Double));
layer->addAttribute(QgsField("XCoordinate", QVariant::Double));
fields.append(QgsField("YCoordinate", QVariant::Double));
layer->addAttribute(QgsField("YCoordinate", QVariant::Double));

layer->dataProvider()->addAttributes(fields);
layer->commitChanges();

QgsFeature feat;
QgsFeatureIterator fit = layer->getFeatures();
while(fit.nextFeature(feat)){
	QgsGeometry *geom = feat.geometry();
	if(geom){
		QgsPoint center = geom->boundingBox().center();
		QgsAttributeMap chmap;
		chmap[layer->fieldNameIndex("XCoordinate")] = center.x();
		chmap[layer->fieldNameIndex("YCoordinate")] = center.y();

		QgsChangedAttributesMap map;
		map.insert(feat.id(), chmap);

		layer->dataProvider()->changeAttributeValues(map);
	}
}



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Labeling-in-vector-layer-development-on-Qt-tp5103733p5104147.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.


More information about the Qgis-developer mailing list