1
1
# coding: utf-8
2
2
"""
3
- Lecture d'un sous-modèle Crue10
3
+ Lecture de plusieurs sous-modèles Crue10
4
4
"""
5
- import os .path
6
- import sys
7
- import arcpy
8
5
import logging
6
+ import math
9
7
import re
8
+ import sys
10
9
import traceback
10
+
11
11
from crue10 .emh .branche import BrancheAvecElementsSeuil
12
- from crue10 .utils import ExceptionCrue10 , logger
13
- from crue10 .emh .section import LitNumerote
12
+ from crue10 .emh .section import SectionIdem , SectionProfil , SectionSansGeometrie
14
13
from crue10 .etude import Etude
15
- from crue10 .emh .section import LimiteGeom , SectionIdem , SectionProfil , SectionSansGeometrie
16
- from crue10 .utils import check_isinstance , check_preffix , ExceptionCrue10 , logger
14
+ from crue10 .utils import ExceptionCrue10 , logger
17
15
16
+ import arcpy
18
17
19
- #Parametres
20
- GDB = arcpy .GetParameterAsText (0 )
21
- EDU_PATH = arcpy .GetParameterAsText (1 )
22
- LST_SOUSMODELE = arcpy .GetParameterAsText (2 ).split (";" )
23
18
24
- #Debug
25
- # GDB = r"D:\Mandats\9011_FF - CNR - GeoGAMA-Crue Maintenance\Production\2-Realisation\Data\_UserFolder\bbb\BDD.gdb"
26
- # EDU_PATH = r"D:\Mandats\9011_FF - CNR - GeoGAMA-Crue Maintenance\Production\2-Realisation\ImportExportCrue10\Etu_from_scratch_2-Sm\Etu_from_scratch.etu.xml"
27
- # LST_SOUSMODELE = ['Sm_amont', 'Sm_aval']
19
+ # Parameters
20
+ if arcpy .GetArgumentCount () == 3 :
21
+ GDB = arcpy .GetParameterAsText (0 )
22
+ EDU_PATH = arcpy .GetParameterAsText (1 )
23
+ LST_SOUSMODELE = arcpy .GetParameterAsText (2 ).split (";" )
24
+ else :
25
+ # Debug
26
+ GDB = r"C:\temp\BDD.gdb"
27
+ EDU_PATH = r"Etu_from_scratch_2-Sm\Etu_from_scratch.etu.xml"
28
+ LST_SOUSMODELE = ['Sm_amont' , 'Sm_aval' ]
28
29
29
30
30
- #Constantes
31
+ # Constants
31
32
FCLASS_NOEUD = "EMG/Noeud"
32
33
FCLASS_CASIER = "EMG/Casier"
33
34
FCLASS_BRANCHE = "EMG/Branche"
38
39
TABLE_CASIER_LOI = "Casier_Loi"
39
40
FCLASS_SEUIL_ELEM = "Seuil_Elem"
40
41
41
-
42
42
arcpy .env .workspace = GDB
43
43
44
- #Init Logger
44
+
45
+ # Init Logger
45
46
formatter = logging .Formatter ('%(levelname)s: %(message)s' )
46
47
47
48
logger .setLevel (logging .DEBUG )
57
58
# logger.addHandler(handler2)
58
59
59
60
61
+ # Functions
62
+
60
63
def truncateAllClass ():
61
64
logger .info ("Vidage des tables" )
62
65
@@ -70,9 +73,11 @@ def truncateAllClass():
70
73
arcpy .DeleteRows_management (GDB + "/" + TABLE_CASIER_LOI )
71
74
arcpy .DeleteRows_management (GDB + "/" + FCLASS_SEUIL_ELEM )
72
75
76
+
73
77
def getDist (ptA , ptB ):
74
78
return math .sqrt ((ptA .X - ptB .X )** 2 + (ptA .Y - ptB .Y )** 2 )
75
79
80
+
76
81
def getMPolyline (coords , distanceTot ):
77
82
points = arcpy .Array ()
78
83
currentDist = 0
@@ -84,18 +89,18 @@ def getMPolyline(coords, distanceTot):
84
89
if not lastPoint is None :
85
90
dist = getDist (point , lastPoint )
86
91
currentDist += dist
87
-
92
+
88
93
point .M = currentDist
89
94
points .append (point )
90
-
95
+
91
96
lastPoint = arcpy .Point (x , y )
92
-
97
+
93
98
if distanceTot is not None :
94
99
ratio = distanceTot / currentDist
95
-
100
+
96
101
for point in points :
97
102
point .M = point .M * ratio
98
-
103
+
99
104
return arcpy .Polyline (points )
100
105
101
106
@@ -110,51 +115,48 @@ def getTroncon(emh_name):
110
115
return ''
111
116
return m .group ('troncon' )[:10 ]
112
117
113
-
114
- try :
115
- # if True:
116
118
119
+ try :
117
120
logger .info ("Parametres" )
118
121
logger .info (GDB )
119
122
logger .info (EDU_PATH )
120
123
logger .info (LST_SOUSMODELE )
121
124
122
-
123
- #Ouverture session d'édition
125
+ # Ouverture session d'édition
124
126
edit = arcpy .da .Editor (arcpy .env .workspace )
125
127
edit .startEditing (False , False )
126
128
127
129
# edit.startOperation()
128
130
129
- #Vidage des tables
131
+ # Vidage des tables
130
132
# truncateAllClass()
131
-
133
+
132
134
# edit.stopOperation()
133
-
134
- #Liste de snoeuds, pour éviter qu'ils soient insérés en double sur plusieurs sous-modèles
135
+
136
+ # Liste des noeuds, pour éviter qu'ils soient insérés en double sur plusieurs sous-modèles
135
137
hashNoeuds = {}
136
-
138
+
137
139
# Get Etude
138
140
study = Etude (EDU_PATH )
139
-
141
+
140
142
for sm_elem in LST_SOUSMODELE :
141
143
logger .info ("Lecture Sous-modele- " + sm_elem )
142
144
# Get Sous-modele
143
145
sous_modele = study .get_sous_modele (sm_elem )
144
146
sous_modele .read_all ()
145
-
146
- #Suppression sections interpolées
147
+
148
+ # Suppression sections interpolées
147
149
sous_modele .remove_sectioninterpolee ()
148
-
149
- #Modifie le xp aval des sections sansgeometrie a partir des branches
150
+
151
+ # Modifie le xp aval des sections sansgeometrie a partir des branches
150
152
sous_modele .replace_zero_xp_sectionaval ()
151
-
153
+
152
154
edit .startOperation ()
153
-
155
+
154
156
logger .info ("Noeuds - " + str (len (sous_modele .noeuds )))
155
157
with arcpy .da .InsertCursor (FCLASS_NOEUD , ["Troncon" , "Nom_noeud" , "SHAPE@" ]) as cursor :
156
158
for nomNoeud in sous_modele .noeuds :
157
- #Vérifie que le noeud n'a pas déjà été importé
159
+ # Vérifie que le noeud n'a pas déjà été importé
158
160
if nomNoeud not in hashNoeuds :
159
161
hashNoeuds [nomNoeud ] = True
160
162
noeud = sous_modele .noeuds [nomNoeud ]
@@ -165,7 +167,7 @@ def getTroncon(emh_name):
165
167
166
168
edit .stopOperation ()
167
169
edit .startOperation ()
168
-
170
+
169
171
logger .info ("Casiers - " + str (len (sous_modele .casiers )))
170
172
with arcpy .da .InsertCursor (FCLASS_CASIER , ["Nom_casier" , "Nom_noeud" , "Distance_appli" , "SHAPE@" ]) as cursor :
171
173
for nomCasier in sous_modele .casiers :
@@ -176,18 +178,18 @@ def getTroncon(emh_name):
176
178
177
179
edit .stopOperation ()
178
180
edit .startOperation ()
179
-
181
+
180
182
logger .info ("Branches - " + str (len (sous_modele .branches )))
181
183
with arcpy .da .InsertCursor (FCLASS_BRANCHE , ["Troncon" , "Nom_branche" , "Type_branche" , "Longueur" , "Nom_noeud_amont" , "Nom_noeud_aval" , "IsActif" , "SHAPE@" ]) as cursor :
182
184
for nomBranche in sous_modele .branches :
183
185
logger .debug ("Branche - " + nomBranche )
184
186
branche = sous_modele .branches [nomBranche ]
185
187
polyline = getMPolyline (branche .geom .coords , branche .length )
186
188
cursor .insertRow ([getTroncon (nomBranche ), nomBranche , branche .type , branche .length , branche .noeud_amont .id , branche .noeud_aval .id , branche .is_active , polyline ])
187
-
189
+
188
190
edit .stopOperation ()
189
191
edit .startOperation ()
190
-
192
+
191
193
logger .info ("Sections - " + str (len (sous_modele .sections )))
192
194
listSectionProfil = []
193
195
with arcpy .da .InsertCursor (TABLE_SECTION , ["Troncon" , "Nom_section" , "Type_section" , "Nom_branche" , "Xp" , "Nom_section_parent" , "Delta_Z" ]) as cursor :
@@ -200,21 +202,21 @@ def getTroncon(emh_name):
200
202
dz = None
201
203
if isinstance (section , SectionSansGeometrie ):
202
204
typeSection = 1
203
- #TODO : Appeler méthode du coeur pour calculer le xp aval = branche.length
205
+ # TODO : Appeler méthode du coeur pour calculer le xp aval = branche.length
204
206
elif isinstance (section , SectionProfil ):
205
207
typeSection = 2
206
- #Merge lis numerotes
208
+ # Merge lits numérotés
207
209
section .merge_consecutive_lit_numerotes ()
208
210
listSectionProfil .append (section )
209
211
elif isinstance (section , SectionIdem ):
210
212
typeSection = 3
211
213
nom_section_parent = section .section_reference .id
212
214
dz = section .dz_section_reference
213
215
cursor .insertRow ([getTroncon (nomBranche ), nomSection , typeSection , nomBranche , section .xp ,nom_section_parent , dz ])
214
-
216
+
215
217
edit .stopOperation ()
216
218
edit .startOperation ()
217
-
219
+
218
220
logger .info ("ProfilPoints (par profil) - " + str (len (listSectionProfil )))
219
221
list_limite_point = []
220
222
with arcpy .da .InsertCursor (FCLASS_PROFIL_POINT , ["Nom_section" , "Absc_proj" , "Z" , "SHAPE@" ]) as cursor :
@@ -223,35 +225,33 @@ def getTroncon(emh_name):
223
225
logger .debug ("Profil - " + profil .id )
224
226
# logger.debug("XY - " + str(len(profil.geom_trace.coords)))
225
227
# logger.debug("XZ - " + str(len(profil.xz)))
226
-
228
+
227
229
line = arcpy .Polyline (arcpy .Array ([arcpy .Point (* coords ) for coords in profil .geom_trace .coords [:]]))
228
230
i = 0
229
231
premier_point_x = 0
230
232
hashOIDPointParAbs = {}
231
233
for p in profil .xz :
232
- absc_proj = p [0 ] # x
233
- z = p [1 ] # z
234
+ absc_proj = p [0 ] # x
235
+ z = p [1 ] # z
234
236
if i == 0 :
235
237
point = line .positionAlongLine (p [0 ])
236
238
premier_point_x = p [0 ]
237
239
else :
238
240
point = line .positionAlongLine (p [0 ] - premier_point_x )
239
-
241
+
240
242
id = cursor .insertRow ([profil .id , absc_proj , z , point ])
241
- hashOIDPointParAbs [absc_proj ] = id
242
- i += 1
243
- # print id
244
- for limit_geom in profil .limites_geom :
245
- oidPoint = hashOIDPointParAbs [limit_geom .xt ]
246
- if limit_geom .id == "Et_AxeHyd" :
243
+ hashOIDPointParAbs [absc_proj ] = id
244
+ i += 1
245
+ for _ , limite in profil .limites_geom .items ():
246
+ oidPoint = hashOIDPointParAbs [limite .xt ]
247
+ if limite .id == "Et_AxeHyd" :
247
248
id_limite = 14
248
- elif limit_geom .id == "Et_Thalweg" :
249
+ elif limite .id == "Et_Thalweg" :
249
250
id_limite = 13
250
251
else :
251
252
continue
252
- list_limite_point .append ([oidPoint , id_limite ])
253
- # print oidPoint
254
-
253
+ list_limite_point .append ([oidPoint , id_limite ])
254
+
255
255
for j in range (0 , 6 ):
256
256
if j == 5 : # on prend le max
257
257
xt = profil .lits_numerotes [j - 1 ].xt_max
@@ -262,77 +262,78 @@ def getTroncon(emh_name):
262
262
list_limite_point .append ([oidPoint , id_limite ])
263
263
else :
264
264
logger .warning ("Profil sans geom - " + profil .id )
265
-
265
+
266
266
del cursor
267
-
267
+
268
268
edit .stopOperation ()
269
269
edit .startOperation ()
270
-
270
+
271
271
logger .info ("Limites - " + str (len (list_limite_point )))
272
272
with arcpy .da .InsertCursor (TABLE_LIMITE , ["OID_Profil_Point" , "Nom_Limite" ]) as cursor_limite :
273
273
for limite in list_limite_point :
274
274
cursor_limite .insertRow (limite )
275
- del cursor_limite
275
+ del cursor_limite
276
276
277
277
edit .stopOperation ()
278
278
edit .startOperation ()
279
279
280
- logger .info ("Porfil_Trace - " + str (len (listSectionProfil )))
280
+ logger .info ("Profil_Trace - " + str (len (listSectionProfil )))
281
281
with arcpy .da .InsertCursor (FCLASS_PROFIL_TRACE , ["Nom_section" , "SHAPE@" ]) as cursor :
282
282
for profil in listSectionProfil :
283
283
if profil .geom_trace is not None :
284
284
logger .debug ("Profil - " + profil .id )
285
285
line = arcpy .Polyline (arcpy .Array ([arcpy .Point (* coords ) for coords in profil .geom_trace .coords [:]]))
286
286
cursor .insertRow ([profil .id , line ])
287
287
del cursor
288
-
288
+
289
289
edit .stopOperation ()
290
290
edit .startOperation ()
291
-
291
+
292
292
logger .info ("Seuil_Elem" )
293
293
with arcpy .da .InsertCursor (FCLASS_SEUIL_ELEM , ["Nom_branche" , "Largeur" , "Z_Seuil" , "CoefD" , "CoefPDC" ]) as cursor :
294
294
for nomBranche in sous_modele .branches :
295
295
branche = sous_modele .branches [nomBranche ]
296
296
if isinstance (branche , BrancheAvecElementsSeuil ):
297
297
logger .debug ("Seuil - " + nomBranche )
298
- for seuil in branche .liste_elements_seuil : # larg, z_seuil, coeff_d, coeff_pdc
298
+ for seuil in branche .liste_elements_seuil : # larg, z_seuil, coeff_d, coeff_pdc
299
299
cursor .insertRow ([nomBranche , seuil [0 ], seuil [1 ], seuil [2 ], seuil [3 ]])
300
300
del cursor
301
-
301
+
302
302
edit .stopOperation ()
303
303
edit .startOperation ()
304
-
304
+
305
305
logger .info ("Casier_Loi" )
306
306
with arcpy .da .InsertCursor (TABLE_CASIER_LOI , ["Nom_casier" , "Xt" , "Cote" ]) as cursor :
307
307
for nomCasier in sous_modele .casiers :
308
308
casier = sous_modele .casiers [nomCasier ]
309
- if len (casier .profils_casier ) > 1 :
309
+
310
+ if len (casier .profils_casier ) > 1 :
310
311
logger .debug ("Casier_Loi - Fusion - " + nomCasier )
311
312
casier .fusion_profil_casiers ()
312
-
313
- if len (casier .profils_casier ) > 0 :
313
+
314
+ if len (casier .profils_casier ) > 0 :
314
315
logger .debug ("Casier_Loi - " + nomCasier )
315
316
for xz in casier .profils_casier [0 ].xz :
316
- cursor .insertRow ([nomCasier , xz [0 ], xz [1 ]])
317
+ cursor .insertRow ([nomCasier , xz [0 ], xz [1 ]])
317
318
del cursor
318
-
319
+
319
320
edit .stopOperation ()
320
-
321
+
321
322
logger .info ("Enregistrement" )
322
323
edit .stopEditing (True )
323
-
324
+
324
325
325
326
except ExceptionCrue10 as e :
326
327
# edit.stopOperation()
327
328
# edit.stopEditing(False)
328
329
logger .critical (e )
329
-
330
-
330
+
331
+
331
332
except Exception as ex :
332
333
# edit.stopOperation()
333
334
# edit.stopEditing(False)
334
335
logger .critical (ex )
335
336
traceback .print_exc ()
336
-
337
337
338
- logger .info ("Fin du traitement" )
338
+
339
+ logger .info ("## Fin du traitement ##" )
0 commit comments