Add select_cell method

This commit is contained in:
Alireza Adli 2024-08-16 09:58:22 -04:00
parent 47837f073a
commit b009a33bf3

View File

@ -27,19 +27,21 @@ class ScrubLayer:
self.layer = self.load_layer() self.layer = self.load_layer()
self.data_count = self.layer.featureCount() self.data_count = self.layer.featureCount()
def cell_value(self, fid, field_name): def get_cell(self, fid, field_name):
return self.layer.getFeature(fid)[field_name] return self.layer.getFeature(fid)[field_name]
def cell_field_fields( def select_cell(
self, self,
field_name, field_name_value, field_field_value, field_name, field_value, required_field,
return_one_value=False): return_one_value=False):
expression = QgsExpression(f'{field_name} = {field_name_value}') """Returns the value of a field
based on the value of another field in the same record"""
expression = QgsExpression(f'{field_name} = {field_value}')
request = QgsFeatureRequest(expression) request = QgsFeatureRequest(expression)
features = self.layer.getFeatures(request) features = self.layer.getFeatures(request)
field_field_values = [] field_field_values = []
for feature in features: for feature in features:
field_field_values.append(feature[field_field_value]) field_field_values.append(feature[required_field])
if return_one_value and field_field_values: if return_one_value and field_field_values:
return field_field_values[0] return field_field_values[0]
return field_field_values return field_field_values