Return a field value based on another field value
This commit is contained in:
parent
ccc7db8310
commit
fe03556e7c
@ -7,7 +7,8 @@ Project Developer: Alireza Adli alireza.adli@concordia.ca
|
||||
|
||||
from qgis.core import QgsApplication, QgsField, QgsProject, \
|
||||
QgsProcessingFeedback, QgsVectorLayer, QgsVectorDataProvider, \
|
||||
QgsExpressionContext, QgsExpressionContextUtils, edit, QgsFeatureRequest
|
||||
QgsExpressionContext, QgsExpressionContextUtils, edit, QgsFeatureRequest, \
|
||||
QgsExpression
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
from qgis.analysis import QgsNativeAlgorithms
|
||||
from basic_functions import *
|
||||
@ -26,9 +27,25 @@ class ScrubLayer:
|
||||
self.layer = self.load_layer()
|
||||
self.data_count = self.layer.featureCount()
|
||||
|
||||
def cell_content(self, fid, field_name):
|
||||
def cell_value(self, fid, field_name):
|
||||
return self.layer.getFeature(fid)[field_name]
|
||||
|
||||
def cell_field_field(self, field_name, field_name_value, field_field_value):
|
||||
expression = QgsExpression(f'{field_name} = {field_name_value}')
|
||||
request = QgsFeatureRequest(expression)
|
||||
features = self.layer.getFeatures(request)
|
||||
for feature in features:
|
||||
return feature[field_field_value]
|
||||
|
||||
def cell_field_fields(self, field_name, field_name_value, field_field_value):
|
||||
expression = QgsExpression(f'{field_name} = {field_name_value}')
|
||||
request = QgsFeatureRequest(expression)
|
||||
features = self.layer.getFeatures(request)
|
||||
field_field_values = []
|
||||
for feature in features:
|
||||
field_field_values.append(feature[field_field_value])
|
||||
return field_field_values
|
||||
|
||||
def load_layer(self):
|
||||
the_layer = QgsVectorLayer(self.layer_path, self.layer_name, 'ogr')
|
||||
if not the_layer.isValid():
|
||||
|
Loading…
Reference in New Issue
Block a user