mn1_rec.py 26 KB

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