@@ -125,9 +125,6 @@ def processAlgorithm(self, parameters, context, feedback):
125
125
if sink is None :
126
126
raise QgsProcessingException (self .invalidSinkError (parameters , self .OUTPUT ))
127
127
128
- spatialIndex = QgsSpatialIndex (point_source .getFeatures (
129
- QgsFeatureRequest ().setSubsetOfAttributes ([]).setDestinationCrs (poly_source .sourceCrs (), context .transformContext ())), feedback )
130
-
131
128
point_attribute_indices = []
132
129
if weight_field_index >= 0 :
133
130
point_attribute_indices .append (weight_field_index )
@@ -150,28 +147,26 @@ def processAlgorithm(self, parameters, context, feedback):
150
147
count = 0
151
148
classes = set ()
152
149
153
- points = spatialIndex .intersects (geom .boundingBox ())
154
- if len (points ) > 0 :
155
- request = QgsFeatureRequest ().setFilterFids (points ).setDestinationCrs (poly_source .sourceCrs (), context .transformContext ())
156
- request .setSubsetOfAttributes (point_attribute_indices )
157
- for point_feature in point_source .getFeatures (request ):
158
- if feedback .isCanceled ():
159
- break
160
-
161
- if engine .contains (point_feature .geometry ().constGet ()):
162
- if weight_field_index >= 0 :
163
- weight = point_feature .attributes ()[weight_field_index ]
164
- try :
165
- count += float (weight )
166
- except :
167
- # Ignore fields with non-numeric values
168
- pass
169
- elif class_field_index >= 0 :
170
- point_class = point_feature .attributes ()[class_field_index ]
171
- if point_class not in classes :
172
- classes .add (point_class )
173
- else :
174
- count += 1
150
+ request = QgsFeatureRequest ().setFilterRect (geom .boundingBox ()).setDestinationCrs (poly_source .sourceCrs (), context .transformContext ())
151
+ request .setSubsetOfAttributes (point_attribute_indices )
152
+ for point_feature in point_source .getFeatures (request ):
153
+ if feedback .isCanceled ():
154
+ break
155
+
156
+ if engine .contains (point_feature .geometry ().constGet ()):
157
+ if weight_field_index >= 0 :
158
+ weight = point_feature .attributes ()[weight_field_index ]
159
+ try :
160
+ count += float (weight )
161
+ except :
162
+ # Ignore fields with non-numeric values
163
+ pass
164
+ elif class_field_index >= 0 :
165
+ point_class = point_feature .attributes ()[class_field_index ]
166
+ if point_class not in classes :
167
+ classes .add (point_class )
168
+ else :
169
+ count += 1
175
170
176
171
output_feature .setGeometry (geom )
177
172
0 commit comments