mirror of
https://github.com/qgis/QGIS.git
synced 2025-06-19 00:02:48 -04:00
Fix inefficient calls to QgsFeature.attributes()[idx]
Replace with just f[idx]. Calling QgsFeature.attributes() allocates a list of all attributes, which is inefficient when only a single attribute value is needed.
This commit is contained in:
parent
6c99cbc1ba
commit
85efc77bb4
@ -162,15 +162,15 @@ class MinimumBoundingGeometry(QgisAlgorithm):
|
||||
|
||||
if type == 0:
|
||||
# bounding boxes - calculate on the fly for efficiency
|
||||
if not f.attributes()[field_index] in bounds_dict:
|
||||
bounds_dict[f.attributes()[field_index]] = f.geometry().boundingBox()
|
||||
if not f[field_index] in bounds_dict:
|
||||
bounds_dict[f[field_index]] = f.geometry().boundingBox()
|
||||
else:
|
||||
bounds_dict[f.attributes()[field_index]].combineExtentWith(f.geometry().boundingBox())
|
||||
bounds_dict[f[field_index]].combineExtentWith(f.geometry().boundingBox())
|
||||
else:
|
||||
if not f.attributes()[field_index] in geometry_dict:
|
||||
geometry_dict[f.attributes()[field_index]] = [f.geometry()]
|
||||
if not f[field_index] in geometry_dict:
|
||||
geometry_dict[f[field_index]] = [f.geometry()]
|
||||
else:
|
||||
geometry_dict[f.attributes()[field_index]].append(f.geometry())
|
||||
geometry_dict[f[field_index]].append(f.geometry())
|
||||
|
||||
feedback.setProgress(int(current * total))
|
||||
|
||||
|
@ -187,7 +187,7 @@ class PointDistance(QgisAlgorithm):
|
||||
break
|
||||
|
||||
inGeom = inFeat.geometry()
|
||||
inID = str(inFeat.attributes()[inIdx])
|
||||
inID = str(inFeat[inIdx])
|
||||
featList = index.nearestNeighbor(inGeom.asPoint(), nPoints)
|
||||
distList = []
|
||||
vari = 0.0
|
||||
@ -199,7 +199,7 @@ class PointDistance(QgisAlgorithm):
|
||||
if same_source_and_target and inFeat.id() == outFeat.id():
|
||||
continue
|
||||
|
||||
outID = outFeat.attributes()[outIdx]
|
||||
outID = outFeat[outIdx]
|
||||
outGeom = outFeat.geometry()
|
||||
dist = distArea.measureLine(inGeom.asPoint(),
|
||||
outGeom.asPoint())
|
||||
|
@ -155,14 +155,14 @@ class PointsInPolygon(QgisAlgorithm):
|
||||
|
||||
if engine.contains(point_feature.geometry().constGet()):
|
||||
if weight_field_index >= 0:
|
||||
weight = point_feature.attributes()[weight_field_index]
|
||||
weight = point_feature[weight_field_index]
|
||||
try:
|
||||
count += float(weight)
|
||||
except:
|
||||
# Ignore fields with non-numeric values
|
||||
pass
|
||||
elif class_field_index >= 0:
|
||||
point_class = point_feature.attributes()[class_field_index]
|
||||
point_class = point_feature[class_field_index]
|
||||
if point_class not in classes:
|
||||
classes.add(point_class)
|
||||
else:
|
||||
|
@ -129,7 +129,7 @@ class RandomSelectionWithinSubsets(QgisAlgorithm):
|
||||
if feedback.isCanceled():
|
||||
break
|
||||
|
||||
classes[feature.attributes()[index]].append(feature.id())
|
||||
classes[feature[index]].append(feature.id())
|
||||
feedback.setProgress(int(i * total))
|
||||
|
||||
selran = []
|
||||
|
@ -234,7 +234,7 @@ class SpatialJoin(QgisAlgorithm):
|
||||
|
||||
join_attributes = []
|
||||
for a in join_field_indexes:
|
||||
join_attributes.append(f.attributes()[a])
|
||||
join_attributes.append(f[a])
|
||||
|
||||
if engine is None:
|
||||
engine = QgsGeometry.createGeometryEngine(f.geometry().constGet())
|
||||
|
@ -306,7 +306,7 @@ class SpatialJoinSummary(QgisAlgorithm):
|
||||
|
||||
join_attributes = []
|
||||
for a in join_field_indexes:
|
||||
join_attributes.append(test_feat.attributes()[a])
|
||||
join_attributes.append(test_feat[a])
|
||||
|
||||
if engine is None:
|
||||
engine = QgsGeometry.createGeometryEngine(f.geometry().constGet())
|
||||
|
@ -76,7 +76,7 @@ def values(source, *attributes):
|
||||
|
||||
# convert attribute value to number
|
||||
try:
|
||||
v = float(feature.attributes()[i])
|
||||
v = float(feature[i])
|
||||
except:
|
||||
v = None
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user