netgeo_2_2_doe.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. '''
  2. Controle les données d'un dossier ou d'une archive contenant des données au format Netgeo 2.2
  3. Python 3.7+
  4. @author: olivier.massot, sept. 2018
  5. '''
  6. from core import gis
  7. from core.mn import ReferentielDb
  8. from core.validation import BaseValidator, BaseGeoModel, is_french_date
  9. xmin, xmax, ymin, ymax = 1341999, 1429750, 8147750, 8294000
  10. with ReferentielDb() as ref_db:
  11. INSEE_VALIDES = [row[0] for row in ref_db.read("SELECT code_insee FROM sig_referentiel.admn_cd50_com;")]
  12. class Artere(BaseGeoModel):
  13. schema = {'geom': {'bbox': {type: 'list', 'items': [{'type': 'int', 'min': xmin, 'max': xmax},
  14. {'type': 'int', 'min': ymin, 'max': ymax},
  15. {'type': 'int', 'min': xmin, 'max': xmax},
  16. {'type': 'int', 'min': ymin, 'max': ymax}]},
  17. 'parts': {},
  18. 'points': {},
  19. 'shapeType': {'allowed': [gis.POLYLINE]}},
  20. 'AR_CODE': {'type': 'string', 'maxlength': 26},
  21. 'AR_NOM': {'type': 'string', 'maxlength': 26},
  22. 'AR_ID_INSE': {'type': 'string', 'allowed': INSEE_VALIDES},
  23. 'AR_LONG': {'type': 'float'},
  24. 'AR_ETAT': {'type': 'string', 'allowed': ['0', '1', '2', '3', '4']},
  25. 'AR_OCCP': {'type': 'string', 'allowed': ['0', '1.1', '1.2', '2', '3', '4']},
  26. 'AR_NOEUD_A': {'type': 'string', 'maxlength': 20},
  27. 'AR_NOEUD_B': {'type': 'string', 'maxlength': 20},
  28. 'AR_NB_FOUR': {'type': 'string', 'maxlength': 20},
  29. 'AR_FOU_DIS': {'type': 'integer'},
  30. 'AR_TYPE_FO': {'type': 'string', 'allowed': ['PVC', 'PEHD', 'SOUS-TUBAGE PEHD', 'SOUS-TUBAGE SOUPLE', 'FACADE', 'AERIEN', 'ENCORBELLEMENT', 'AUTRE']},
  31. 'AR_TYFO_AI': {'type': 'string', 'allowed': ['PVC', 'PEH', 'TUB', 'FAC', 'ENC', 'APP']},
  32. 'AR_DIAM_FO': {'type': 'string', 'allowed': ['10', '14', '18', '25', '28', '32', '40', '45', '60', 'NUL']},
  33. 'AR_PRO_FOU': {'type': 'string', 'allowed': ['MANCHE NUMERIQUE', 'COLLECTIVITE', 'ORANGE', 'AUTRE (à préciser)']},
  34. 'AR_FAB': {'type': 'string', 'maxlength': 100}, 'AR_REFFAB': {'type': 'string', 'maxlength': 100},
  35. 'AR_COULEUR': {'type': 'string', 'maxlength': 20}, 'AR_AIGUIL': {'type': 'string', 'allowed': ['OUI', 'NON']},
  36. 'AR_NBCABL': {'type': 'integer'},
  37. 'AR_PRO_CAB': {'type': 'string', 'allowed': ['MANCHE NUMERIQUE']},
  38. 'AR_GEST_FO': {'type': 'string', 'allowed': ['MANCHE NUMERIQUE', 'MANCHE TELECOM', 'COLLECTIVITE', 'ORANGE', 'AUTRE (à préciser)', 'NUL']},
  39. 'AR_UTIL_FO': {'type': 'string', 'allowed': ['MANCHE NUMERIQUE', 'MANCHE TELECOM', 'COLLECTIVITE', 'ORANGE', 'MANCHE FIBRE', 'AUTRE (à préciser)', 'NUL']},
  40. 'AR_DATE_IN': {'validator': is_french_date},
  41. 'AR_DATE_RE': {'validator': is_french_date},
  42. 'AR_REF_PLA': {'type': 'string', 'maxlength': 100},
  43. 'AR_SRC_GEO': {'type': 'string', 'maxlength': 50},
  44. 'AR_QLT_GEO': {'type': 'string', 'allowed': ['A', 'B', 'C']},
  45. 'AR_PRO_MD': {'type': 'string', 'allowed': ['MANCHE NUMERIQUE']},
  46. 'AR_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  47. 'AR_STATUT': {'type': 'string', 'allowed': ['EN ETUDE', 'EN REALISATION', 'EN SERVICE', 'HORS SERVICE']}}
  48. class Cable(BaseGeoModel):
  49. schema = {'geom': {'bbox': {type: 'list', 'items': [{'type': 'int', 'min': xmin, 'max': xmax},
  50. {'type': 'int', 'min': ymin, 'max': ymax},
  51. {'type': 'int', 'min': xmin, 'max': xmax},
  52. {'type': 'int', 'min': ymin, 'max': ymax}]},
  53. 'parts': {},
  54. 'points': {},
  55. 'shapeType': {'allowed': [gis.POLYLINE]}},
  56. '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, 'allowed': ['AERIEN', 'IMMEUBLE', 'FACADE', 'MIXTE', 'SOUTERRAIN']},
  64. 'CA_TYPFCT': {'type': 'string', 'maxlength': 3, 'allowed': ['CDI', 'CTR', 'CBM', 'RAC', 'CBO']},
  65. 'CA_ETAT': {'type': 'string', 'maxlength': 1, 'allowed': ['0', '1', '2', '3', '4']},
  66. 'CA_LONG': {'type': 'float'}, 'CA_EQ_A': {'type': 'string', 'maxlength': 18},
  67. 'CA_EQ_B': {'type': 'string', 'maxlength': 18},
  68. 'CA_DIAMETR': {'type': 'integer'},
  69. 'CA_COULEUR': {'type': 'string', 'maxlength': 20, 'allowed': ['NOIR', 'BLEU', 'BLANC']},
  70. 'CA_TECHNOL': {'type': 'string', 'maxlength': 17, 'allowed': ['G657A2_M6', 'G657A2_M12']},
  71. 'A_NB_FO_U': {'type': 'integer'}, 'CA_NB_FO_D': {'type': 'integer'},
  72. 'CA_PRO': {'type': 'string', 'maxlength': 20, 'allowed': ['MANCHE NUMERIQUE']},
  73. 'CA_GEST': {'type': 'string', 'maxlength': 20, 'allowed': ['NUL']},
  74. 'CA_DATE_IN': {'validator': is_french_date},
  75. 'CA_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  76. 'CA_STATUT': {'type': 'string', 'maxlength': 14, 'allowed': ['EN ETUDE', 'EN REALISATION', 'EN SERVICE', 'HORS SERVICE']}}
  77. class Equipement(BaseGeoModel):
  78. schema = {'geom': {'bbox': {type: 'list', 'items': [{'type': 'int', 'min': xmin, 'max': xmax},
  79. {'type': 'int', 'min': ymin, 'max': ymax},
  80. {'type': 'int', 'min': xmin, 'max': xmax},
  81. {'type': 'int', 'min': ymin, 'max': ymax}]},
  82. 'parts': {},
  83. 'points': {},
  84. 'shapeType': {'allowed': [gis.POLYLINE]}},
  85. 'EQ_CODE': {'type': 'string', 'maxlength': 18},
  86. 'EQ_NOM': {'type': 'string', 'maxlength': 18},
  87. 'EQ_NOM_NOE': {'type': 'string', 'maxlength': 14},
  88. 'EQ_REF': {'type': 'string', 'maxlength': 100},
  89. 'EQ_EMPRISE': {'type': 'string', 'maxlength': 7},
  90. 'EQ_FABR': {'type': 'string', 'maxlength': 100},
  91. 'EQ_CAPFO': {'type': 'integer'},
  92. 'EQ_NBMXEQ': {'type': 'integer'},
  93. 'EQ_NBCAB': {'type': 'integer'},
  94. 'EQ_DIMENS': {'type': 'string', 'maxlength': 50},
  95. 'EQ_TYPEQ': {'type': 'string', 'maxlength': 100},
  96. 'EQ_ETAT': {'type': 'string', 'maxlength': 1, 'allowed': ['0', '1', '2', '3', '4']},
  97. 'EQ_OCCP': {'type': 'string', 'maxlength': 3, 'allowed': ['0', '1.1', '1.2', '2', '3', '4']},
  98. 'EQ_TYPE': {'type': 'string', 'maxlength': 3, 'allowed': ['PBO', 'PEC', 'BPE', 'BAI']},
  99. 'EQ_TYPSTRC': {'type': 'string', 'maxlength': 16, 'allowed': ['CHAMBRE', 'AERIEN', 'FACADE', 'COLONNE MONTANTE', 'PIED IMMEUBLE', 'DTIO']},
  100. 'EQ_TYPE_LQ': {'type': 'string', 'maxlength': 6, 'allowed': ['PBO', 'BPE JB', 'BPE JD', 'BAIDC', 'BAIOP']},
  101. 'EQ_TYPE_PH': {'type': 'string', 'maxlength': 24, 'allowed': ['PBO 6', 'PBO 12', 'BPE 12EP', 'BPE 24EP', 'BPE 48EP', 'BPE 72EP', 'BPE 96EP', 'BPE 144EP', 'BPE 288EP', 'BPE 576EP', 'BPE 720EP']},
  102. 'EQ_PRO': {'type': 'string', 'maxlength': 20, 'allowed': ['MANCHE NUMERIQUE', 'COLLECTIVITE', 'ORANGE', 'AUTRE (à préciser)', 'NUL']},
  103. 'EQ_GEST': {'type': 'string', 'maxlength': 20, 'allowed': ['MANCHE NUMERIQUE', 'MANCHE TELECOM', 'COLLECTIVITE', 'ORANGE', 'MANCHE FIBRE', 'AUTRE (à préciser)', 'NUL']},
  104. 'EQ_HAUT': {'type': 'float'}, 'EQ_DATE_IN': {'type': 'datetime'},
  105. 'EQ_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  106. 'EQ_STATUT': {'type': 'string', 'maxlength': 14, 'allowed': ['EN ETUDE', 'EN REALISATION', 'EN SERVICE', 'HORS SERVICE']}}
  107. class Noeud(BaseGeoModel):
  108. schema = {'geom': {'bbox': {type: 'list', 'items': [{'type': 'int', 'min': xmin, 'max': xmax},
  109. {'type': 'int', 'min': ymin, 'max': ymax},
  110. {'type': 'int', 'min': xmin, 'max': xmax},
  111. {'type': 'int', 'min': ymin, 'max': ymax}]},
  112. 'parts': {},
  113. 'points': {},
  114. 'shapeType': {'allowed': [gis.POINT]}},
  115. 'NO_CODE': {'type': 'string', 'maxlength': 18},
  116. 'NO_ID_INSE': {'type': 'string', 'allowed': INSEE_VALIDES},
  117. 'NO_NOM': {'type': 'string', 'maxlength': 20},
  118. 'NO_VOIE': {'type': 'string', 'maxlength': 100},
  119. 'NO_EMPRISE': {'type': 'string', 'maxlength': 10},
  120. 'NO_ETAT': {'type': 'string', 'maxlength': 1, 'allowed': ['0', '1', '2', '3', '4']},
  121. 'NO_OCCP': {'type': 'string', 'maxlength': 3, 'allowed': ['0', '1.1', '1.2', '2', '3', '4']},
  122. 'NO_TYPE': {'type': 'string', 'maxlength': 3, 'allowed': ['CHA', 'POT', 'LTE', 'SEM', 'FAC', 'OUV', 'IMM']},
  123. 'NO_TYPFCT': {'type': 'string', 'maxlength': 14, 'allowed': ['INTERCONNEXION', 'SATELLITE', 'PASSAGE', 'REGARD', 'INDETERMINE']},
  124. 'NO_TYPE_LQ': {'type': 'string', 'maxlength': 10, 'allowed': ['CHTIR', 'CHRACC', 'POT', 'NRO', 'PM', 'MIMO', 'FAC', 'OUV', 'IMM']},
  125. 'NO_TYPE_PH': {'type': 'string', 'maxlength': 20, 'allowed': ['CHAMBRE', 'POTEAU', 'ARMOIRE', 'SHELTER', 'BATIMENT', 'SITE MIMO', 'FACADE', 'OUVRAGE', 'IMMEUBLE']},
  126. 'NO_CODE_PH': {'type': 'string', 'maxlength': 20},
  127. 'NO_TECH_PS': {'type': 'string', 'maxlength': 4, 'allowed': ['COAX', 'CUT', 'ECL', 'ELEC', 'VP', 'OPT', 'NC']},
  128. 'NO_AMO': {'type': 'string', 'maxlength': 20},
  129. 'NO_PLINOX': {'type': 'string', 'maxlength': 3, 'allowed': ['OUI', 'NON']},
  130. 'NO_X': {'type': 'float'},
  131. 'NO_Y': {'type': 'float'},
  132. 'NO_PRO': {'type': 'string', 'maxlength': 20, 'allowed': ['MANCHE NUMERIQUE', 'COLLECTIVITE', 'ORANGE', 'ERDF', 'AUTRE (à préciser)', 'NUL']},
  133. 'NO_GEST': {'type': 'string', 'maxlength': 20, 'allowed': ['MANCHE NUMERIQUE', 'MANCHE TELECOM', 'COLLECTIVITE', 'ORANGE', 'ERDF', 'MANCHE FIBRE', 'AUTRE (à préciser)', 'NUL']},
  134. 'NO_HAUT': {'type': 'float'},
  135. 'NO_DATE_IN': {'validator': is_french_date},
  136. 'NO_REF_PLA': {'type': 'string', 'maxlength': 100},
  137. 'NO_SRC_GEO': {'type': 'string', 'maxlength': 50},
  138. 'NO_QLT_GEO': {'type': 'string', 'maxlength': 1, 'allowed': ['A', 'B', 'C']},
  139. 'NO_PRO_MD': {'type': 'string', 'maxlength': 20, 'allowed': ['MANCHE NUMERIQUE']},
  140. 'NO_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  141. 'NO_STATUT': {'type': 'string', 'maxlength': 14, 'allowed': ['EN ETUDE', 'EN REALISATION', 'EN SERVICE', 'HORS SERVICE']}}
  142. class Tranchee(BaseGeoModel):
  143. schema = {'geom': {'bbox': {type: 'list', 'items': [{'type': 'int', 'min': xmin, 'max': xmax},
  144. {'type': 'int', 'min': ymin, 'max': ymax},
  145. {'type': 'int', 'min': xmin, 'max': xmax},
  146. {'type': 'int', 'min': ymin, 'max': ymax}]},
  147. 'parts': {},
  148. 'points': {},
  149. 'shapeType': {'allowed': [gis.POLYLINE]}},
  150. 'TR_CODE': {'type': 'string', 'maxlength': 23},
  151. 'TR_NOM': {'type': 'string', 'maxlength': 23, 'tester': 'lambda t, x: x=t.TR_CODE'},
  152. 'TR_ID_INSE': {'type': 'string', 'allowed': INSEE_VALIDES},
  153. 'TR_VOIE': {'type': 'string', 'maxlength': 200},
  154. 'TR_TYP_IMP': {'type': 'string', 'allowed': ['ACCOTEMENT STABILISE', 'ACCOTEMENT NON STABILISE', 'CHAUSSEE LOURDE', 'CHAUSSEE LEGERE', 'FOSSE', 'TROTTOIR', 'ESPACE VERT', 'ENCORBELLEMENT']},
  155. 'TR_MOD_POS': {'type': 'string', 'allowed': ['TRADITIONNEL', 'MICRO TRANCHEE', 'FONCAGE 60', 'FONCAGE 90', 'FONCAGE 120', 'TRANCHEUSE', 'FORAGE URBAIN', 'FORAGE RURAL', 'ENCORBELLEMENT']},
  156. 'TR_MPOS_AI': {'type': 'string', 'allowed': ['TRA', 'ALL', 'FONCAGE 60', 'FON', 'FOR', 'ENC']},
  157. 'TR_LONG': {'type': 'float'},
  158. 'TR_LARG': {'type': 'float'},
  159. 'TR_REVET': {'type': 'string', 'allowed': ['SABLE', 'BICOUCHE', 'ENROBE', 'BETON', 'PAVE', 'TERRAIN NATUREL']},
  160. 'TR_CHARGE': {'type': 'float'},
  161. 'TR_GRILLAG': {'type': 'float'},
  162. 'TR_REMBLAI': {'type': 'string'},
  163. 'TR_PLYNOX': {'type': 'string', 'allowed': ['OUI', 'NON']},
  164. 'TR_PRO_VOI': {'type': 'string', 'allowed': ['COMMUNE', 'COMMUNAUTE DE COMMUNES', 'DEPARTEMENT', 'ETAT', 'PRIVE']},
  165. 'TR_GEST_VO': {'type': 'string', 'allowed': ['COMMUNE', 'COMMUNAUTE DE COMMUNES', 'DEPARTEMENT', 'ETAT', 'PRIVE']},
  166. 'TR_SCHEMA': {'maxlength': 100, 'type': 'string'},
  167. 'TR_DATE_IN': {'validator': is_french_date},
  168. 'TR_SRC_GEO': {'type': 'string', 'maxlength': 50},
  169. 'TR_QLT_GEO': {'type': 'string', 'allowed': ['A', 'B', 'C']},
  170. 'TR_PRO_MD': {'type': 'string', 'maxlength': 20},
  171. 'TR_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  172. 'TR_STATUT': {'type': 'string', 'allowed': ['EN ETUDE', 'EN REALISATION', 'EN SERVICE', 'HORS SERVICE']}}
  173. class Zapbo(BaseGeoModel):
  174. schema = {'geom': {'bbox': {type: 'list', 'items': [{'type': 'int', 'min': xmin, 'max': xmax},
  175. {'type': 'int', 'min': ymin, 'max': ymax},
  176. {'type': 'int', 'min': xmin, 'max': xmax},
  177. {'type': 'int', 'min': ymin, 'max': ymax}]},
  178. 'parts': {},
  179. 'points': {},
  180. 'shapeType': {'allowed': [gis.POLYGON]}},
  181. 'ID_ZAPBO': {'type': 'string', 'maxlength': 10},
  182. 'COMMENTAIR': {'type': 'string', 'maxlength': 254, 'empty': True},
  183. 'STATUT': {'type': 'string', 'allowed': ['EN ETUDE', 'EN REALISATION', 'EN SERVICE', 'HORS SERVICE']}}
  184. class Netgeo22Validator(BaseValidator):
  185. name = "Netgeo v2.2 DOE"
  186. files = {"artere_geo.shp": Artere, "cable_geo.shp": Cable, "equipement_passif.shp": Equipement, "noeud_geo.shp":Noeud, "tranchee_geo.shp":Tranchee, "zapbo_geo.shp":Zapbo}
  187. @classmethod
  188. def _load_file(cls, model, file_path):
  189. result = []
  190. with gis.ShapeFile(file_path) as sf:
  191. fields = sf.fields()
  192. for record in sf.records():
  193. data = dict(zip(fields, record.record))
  194. item = model(record.shape, **data)
  195. result.append(item)
  196. return result
  197. @classmethod
  198. def _technical_validation(cls, dataset):
  199. # rattacher les noeuds aux artères
  200. # rattacher les equipements aux cables
  201. return dataset
  202. if __name__ == "__main__":
  203. from core.constants import MAIN
  204. subject = MAIN / "work" / "STURNO_192AP0_REC_COMPLEMENT_180822_OK.zip"
  205. report = Netgeo22Validator.submit(subject)