[Qgis-developer] patch for split feature issue

Adrien Gruson agruson at archivideo.com
Thu Jun 5 05:41:41 EDT 2008


Hi all,
i was post 2 week ago a bug in the trac 
(http://trac.osgeo.org/qgis/ticket/1103) because some case the copy of 
attributs have some issues.
The problem was in QgsVectorLayer::featuresInRectangle :
The problem is in this code
|for(changedIt = mChangedGeometries.begin(); changedIt != 
mChangedGeometries.end(); ++changedIt)
{
[...]
 if(fetchAttributes)
 {
    QgsFeature tmpFeature;
    mDataProvider->getFeatureAtId(changedIt.key(), tmpFeature, false, 
mDataProvider->allAttributesList());
    newFeature.setAttributeMap(tmpFeature.attributeMap());
  }
  features.push_back(newFeature);
}}
|
Because if the feature is in mAddedFeature the function |getFeatureAtId 
|Return no attribut (because the feature isn't commited).||
||
Regards,

Adrien Gruson.

_
Patch :_

Index: /raid/homes/agruson/workspace/SVN_Src_Qgis/core/qgsvectorlayer.cpp
===================================================================
--- 
/raid/homes/agruson/workspace/SVN_Src_Qgis/core/qgsvectorlayer.cpp    
(revision 8593)
+++ 
/raid/homes/agruson/workspace/SVN_Src_Qgis/core/qgsvectorlayer.cpp    
(working copy)
@@ -1273,10 +1273,30 @@
         }
       if(fetchAttributes)
         {
-          QgsFeature tmpFeature;
-          mDataProvider->getFeatureAtId(changedIt.key(), tmpFeature, 
false, mDataProvider->allAttributesList());
-          newFeature.setAttributeMap(tmpFeature.attributeMap());
-         
+          if(changedIt.key()<0)
+          {
+              //The feature is in mAddedFeature's list because its id<0
+              bool findMyFeature = false;
+              for (QgsFeatureList::iterator iter = 
mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter)
+              {
+                if(iter->featureId()==changedIt.key())
+                {
+                  findMyFeature = true;
+                  newFeature.setAttributeMap(iter->attributeMap());
+                  break;
+                }
+              }
+              if(!findMyFeature)
+              {
+                QgsLogger::warning("No attribute for the feature");
+              }
+          }
+          else
+          {
+              QgsFeature tmpFeature;
+              mDataProvider->getFeatureAtId(changedIt.key(), 
tmpFeature, false, mDataProvider->allAttributesList());
+              newFeature.setAttributeMap(tmpFeature.attributeMap()); 
+          }
         }
       features.push_back(newFeature);
     }



More information about the Qgis-developer mailing list