mn2_rec.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. '''
  2. Schéma de validation des données MN2
  3. @author: olivier.massot, 2018
  4. '''
  5. import logging
  6. from qgis.core import QgsGeometry
  7. from core.cerberus_ import is_float, is_multi_int, is_int, \
  8. is_modern_french_date
  9. from core.validation_errors import UniqueError, RelationError, \
  10. DuplicatedGeom, MissingItem, DimensionError, TechnicalValidationError
  11. from core.validator import QgsModel, BaseValidator
  12. logger = logging.getLogger("mncheck")
  13. SCHEMA_NAME = "Schéma MN v2 REC"
  14. STATUTS = ['EN ETUDE', 'EN REALISATION', 'EN SERVICE', 'HORS SERVICE']
  15. XMIN, XMAX, YMIN, YMAX = 1341999, 1429750, 8147750, 8294000
  16. CRS = 'EPSG:3949' # Coordinate Reference System
  17. TOLERANCE = 1
  18. ##### Modeles
  19. class Artere(QgsModel):
  20. layername = "artere_geo"
  21. geom_type = QgsModel.GEOM_LINE
  22. crs = CRS
  23. bounding_box = (XMIN,YMIN,XMAX,YMAX)
  24. schema = {'AR_CODE': {'type': 'string', 'maxlength': 26},
  25. 'AR_NOM': {'type': 'string', 'maxlength': 26},
  26. 'AR_ID_INSE': {'type': 'string', 'empty': False, 'regex': r'50\d{3}'},
  27. 'AR_LONG': {'empty': False, 'validator': is_float},
  28. 'AR_ETAT': {'type': 'string', 'empty': False, 'allowed': ['0', '1', '2', '3', '4']},
  29. 'AR_OCCP': {'type': 'string', 'empty': False, 'allowed': ['0', '1.1', '1.2', '2', '3', '4']},
  30. 'AR_NOEUD_A': {'type': 'string', 'empty': False, 'maxlength': 20},
  31. 'AR_NOEUD_B': {'type': 'string', 'empty': False, 'maxlength': 20},
  32. 'AR_NB_FOUR': {'empty': False, 'validator': is_multi_int},
  33. 'AR_FOU_DIS': {'empty': False, 'validator': is_int},
  34. 'AR_TYPE_FO': {'type': 'string', 'multiallowed': ['PVC', 'PEHD', 'SOUS-TUBAGE PEHD', 'SOUS-TUBAGE SOUPLE', 'FACADE', 'AERIEN', 'ENCORBELLEMENT', 'AUTRE']},
  35. 'AR_TYFO_AI': {'type': 'string', 'multiallowed': ['PVC', 'PEH', 'TUB', 'FAC', 'ENC', 'APP']},
  36. 'AR_DIAM_FO': {'type': 'string', 'multiallowed': ['10', '14', '18', '25', '28', '32', '40', '45', '60', '80', '150', 'NUL']},
  37. 'AR_PRO_FOU': {'type': 'string', 'multiallowed': ['MANCHE NUMERIQUE', 'COLLECTIVITE', 'ORANGE', 'PRIVE', 'ERDF', 'AUTRE (à préciser)']},
  38. 'AR_FABRICANT': {'type': 'string', 'empty': False, 'maxlength': 100},
  39. 'AR_REF_FABRICANT': {'type': 'string', 'empty': False, 'maxlength': 100},
  40. 'AR_COULEUR': {'type': 'string', 'empty': False, 'maxlength': 20},
  41. 'AR_AIGUILLEE': {'type': 'string', 'empty': False, 'maxlength': 3, 'allowed': ['OUI', 'NON']},
  42. 'AR_NB_CABLES': {'empty': False, 'validator': is_int},
  43. 'AR_PRO_CAB': {'type': 'string', 'empty': False, 'allowed': ['MANCHE NUMERIQUE']},
  44. 'AR_GEST_FO': {'type': 'string', 'multiallowed': ['MANCHE NUMERIQUE', 'MANCHE TELECOM', 'COLLECTIVITE', 'ORANGE', 'MANCHE FIBRE', 'PRIVE', 'ERDF', 'AUTRE (à préciser)', 'NUL']},
  45. 'AR_UTIL_FO': {'type': 'string', 'multiallowed': ['MANCHE NUMERIQUE', 'MANCHE TELECOM', 'COLLECTIVITE', 'ORANGE', 'MANCHE FIBRE', 'PRIVE', 'AUTRE (à préciser)', 'NUL']},
  46. 'AR_DATE_IN': {'empty': False, 'validator': is_modern_french_date},
  47. 'AR_DATE_RE': {'empty': False, 'validator': is_modern_french_date},
  48. 'AR_REF_PLA': {'type': 'string', 'maxlength': 100},
  49. 'AR_SRC_GEO': {'type': 'string', 'maxlength': 50},
  50. 'AR_QLT_GEO': {'type': 'string', 'empty': False, 'allowed': ['A', 'B', 'C']},
  51. 'AR_PRO_MD': {'type': 'string', 'empty': False, 'default': 'MANCHE NUMERIQUE', 'allowed': ['MANCHE NUMERIQUE']},
  52. 'AR_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  53. 'AR_STATUT': {'type': 'string', 'empty': False, 'allowed': STATUTS}}
  54. def __repr__(self):
  55. return "Artere {}".format(self.AR_CODE)
  56. class Cable(QgsModel):
  57. layername = "cable_geo"
  58. geom_type = QgsModel.GEOM_LINE
  59. crs = CRS
  60. bounding_box = (XMIN,YMIN,XMAX,YMAX)
  61. schema = {'CA_CODE': {'type': 'string', 'maxlength': 18},
  62. 'CA_NOM': {'type': 'string', 'maxlength': 18},
  63. 'CA_NUMERO': {'type': 'string', 'maxlength': 17},
  64. 'CA_EMPRISE': {'type': 'string', 'maxlength': 10},
  65. 'CA_FAB': {'type': 'string', 'maxlength': 100},
  66. 'CA_REFFAB': {'type': 'string', 'maxlength': 100},
  67. 'CA_MODELE': {'type': 'string', 'maxlength': 10},
  68. 'CA_TYPE': {'type': 'string', 'maxlength': 10, 'empty': False, 'allowed': ['AERIEN', 'IMMEUBLE', 'FACADE', 'MIXTE', 'SOUTERRAIN']},
  69. 'CA_TYPFCT': {'type': 'string', 'maxlength': 3, 'empty': False, 'allowed': ['CDI', 'CTR', 'CBM', 'RAC', 'CBO']},
  70. 'CA_ETAT': {'type': 'string', 'maxlength': 1, 'empty': False, 'allowed': ['0', '1', '2', '3', '4']},
  71. 'CA_LONG': {'validator': is_float},
  72. 'CA_EQ_A': {'type': 'string', 'maxlength': 18},
  73. 'CA_EQ_B': {'type': 'string', 'maxlength': 18},
  74. 'CA_DIAMETR': {'empty': False, 'validator': is_float},
  75. 'CA_COULEUR': {'type': 'string', 'maxlength': 20, 'empty': False, 'allowed': ['NOIR', 'BLEU', 'BLANC']},
  76. 'CA_TECHNOL': {'type': 'string', 'maxlength': 17, 'empty': False, 'allowed': ['G657A2_M6', 'G657A2_M12']},
  77. 'CA_NB_FO': {'validator': is_int},
  78. 'CA_NB_FO_U': {'empty': False, 'validator': is_int},
  79. 'CA_NB_FO_D': {'empty': False, 'validator': is_int},
  80. 'CA_PRO': {'type': 'string', 'maxlength': 20, 'empty': False, 'allowed': ['MANCHE NUMERIQUE']},
  81. 'CA_GEST': {'type': 'string', 'maxlength': 20, 'empty': False, 'allowed': ['MANCHE FIBRE']},
  82. 'CA_DATE_IN': {'empty': False, 'validator': is_modern_french_date},
  83. 'CA_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  84. 'CA_STATUT': {'type': 'string', 'empty': False, 'allowed': STATUTS}}
  85. def __repr__(self):
  86. return "Cable {}-{}".format(self.CA_EQ_A, self.CA_EQ_B)
  87. class Equipement(QgsModel):
  88. layername = "equipement_passif"
  89. geom_type = QgsModel.GEOM_POINT
  90. crs = CRS
  91. bounding_box = (XMIN,YMIN,XMAX,YMAX)
  92. schema = {'EQ_CODE': {'type': 'string', 'maxlength': 18},
  93. 'EQ_NOM': {'type': 'string', 'maxlength': 10, 'contains_any_of': ['PBO', 'BPE', 'BAI']},
  94. 'EQ_NOM_NOE': {'type': 'string', 'maxlength': 30},
  95. 'EQ_REF': {'type': 'string', 'maxlength': 100},
  96. 'EQ_EMPRISE': {'type': 'string', 'maxlength': 7},
  97. 'EQ_FABR': {'type': 'string', 'maxlength': 100},
  98. 'EQ_CAPFO': {'empty': False, 'validator': is_int},
  99. 'EQ_NBMXEQ': {'empty': False, 'validator': is_int},
  100. 'EQ_NBCAB': {'empty': False, 'validator': is_int},
  101. 'EQ_DIMENS': {'type': 'string', 'maxlength': 50},
  102. 'EQ_TYPEQ': {'type': 'string', 'maxlength': 100},
  103. 'EQ_ETAT': {'type': 'string', 'empty': False, 'allowed': ['0', '1', '2', '3', '4']},
  104. 'EQ_OCCP': {'type': 'string', 'empty': False, 'allowed': ['0', '1.1', '1.2', '2', '3', '4']},
  105. 'EQ_TYPE': {'type': 'string', 'empty': False, 'allowed': ['PBO', 'PBOE', 'BPE', 'BAI']},
  106. 'EQ_TYPSTRC': {'type': 'string', 'empty': False, 'allowed': ['CHAMBRE', 'AERIEN', 'FACADE', 'COLONNE MONTANTE', 'PIED IMMEUBLE', 'DTIO']},
  107. 'EQ_TYPE_LQ': {'type': 'string', 'empty': False, 'allowed': ['PBO', 'BPE JB', 'BPE JD', 'BAIDC', 'BAIOP']},
  108. 'EQ_TYPE_PH': {'type': 'string', 'empty': False, 'allowed': ['PBO 6', 'PBO 12', 'BPE 12EP', 'BPE 24EP', 'BPE 48EP', 'BPE 72EP', 'BPE 96EP', 'BPE 144EP', 'BPE 288EP', 'BPE 576EP', 'BPE 720EP', 'BAI']},
  109. 'EQ_PRO': {'type': 'string', 'empty': False, 'allowed': ['MANCHE NUMERIQUE', 'COLLECTIVITE', 'ORANGE', 'PRIVE', 'AUTRE (à préciser)', 'NUL']},
  110. 'EQ_GEST': {'type': 'string', 'empty': False, 'allowed': ['MANCHE NUMERIQUE', 'MANCHE TELECOM', 'COLLECTIVITE', 'ORANGE', 'MANCHE FIBRE', 'PRIVE', 'AUTRE (à préciser)', 'NUL']},
  111. 'EQ_HAUT': {'empty': False, 'validator': is_float},
  112. 'EQ_DATE_IN': {'empty': False, 'validator': is_modern_french_date},
  113. 'EQ_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  114. 'EQ_STATUT': {'type': 'string', 'empty': False, 'allowed': STATUTS}}
  115. def __repr__(self):
  116. return "Equipement {}".format(self.EQ_NOM)
  117. class Noeud(QgsModel):
  118. layername = "noeud_geo"
  119. geom_type = QgsModel.GEOM_POINT
  120. crs = CRS
  121. bounding_box = (XMIN,YMIN,XMAX,YMAX)
  122. schema = {'NO_CODE': {'type': 'string', 'maxlength': 18},
  123. 'NO_NOM': {'type': 'string', 'maxlength': 30},
  124. 'NO_ID_INSE': {'type': 'string', 'empty': False, 'regex': r'50\d{3}'},
  125. 'NO_VOIE': {'type': 'string', 'maxlength': 100},
  126. 'NO_EMPRISE': {'type': 'string', 'maxlength': 10},
  127. 'NO_ETAT': {'type': 'string', 'empty': False, 'allowed': ['0', '1', '2', '3', '4']},
  128. 'NO_OCCP': {'type': 'string', 'empty': False, 'allowed': ['0', '1.1', '1.2', '2', '3', '4']},
  129. 'NO_TYPE': {'type': 'string', 'empty': False, 'allowed': ['CHA', 'POT', 'LTE', 'SEM', 'FAC', 'OUV', 'IMM']},
  130. 'NO_TYPFCT': {'type': 'string', 'empty': False, 'allowed': ['INTERCONNEXION', 'SATELLITE', 'PASSAGE', 'REGARD', 'INDETERMINE']},
  131. 'NO_TYPE_LQ': {'type': 'string', 'empty': False, 'allowed': ['CHTIR', 'CHRACC', 'POT', 'NRO', 'PM', 'MIMO', 'FAC', 'OUV', 'IMM']},
  132. 'NO_TYPE_PH': {'type': 'string', 'empty': False, 'allowed': ['CHAMBRE', 'POTEAU', 'ARMOIRE', 'SHELTER', 'BATIMENT', 'SITE MIMO', 'FACADE', 'OUVRAGE', 'IMMEUBLE']},
  133. 'NO_CODE_PH': {'type': 'string', 'maxlength': 20},
  134. 'NO_TECH_PS': {'type': 'string', 'maxlength': 20, 'multiallowed': ['COAX', 'CUT', 'ECL', 'ELEC', 'VP', 'OPT', 'NC']},
  135. 'NO_AMO': {'type': 'string', 'maxlength': 20},
  136. 'NO_PLINOX': {'required':False, 'type': 'string', 'maxlength': 3, 'allowed': ['OUI', 'NON']},
  137. 'NO_X': {'empty': False, 'validator': is_float},
  138. 'NO_Y': {'empty': False, 'validator': is_float},
  139. 'NO_PRO': {'type': 'string', 'maxlength': 20, 'empty': False, 'allowed': ['MANCHE NUMERIQUE', 'COLLECTIVITE', 'ORANGE', 'ERDF', 'PRIVE', 'ENEDIS', 'AUTRE (à préciser)', 'NUL']},
  140. 'NO_GEST': {'type': 'string', 'maxlength': 20, 'empty': False, 'allowed': ['MANCHE NUMERIQUE', 'MANCHE TELECOM', 'COLLECTIVITE', 'ORANGE', 'ERDF', 'ENEDIS', 'MANCHE FIBRE', 'PRIVE', 'AUTRE (à préciser)', 'NUL']},
  141. 'NO_HAUT': {'empty': False, 'validator': is_float},
  142. 'NO_DATE_IN': {'empty': False, 'validator': is_modern_french_date},
  143. 'NO_REF_PLA': {'type': 'string', 'maxlength': 100},
  144. 'NO_SRC_GEO': {'type': 'string', 'maxlength': 50},
  145. 'NO_QLT_GEO': {'type': 'string', 'maxlength': 1, 'empty': False, 'allowed': ['A', 'B', 'C']},
  146. 'NO_PRO_MD': {'type': 'string', 'maxlength': 20, 'empty': False, 'allowed': ['MANCHE NUMERIQUE']},
  147. 'NO_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  148. 'NO_STATUT': {'type': 'string', 'empty': False, 'allowed': STATUTS}}
  149. def __repr__(self):
  150. return "Noeud {}".format(self.NO_NOM)
  151. class Tranchee(QgsModel):
  152. layername = "tranchee_geo"
  153. geom_type = QgsModel.GEOM_LINE
  154. crs = CRS
  155. bounding_box = (XMIN,YMIN,XMAX,YMAX)
  156. schema = {'TR_CODE': {'type': 'string', 'maxlength': 23},
  157. 'TR_NOM': {'type': 'string', 'maxlength': 23},
  158. 'TR_ID_INSE': {'type': 'string', 'empty': False, 'regex': r'50\d{3}'},
  159. 'TR_VOIE': {'type': 'string', 'maxlength': 200},
  160. 'TR_TYP_IMP': {'type': 'string', 'empty': False, 'allowed': ['ACCOTEMENT STABILISE', 'ACCOTEMENT NON STABILISE', 'CHAUSSEE LOURDE', 'CHAUSSEE LEGERE', 'FOSSE', 'TROTTOIR', 'ESPACE VERT', 'ENCORBELLEMENT']},
  161. 'TR_MOD_POS': {'type': 'string', 'empty': False, 'allowed': ['TRADITIONNEL', 'MICRO TRANCHEE', 'FONCAGE 60', 'FONCAGE 90', 'FONCAGE 120', 'TRANCHEUSE', 'FORAGE URBAIN', 'FORAGE RURAL', 'ENCORBELLEMENT']},
  162. 'TR_MPOS_AI': {'type': 'string', 'empty': False, 'allowed': ['TRA', 'ALL', 'FONCAGE 60', 'FON', 'FOR', 'ENC']},
  163. 'TR_LONG': {'empty': False, 'validator': is_float},
  164. 'TR_LARG': {'empty': False, 'validator': is_float},
  165. 'TR_REVET': {'empty':True, 'type': 'string', 'allowed': ['SABLE', 'BICOUCHE', 'ENROBE', 'BETON', 'PAVE', 'TERRAIN NATUREL']},
  166. 'TR_CHARGE': {'empty': False, 'validator': is_float},
  167. 'TR_GRILLAG': {'empty':True, 'validator': is_float},
  168. 'TR_REMBLAI': {'type': 'string'},
  169. 'TR_PLYNOX': {'type': 'string', 'empty': False, 'allowed': ['OUI', 'NON']},
  170. 'TR_PRO_VOI': {'type': 'string', 'empty': False, 'allowed': ['COMMUNE', 'COMMUNAUTE DE COMMUNES', 'DEPARTEMENT', 'ETAT', 'PRIVE']},
  171. 'TR_GEST_VO': {'type': 'string', 'empty': False, 'allowed': ['COMMUNE', 'COMMUNAUTE DE COMMUNES', 'DEPARTEMENT', 'ETAT', 'PRIVE']},
  172. 'TR_SCHEMA': {'maxlength': 100, 'type': 'string'},
  173. 'TR_DATE_IN': {'empty': False, 'validator': is_modern_french_date},
  174. 'TR_SRC_GEO': {'type': 'string', 'maxlength': 50},
  175. 'TR_QLT_GEO': {'type': 'string', 'empty': False, 'allowed': ['A', 'B', 'C']},
  176. 'TR_PRO_MD': {'type': 'string', 'maxlength': 20},
  177. 'TR_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  178. 'TR_STATUT': {'type': 'string', 'empty': False, 'allowed': STATUTS}}
  179. def __repr__(self):
  180. return "Tranchee {}".format(self.TR_VOIE)
  181. class Zapbo(QgsModel):
  182. layername = "zapbo_geo"
  183. geom_type = QgsModel.GEOM_POLYGON
  184. crs = CRS
  185. bounding_box = (XMIN,YMIN,XMAX,YMAX)
  186. schema = {'ID_ZAPBO': {'type': 'string', 'maxlength': 30, 'contains_any_of': ['PBO', 'BPE']},
  187. 'COMMENTAIR': {'type': 'string', 'maxlength': 254, 'empty': True},
  188. 'STATUT': {'type': 'string', 'empty': False, 'allowed': STATUTS}}
  189. def __repr__(self):
  190. return "Zapbo {}".format(self.ID_ZAPBO)
  191. ##### Validator
  192. class Validator(BaseValidator):
  193. schema_name = "MN2 REC"
  194. models = [Artere, Cable, Equipement, Noeud, Tranchee, Zapbo]
  195. def _technical_validation(self):
  196. # construction des index
  197. arteres = self.dataset[Artere]
  198. cables = self.dataset[Cable]
  199. tranchees = self.dataset[Tranchee]
  200. noeuds = {}
  201. for noeud in self.dataset[Noeud]:
  202. if not noeud.NO_NOM in noeuds:
  203. noeuds[noeud.NO_NOM] = noeud
  204. else:
  205. self.log_error(UniqueError("Doublons dans le champs: {}".format(noeud), layername=Noeud.layername, field="NO_NOM"))
  206. equipements = {}
  207. for equipement in self.dataset[Equipement]:
  208. if not equipement.EQ_NOM in equipements:
  209. equipements[equipement.EQ_NOM] = equipement
  210. else:
  211. self.log_error(UniqueError("Doublons dans le champs: {}".format(equipement), layername=Equipement.layername, field="EQ_NOM"))
  212. zapbos = {}
  213. for zapbo in self.dataset[Zapbo]:
  214. if not zapbo.ID_ZAPBO in zapbos:
  215. zapbos[zapbo.ID_ZAPBO] = zapbo
  216. else:
  217. self.log_error(UniqueError("Doublons dans le champs: {}".format(zapbo), layername=Zapbo.layername, field="ID_ZAPBO"))
  218. # rattachement les noeuds aux artères
  219. for artere in arteres:
  220. try:
  221. artere.noeud_a = noeuds[artere.AR_NOEUD_A]
  222. except KeyError:
  223. artere.noeud_a = None
  224. self.log_error(RelationError("Le noeud '{}' n'existe pas".format(artere.AR_NOEUD_A), layername=Artere.layername, field="AR_NOEUD_A"))
  225. try:
  226. artere.noeud_b = noeuds[artere.AR_NOEUD_B]
  227. except KeyError:
  228. artere.noeud_b = None
  229. self.log_error(RelationError("Le noeud '{}' n'existe pas".format(artere.AR_NOEUD_B), layername=Artere.layername, field="AR_NOEUD_A"))
  230. # rattachement des equipements aux cables
  231. for cable in cables:
  232. try:
  233. cable.equipement_a = equipements[cable.CA_EQ_A]
  234. except KeyError:
  235. cable.equipement_a = None
  236. self.log_error(RelationError("L'équipement '{}' n'existe pas".format(cable.CA_EQ_A), layername=Cable.layername, field="CA_EQ_A"))
  237. try:
  238. cable.equipement_b = equipements[cable.CA_EQ_B]
  239. except KeyError:
  240. cable.equipement_b = None
  241. self.log_error(RelationError("L'équipement '{}' n'existe pas".format(cable.CA_EQ_B), layername=Cable.layername, field="CA_EQ_B"))
  242. # rattachement des equipements aux noeuds
  243. for equipement in equipements.values():
  244. try:
  245. equipement.noeud = noeuds[equipement.EQ_NOM_NOE]
  246. except KeyError:
  247. equipement.noeud = None
  248. self.log_error(RelationError("Le noeud '{}' n'existe pas".format(equipement.EQ_NOM_NOE, equipement.EQ_NOM), layername=Equipement.layername, field="EQ_NOM_NOE"))
  249. # verifie que tous les equipements sont l'equipement B d'au moins un cable
  250. equipements_b = [cable.CA_EQ_B for cable in cables]
  251. for eq_id in equipements:
  252. if equipements[eq_id].EQ_TYPE == "BAI":
  253. continue
  254. if not eq_id in equipements_b:
  255. self.log_error(RelationError("L'equipement '{}' n'est l'équipement B d'aucun cable".format(eq_id), layername=Equipement.layername, field="EQ_NOM"))
  256. # controle des doublons graphiques
  257. for i, tranchee in enumerate(tranchees):
  258. for other in tranchees[i+1:]:
  259. if tranchee.geom == other.geom:
  260. self.log_error(DuplicatedGeom("Une entité graphique est dupliquée".format(tranchee), layername=Tranchee.layername, field="geom"))
  261. for i, artere in enumerate(arteres):
  262. for other in arteres[i+1:]:
  263. if artere.geom == other.geom:
  264. self.log_error(DuplicatedGeom("Une entité graphique est dupliquée ('{}')".format(artere), layername=Artere.layername, field="geom"))
  265. for i, cable in enumerate(cables):
  266. for other in cables[i+1:]:
  267. if cable.geom == other.geom and cable.CA_EQ_A == other.CA_EQ_A and cable.CA_EQ_B == other.CA_EQ_B:
  268. self.log_error(DuplicatedGeom("Une entité graphique est dupliquée ('{}')".format(cable), layername=Cable.layername, field="geom"))
  269. ls_noeuds = list(noeuds.values())
  270. for i, noeud in enumerate(ls_noeuds):
  271. for other in ls_noeuds[i+1:]:
  272. if noeud.geom == other.geom:
  273. self.log_error(DuplicatedGeom("Une entité graphique est dupliquée ('{}')".format(noeud), layername=Noeud.layername, field="geom"))
  274. del ls_noeuds
  275. ls_zapbos = list(zapbos.values())
  276. for i, zapbo in enumerate(ls_zapbos):
  277. for other in ls_zapbos[i+1:]:
  278. if zapbo.geom == other.geom:
  279. self.log_error(DuplicatedGeom("Une entité graphique est dupliquée ('{}')".format(zapbo), layername=Zapbo.layername, field="geom"))
  280. del ls_zapbos
  281. # Arteres: comparer la géométrie à celle des noeuds
  282. for artere in arteres:
  283. if not artere.noeud_a or not artere.noeud_b:
  284. continue
  285. if not any(((artere.points[0].distanceSquared(artere.noeud_a.points[0]) <= TOLERANCE and \
  286. artere.points[-1].distanceSquared(artere.noeud_b.points[0]) <= TOLERANCE),
  287. (artere.points[0].distanceSquared(artere.noeud_b.points[0]) <= TOLERANCE and \
  288. artere.points[-1].distanceSquared(artere.noeud_a.points[0]) <= TOLERANCE))):
  289. self.log_error(MissingItem("Pas de noeud aux coordonnées attendues ('{}')".format(artere), layername=Artere.layername, field="geom"))
  290. # Cables: comparer la géométrie à celle des equipements (on utilise en fait la geom du noeud correspondant à l'équipement)
  291. for cable in cables:
  292. if not cable.equipement_a or not cable.equipement_b or not cable.is_geometry_valid() or not cable.equipement_a.noeud or not cable.equipement_b.noeud:
  293. continue
  294. if not any(((cable.points[0].distanceSquared(cable.equipement_a.noeud.points[0]) <= TOLERANCE and \
  295. cable.points[-1].distanceSquared(cable.equipement_b.noeud.points[0]) <= TOLERANCE),
  296. (cable.points[0].distanceSquared(cable.equipement_b.noeud.points[0]) <= TOLERANCE and \
  297. cable.points[-1].distanceSquared(cable.equipement_a.noeud.points[0]) <= TOLERANCE))):
  298. self.log_error(MissingItem("Pas d'equipement aux coordonnées attendues ('{}')".format(cable), layername=Cable.layername, field="geom"))
  299. # Verifie que chaque tranchée a au moins une artère
  300. arteres_full_buffer = QgsGeometry().unaryUnion([a.geom for a in arteres]).buffer(TOLERANCE, 100)
  301. for tranchee in tranchees:
  302. if not arteres_full_buffer.contains(tranchee.geom):
  303. self.log_error(MissingItem("Tranchée ou portion de tranchée sans artère ('{}')".format(tranchee), layername=Tranchee.layername, field="*"))
  304. # Verifie que chaque cable a au moins une artère (sauf si commentaire contient 'baguette')
  305. for cable in cables:
  306. if "baguette" in cable.CA_COMMENT.lower() or not cable.is_geometry_valid():
  307. continue
  308. if not arteres_full_buffer.contains(cable.geom):
  309. self.log_error(MissingItem("Cable ou portion de cable sans artère ('{}')".format(cable), layername=Cable.layername, field="*"))
  310. del arteres_full_buffer
  311. # Verifie que chaque artère a au moins un cable (sauf si commentaire contient un de ces mots 'racco client adductio attente bus 'sans cable'')
  312. cables_full_buffer = QgsGeometry().unaryUnion([c.geom for c in cables]).buffer(TOLERANCE, 100)
  313. for artere in arteres:
  314. if any(x in artere.AR_COMMENT.lower() for x in ['racco','client','adductio','attente','bus','sans cable']):
  315. continue
  316. if not cables_full_buffer.contains(artere.geom):
  317. self.log_error(MissingItem("Artère sans cable ('{}')".format(artere), layername=Artere.layername, field="*"))
  318. del cables_full_buffer
  319. # Contrôle des dimensions logiques
  320. for artere in arteres:
  321. try:
  322. if not int(artere.AR_FOU_DIS) <= int(artere.AR_NB_FOUR):
  323. self.log_error(DimensionError("Le nombre de fourreaux disponibles doit être inférieur au nombre total ('{}')".format(artere), layername=Artere.layername, field="AR_FOU_DIS"))
  324. except (TypeError, ValueError):
  325. pass
  326. for cable in cables:
  327. try:
  328. if not int(cable.CA_NB_FO_U) <= int(cable.CA_NB_FO):
  329. self.log_error(DimensionError("Le nombre de fourreaux utilisés doit être inférieur au nombre total ('{}')".format(cable), layername=Cable.layername, field="CA_NB_FO_U"))
  330. if not int(cable.CA_NB_FO_D) <= int(cable.CA_NB_FO):
  331. self.log_error(DimensionError("Le nombre de fourreaux disponibles doit être inférieur au nombre total ('{}')".format(cable), layername=Cable.layername, field="CA_NB_FO_D"))
  332. except (TypeError, ValueError):
  333. pass
  334. # Verifier que chaque equipement de type PBO est contenu dans une zapbo, et que le nom de la zapbo contient le nom de l'equipement
  335. for equipement in equipements.values():
  336. if not equipement.EQ_TYPE == "PBO":
  337. continue
  338. #zapbos englobant l'equipement
  339. candidates = []
  340. for zapbo in zapbos.values():
  341. if zapbo.geom.contains(equipement.geom):
  342. candidates.append(zapbo)
  343. # le pbo doit être contenu dans une zapbo
  344. if not candidates:
  345. self.log_error(MissingItem("Le PBO n'est contenu dans aucune ZAPBO: {}".format(equipement), layername=Equipement.layername, field="geom"))
  346. continue
  347. # On se base sur le nom pour trouver la zapbo correspondante
  348. try:
  349. equipement.zapbo = next((z for z in candidates if equipement.EQ_NOM in z.ID_ZAPBO))
  350. except StopIteration:
  351. self.log_error(MissingItem("Le nom du PBO ne coincide avec le nom d'aucune des ZAPBO qui le contient: {}".format(equipement), layername=Equipement.layername, field="EQ_NOM"))
  352. break
  353. if not hasattr(equipement.zapbo, "nb_prises") or equipement.zapbo.nb_prises is None:
  354. equipement.zapbo.nb_prises = 0
  355. # Controle du dimensionnement des PBO
  356. if equipement.zapbo.nb_prises is not None:
  357. if equipement.EQ_TYPE_PH == 'PBO 6' and not equipement.zapbo.nb_prises < 6:
  358. self.log_error(DimensionError("Le PBO 6 contient plus de 5 prises: {}".format(equipement), layername=Equipement.layername, field="*"))
  359. if equipement.EQ_TYPE_PH == 'PBO 12' and not equipement.zapbo.nb_prises >= 6 and equipement.zapbo.nb_prises <= 8:
  360. self.log_error(DimensionError("Le PBO 12 contient mois de 6 prises ou plus de 8 prises: {}".format(equipement), layername=Equipement.layername, field="*"))
  361. if equipement.zapbo.STATUT == "REC" and not equipement.EQ_STATUT == "REC":
  362. self.log_error(TechnicalValidationError("Le statut du PBO n'est pas cohérent avec le statut de sa ZAPBO: {}".format(equipement), layername=Equipement.layername, field="*"))
  363. if equipement.EQ_STATUT == "REC" and not equipement.zapbo.STATUT == "REC" and not equipement.zapbo.ID_ZAPBO[:4].lower() == "att_":
  364. self.log_error(TechnicalValidationError("Le statut du PBO n'est pas cohérent avec le statut de sa ZAPBO: {}".format(equipement), layername=Equipement.layername, field="*"))