Skip to content

Commit

Permalink
Fix for smarter attribute insertion in QgsOgrProvider::addFeature. Th…
Browse files Browse the repository at this point in the history
…is is e.g. usefull for copying/pasting features

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5719 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Aug 21, 2006
1 parent d4626da commit 42dcd4a
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -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
{
Expand Down

0 comments on commit 42dcd4a

Please sign in to comment.