[Qgis-developer] Attribute data update of a shape file
maaza mekuria
sailmcm at yahoo.com
Fri Apr 29 10:56:35 EDT 2011
Dear QGIS Gurus:
I have a written a plugin that updates an attribute of a shape file and it tells me it ran fine and yet, I am not able to see the changes in the attribute table once the program finishes. I am using QGIS 1.6 Copiapo on Windows). I am compiling using the 1.7 source, but I have tried using the trunk version and it does not seem to matter at all.
I can see the edit starting with all the extent selected and it finishes without an error. I also write a log file before and after the feature attribute change and the feature values change correctly.
What am i doing wrong?
The simplified code is posted below,
QgsVectorDataProvider* vProvider = theVectorLayer->dataProvider();
theVectorLayer->select(vProvider->attributeIndexes(),
theVectorLayer->extent(), true, false);
QgsFeature currentFeature;
QgsGeometry* currentGeometry = 0;
bool blnEdit = theVectorLayer->startEditing();
QgsAttributeList attrList = vProvider->attributeIndexes();
vProvider->select(attrList);
blnFeat = vProvider->nextFeature(currentFeature);
QgsAttributeMap atMap1;
vProvider->createSpatialIndex();
QgsAttributeList attrList = vProvider->attributeIndexes();
vProvider->select(attrList);
blnFeat = vProvider->nextFeature(currentFeature);
QgsAttributeMap atMap1;
QString featureAttributesString;
int ltsVal = 10;
int ltsFldIdx = 1;
QVariant fld0 ;
while(blnFeat)
{
atMap1 = currentFeature.attributeMap();
fld0 = atMap1.value(0);
currentGeometry = currentFeature.geometry();
if(!currentGeometry)
{
continue;
}
else
{
currentFeature.changeAttribute(ltsFldIdx,QVariant(ltsVal));
}
blnFeat = vProvider->nextFeature(currentFeature);
}
blnAttrAdded = theVectorLayer->commitChanges();
theVectorLayer->endEditCommand();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20110429/0d7c5dbb/attachment.html
More information about the Qgis-developer
mailing list