I am writing a script in pyqgis which should perform the following task:
First it should read a csv file which we consider it as a input csv,csv file will be something like this:
layer ,columnname ,condition ,values layer1 ,id ,not blank , layer1 ,type ,matching ,type1,type2,type3,NA layer2 ,gisid ,not blank,integer, layer2 ,layer_condition,matching ,a,b,c,d
It should read layer name unique and check whether those layer is present or not
layer will be having the columns mentioned in the csv it should check based on the condition column for example in layer1 for column id condition is not blank so all the features in the layer should not have any null values or blank spaces and for column like type condition is matching so all the feautre values should have one of the values mentioned in the values column.
So far i have tried the following code:
import csv
layer=QgsProject.instance().mapLayersByName('layer1')[0]
with open(r'layer1_Validation.csv') as file_obj:
reader_obj = csv.DictReader(file_obj)
for i,row in enumerate(reader_obj):
if row['Condition'] == "Matching":
a=row['values'].split(',')
column=row['ColumnName']
print(a)
print(column)
for f in layer.getFeatures():
for s in a:
if f[column] == a:
print(f.id())
break