forked from Max77T/plantmap-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deepValidationProcess.py
84 lines (73 loc) · 2.89 KB
/
deepValidationProcess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# coding: utf8
from plantmap_engine import plantMapEngine
from IplantMapThread import PlantMapThreadInterface
from logger import *
from qgis_utils import QgisUtils
from PyQt4.QtCore import *
class deepValidation(PlantMapThreadInterface):
"""
This class make a deep research in the input layer to know exactly the status of a taxon.
It replaces the subset filter with the input field and each value of the taxon board
"""
addTaxonSignal = pyqtSignal(str, str, str)
def __init__(self, layer, fieldName, whereEditable, description, taxonList):
super(deepValidation, self).__init__()
self.resultTaxonList = []
self.layer = layer
self.fieldName = fieldName
self.whereEditable = whereEditable
self.description = description
self.pme = plantMapEngine()
self.taxonList = taxonList
self.timerInit(len(self.taxonList))
def run(self):
"""
Main process of the class, put the result of research in a list which is return to the main thread
"""
try:
#Logger
self.logProgress.emit(Logger.INFO, u"=> Début du filtrage avancé <=" )
#Temporary list of taxons
myListTaxon = []
#Test if user filled the whereeditable field
self.whereEditableWithAnd = self.whereEditable
if self.whereEditableWithAnd != '':
self.whereEditableWithAnd = " AND " + self.whereEditable
#Iterating over each taxon that the user put into the list to generate
for taxon in self.taxonList:
self.timerNewTurn()
self.timerNotify()
if(self.isKilled() == True):
break
#Remove the quoto at the begining and the end of taxon's string
#newTaxon = filter(lambda x: x != "'", taxon[0])
if taxon[1] == None or taxon[1] == "":
#Make our own filter on the layer
filterLayer = str(self.fieldName) +" = "+ taxon[0] + self.whereEditableWithAnd
#Apply the filter
result = QgisUtils.set_subsetstring(self.layer, filterLayer)
if result == False:
self.logProgress.emit(Logger.ERROR, u"Filtre incorrect : " + str(filterLayer))
#Get the description of the taxon according to the parameters
desc = self.pme.get_description(taxon[0],self.layer,self.fieldName,self.description,self.whereEditable)
if desc != None:
t = (taxon[0], desc, "OK")
self.addTaxonSignal.emit(taxon[0], desc, "OK")
myListTaxon.append(t)
else:
myListTaxon.append((taxon[0], desc, "NOK"))
self.addTaxonSignal.emit(taxon[0], desc, "NOK")
else:
myListTaxon.append((taxon[0], taxon[1], "OK"))
self.addTaxonSignal.emit(taxon[0], taxon[1], "OK")
self.resultTaxonList = myListTaxon
self.logProgress.emit(Logger.INFO, u"=> Fin du filtrage <=" )
self.timerEnd()
except Exception as e:
self.logProgress.emit(Logger.ERROR, u"Echec de filtrage avancé : " + str(e))
def getResult(self):
"""
Return the list of taxon with their status
:returns: taxon list with status and description for each one
"""
return self.resultTaxonList