Skip to content
Permalink
Browse files
Fix for smarter attribute insertion in QgsOgrProvider::addFeature. Th…
…is is e.g. usefull for copying/pasting features

git-svn-id: http://svn.osgeo.org/qgis/trunk@5719 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Aug 21, 2006
1 parent 379e1d1 commit c2e86b32211848f525b53846cdab5696580fda0a
Showing with 15 additions and 9 deletions.
  1. +15 −9 src/providers/ogr/qgsogrprovider.cpp
@@ -1027,26 +1027,32 @@ bool QgsOgrProvider::addFeature(QgsFeature* f)
}
}

//todo: choose i such that it doesn't get larger than fdef->GetFieldCount()
//todo: only add the attribute if it has the same name as fdef->GetFieldDefn(i)->GetNameRef()

//add possible attribute information
for(int i=0;i<f->attributeMap().size();++i)
{
QString s=(f->attributeMap())[i].fieldValue();

//find a matching field for the new attribute
QString newAttribute = (f->attributeMap())[i].fieldName();
int targetAttributeId = fdef->GetFieldIndex(newAttribute);
if(targetAttributeId == -1)
{
continue;
}

if(!s.isEmpty())
{
if(fdef->GetFieldDefn(i)->GetType()==OFTInteger)
if(fdef->GetFieldDefn(targetAttributeId)->GetType()==OFTInteger)
{
feature->SetField(i,s.toInt());
feature->SetField(targetAttributeId,s.toInt());
}
else if(fdef->GetFieldDefn(i)->GetType()==OFTReal)
else if(fdef->GetFieldDefn(targetAttributeId)->GetType()==OFTReal)
{
feature->SetField(i,s.toDouble());
feature->SetField(targetAttributeId,s.toDouble());
}
else if(fdef->GetFieldDefn(i)->GetType()==OFTString)
else if(fdef->GetFieldDefn(targetAttributeId)->GetType()==OFTString)
{
feature->SetField(i,s.ascii());
feature->SetField(targetAttributeId,s.ascii());
}
else
{

0 comments on commit c2e86b3

Please sign in to comment.