Unable to update some of the attributes using PyQGIS

المشرف العام

Administrator
طاقم الإدارة
I'm trying to create new attribute and populate it, but for unknown reason some of the features does not update while others are updated normally.

# scores - list of values which length is equal to the number of features in layer. score_att_name = 'F_SCORE' caps = self.layer.dataProvider().capabilities() if caps & QgsVectorDataProvider.AddAttributes: res = self.layer.dataProvider().addAttributes([QgsField(score_att_name, QVariant.Double)]) self.layer.updateFields() feats = self.layer.getFeatures() att_id = self.layer.fieldNameIndex(score_att_name) self.layer.startEditing() i = 0 for feat in feats: score = scores attrs = {att_id: score} fid = feat.id() self.layer.dataProvider().changeAttributeValues({ fid : attrs }) self.layer.updateFeature(feat) i += 1 self.layer.commitChanges() There are no NULL/None values in scores and number of items in it corresponds to the number of features in layer. It is expected either for all the features to get non-NULL values in the newly created attribute or get NULL for all of them (if there is an error in code).

Here is the scores content:

[-0.1924320401655787, -0.3011441017990289, -0.16252774237448944, -0.30138576399544564, -0.30200044628243455, -0.2779783498269975, -0.2420625175170869, -0.295068402157225, -0.2976507832929624, -0.2140032879792433, -0.29832468774549037, -0.29723224511785584, -0.28129089378239636, -0.2894700697069985, -0.16974038814535744, -0.25809302976180065, -0.2988300443409982, 0.0917123519767264, -0.26583612088822345, 4.94647318248023, -0.29526096086609877, -0.21327671122718667, -0.2823017044646275, -0.2580216656881462, -0.23932206565124473, 0.1411220021301911, -0.2874893152592108, -0.3036300172774237, 3.692289329980737, -0.2726130899249829, -0.3021985904055799, -0.3030091219894229, 0.1411220021301911, -0.29398722839889163, -0.29541202867082983, -0.25634338249136523, -0.018893864443287018, -0.2935667830438211, 0.40979414662628333, -0.2945805319935501, -0.16338703660469128, -0.30414800204438525]

أكثر...
 
أعلى