@@ -93,11 +93,11 @@ def processAlgorithm(self, parameters, context, feedback):
93
93
layer = self .parameterAsVectorLayer (parameters , self .INPUT , context )
94
94
method = self .parameterAsEnum (parameters , self .METHOD , context )
95
95
96
- featureCount = layer .featureCount ()
96
+ ids = layer .allFeatureIds ()
97
97
value = self .parameterAsInt (parameters , self .NUMBER , context )
98
98
99
99
if method == 0 :
100
- if value > featureCount :
100
+ if value > len ( ids ) :
101
101
raise QgsProcessingException (
102
102
self .tr ('Selected number is greater than feature count. '
103
103
'Choose a lower value and try again.' ))
@@ -106,9 +106,9 @@ def processAlgorithm(self, parameters, context, feedback):
106
106
raise QgsProcessingException (
107
107
self .tr ("Percentage can't be greater than 100. Set a "
108
108
"different value and try again." ))
109
- value = int (round (value / 100.0 , 4 ) * featureCount )
109
+ value = int (round (value / 100.0 , 4 ) * len ( ids ) )
110
110
111
- selran = random .sample (list ( range ( featureCount )) , value )
111
+ selran = random .sample (ids , value )
112
112
113
113
layer .selectByIds (selran )
114
114
return {self .OUTPUT : parameters [self .INPUT ]}
0 commit comments