mn2_rec.py 28 KB

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