Skip to content

Commit 5d56693

Browse files
authored
Mise à jour des scripts GéoGAMA-Crue (support g1.3) (#10)
1 parent 9819b19 commit 5d56693

File tree

3 files changed

+263
-277
lines changed

3 files changed

+263
-277
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Journal des modifications
22
=========================
33

4+
## [] - En cours
5+
- Corrections scripts geogama
6+
7+
48
## [4.2] - 2024-09-27
59
### Nouveautés
610
- Prise en compte du déplacement de `Pm_TolStQ` du CCM vers le OPTI pour les initialisations de type Saint-Venant (g1.3)

geogama/crue_vers_geogama.py

Lines changed: 86 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
# coding: utf-8
22
"""
3-
Lecture d'un sous-modèle Crue10
3+
Lecture de plusieurs sous-modèles Crue10
44
"""
5-
import os.path
6-
import sys
7-
import arcpy
85
import logging
6+
import math
97
import re
8+
import sys
109
import traceback
10+
1111
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
1413
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
1715

16+
import arcpy
1817

19-
#Parametres
20-
GDB = arcpy.GetParameterAsText(0)
21-
EDU_PATH = arcpy.GetParameterAsText(1)
22-
LST_SOUSMODELE = arcpy.GetParameterAsText(2).split(";")
2318

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']
2829

2930

30-
#Constantes
31+
# Constants
3132
FCLASS_NOEUD = "EMG/Noeud"
3233
FCLASS_CASIER = "EMG/Casier"
3334
FCLASS_BRANCHE = "EMG/Branche"
@@ -38,10 +39,10 @@
3839
TABLE_CASIER_LOI = "Casier_Loi"
3940
FCLASS_SEUIL_ELEM = "Seuil_Elem"
4041

41-
4242
arcpy.env.workspace = GDB
4343

44-
#Init Logger
44+
45+
# Init Logger
4546
formatter = logging.Formatter('%(levelname)s: %(message)s')
4647

4748
logger.setLevel(logging.DEBUG)
@@ -57,6 +58,8 @@
5758
# logger.addHandler(handler2)
5859

5960

61+
# Functions
62+
6063
def truncateAllClass():
6164
logger.info("Vidage des tables")
6265

@@ -70,9 +73,11 @@ def truncateAllClass():
7073
arcpy.DeleteRows_management(GDB+"/"+TABLE_CASIER_LOI)
7174
arcpy.DeleteRows_management(GDB+"/"+FCLASS_SEUIL_ELEM)
7275

76+
7377
def getDist(ptA, ptB):
7478
return math.sqrt((ptA.X - ptB.X)**2 + (ptA.Y - ptB.Y)**2)
7579

80+
7681
def getMPolyline(coords, distanceTot):
7782
points = arcpy.Array()
7883
currentDist = 0
@@ -84,18 +89,18 @@ def getMPolyline(coords, distanceTot):
8489
if not lastPoint is None:
8590
dist = getDist(point, lastPoint)
8691
currentDist += dist
87-
92+
8893
point.M = currentDist
8994
points.append(point)
90-
95+
9196
lastPoint = arcpy.Point(x, y)
92-
97+
9398
if distanceTot is not None:
9499
ratio = distanceTot / currentDist
95-
100+
96101
for point in points:
97102
point.M = point.M * ratio
98-
103+
99104
return arcpy.Polyline(points)
100105

101106

@@ -110,51 +115,48 @@ def getTroncon(emh_name):
110115
return ''
111116
return m.group('troncon')[:10]
112117

113-
114-
try:
115-
# if True:
116118

119+
try:
117120
logger.info("Parametres")
118121
logger.info(GDB)
119122
logger.info(EDU_PATH)
120123
logger.info(LST_SOUSMODELE)
121124

122-
123-
#Ouverture session d'édition
125+
# Ouverture session d'édition
124126
edit = arcpy.da.Editor(arcpy.env.workspace)
125127
edit.startEditing(False, False)
126128

127129
# edit.startOperation()
128130

129-
#Vidage des tables
131+
# Vidage des tables
130132
# truncateAllClass()
131-
133+
132134
# 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
135137
hashNoeuds = {}
136-
138+
137139
# Get Etude
138140
study = Etude(EDU_PATH)
139-
141+
140142
for sm_elem in LST_SOUSMODELE:
141143
logger.info("Lecture Sous-modele- " + sm_elem)
142144
# Get Sous-modele
143145
sous_modele = study.get_sous_modele(sm_elem)
144146
sous_modele.read_all()
145-
146-
#Suppression sections interpolées
147+
148+
# Suppression sections interpolées
147149
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
150152
sous_modele.replace_zero_xp_sectionaval()
151-
153+
152154
edit.startOperation()
153-
155+
154156
logger.info("Noeuds - " + str(len(sous_modele.noeuds)))
155157
with arcpy.da.InsertCursor(FCLASS_NOEUD, ["Troncon", "Nom_noeud", "SHAPE@"]) as cursor:
156158
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é
158160
if nomNoeud not in hashNoeuds:
159161
hashNoeuds[nomNoeud] = True
160162
noeud = sous_modele.noeuds[nomNoeud]
@@ -165,7 +167,7 @@ def getTroncon(emh_name):
165167

166168
edit.stopOperation()
167169
edit.startOperation()
168-
170+
169171
logger.info("Casiers - " + str(len(sous_modele.casiers)))
170172
with arcpy.da.InsertCursor(FCLASS_CASIER, ["Nom_casier", "Nom_noeud", "Distance_appli", "SHAPE@"]) as cursor:
171173
for nomCasier in sous_modele.casiers:
@@ -176,18 +178,18 @@ def getTroncon(emh_name):
176178

177179
edit.stopOperation()
178180
edit.startOperation()
179-
181+
180182
logger.info("Branches - " + str(len(sous_modele.branches)))
181183
with arcpy.da.InsertCursor(FCLASS_BRANCHE, ["Troncon", "Nom_branche", "Type_branche", "Longueur", "Nom_noeud_amont", "Nom_noeud_aval", "IsActif", "SHAPE@"]) as cursor:
182184
for nomBranche in sous_modele.branches:
183185
logger.debug("Branche - " + nomBranche)
184186
branche = sous_modele.branches[nomBranche]
185187
polyline = getMPolyline(branche.geom.coords, branche.length)
186188
cursor.insertRow([getTroncon(nomBranche), nomBranche, branche.type, branche.length, branche.noeud_amont.id, branche.noeud_aval.id, branche.is_active, polyline])
187-
189+
188190
edit.stopOperation()
189191
edit.startOperation()
190-
192+
191193
logger.info("Sections - " + str(len(sous_modele.sections)))
192194
listSectionProfil = []
193195
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):
200202
dz = None
201203
if isinstance(section, SectionSansGeometrie):
202204
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
204206
elif isinstance(section, SectionProfil):
205207
typeSection = 2
206-
#Merge lis numerotes
208+
# Merge lits numérotés
207209
section.merge_consecutive_lit_numerotes()
208210
listSectionProfil.append(section)
209211
elif isinstance(section, SectionIdem):
210212
typeSection = 3
211213
nom_section_parent = section.section_reference.id
212214
dz = section.dz_section_reference
213215
cursor.insertRow([getTroncon(nomBranche), nomSection, typeSection, nomBranche, section.xp ,nom_section_parent, dz])
214-
216+
215217
edit.stopOperation()
216218
edit.startOperation()
217-
219+
218220
logger.info("ProfilPoints (par profil) - " + str(len(listSectionProfil)))
219221
list_limite_point = []
220222
with arcpy.da.InsertCursor(FCLASS_PROFIL_POINT, ["Nom_section", "Absc_proj", "Z", "SHAPE@"]) as cursor:
@@ -223,35 +225,33 @@ def getTroncon(emh_name):
223225
logger.debug("Profil - " + profil.id)
224226
# logger.debug("XY - " + str(len(profil.geom_trace.coords)))
225227
# logger.debug("XZ - " + str(len(profil.xz)))
226-
228+
227229
line = arcpy.Polyline(arcpy.Array([arcpy.Point(*coords) for coords in profil.geom_trace.coords[:]]))
228230
i = 0
229231
premier_point_x = 0
230232
hashOIDPointParAbs = {}
231233
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
234236
if i == 0:
235237
point = line.positionAlongLine(p[0])
236238
premier_point_x = p[0]
237239
else:
238240
point = line.positionAlongLine(p[0] - premier_point_x)
239-
241+
240242
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":
247248
id_limite = 14
248-
elif limit_geom.id == "Et_Thalweg":
249+
elif limite.id == "Et_Thalweg":
249250
id_limite = 13
250251
else:
251252
continue
252-
list_limite_point.append([oidPoint, id_limite])
253-
# print oidPoint
254-
253+
list_limite_point.append([oidPoint, id_limite])
254+
255255
for j in range(0, 6):
256256
if j == 5: # on prend le max
257257
xt = profil.lits_numerotes[j - 1].xt_max
@@ -262,77 +262,78 @@ def getTroncon(emh_name):
262262
list_limite_point.append([oidPoint, id_limite])
263263
else:
264264
logger.warning("Profil sans geom - " + profil.id)
265-
265+
266266
del cursor
267-
267+
268268
edit.stopOperation()
269269
edit.startOperation()
270-
270+
271271
logger.info("Limites - " + str(len(list_limite_point)))
272272
with arcpy.da.InsertCursor(TABLE_LIMITE, ["OID_Profil_Point", "Nom_Limite"]) as cursor_limite:
273273
for limite in list_limite_point:
274274
cursor_limite.insertRow(limite)
275-
del cursor_limite
275+
del cursor_limite
276276

277277
edit.stopOperation()
278278
edit.startOperation()
279279

280-
logger.info("Porfil_Trace - " + str(len(listSectionProfil)))
280+
logger.info("Profil_Trace - " + str(len(listSectionProfil)))
281281
with arcpy.da.InsertCursor(FCLASS_PROFIL_TRACE, ["Nom_section", "SHAPE@"]) as cursor:
282282
for profil in listSectionProfil:
283283
if profil.geom_trace is not None:
284284
logger.debug("Profil - " + profil.id)
285285
line = arcpy.Polyline(arcpy.Array([arcpy.Point(*coords) for coords in profil.geom_trace.coords[:]]))
286286
cursor.insertRow([profil.id, line])
287287
del cursor
288-
288+
289289
edit.stopOperation()
290290
edit.startOperation()
291-
291+
292292
logger.info("Seuil_Elem")
293293
with arcpy.da.InsertCursor(FCLASS_SEUIL_ELEM, ["Nom_branche", "Largeur", "Z_Seuil", "CoefD", "CoefPDC"]) as cursor:
294294
for nomBranche in sous_modele.branches:
295295
branche = sous_modele.branches[nomBranche]
296296
if isinstance(branche, BrancheAvecElementsSeuil):
297297
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
299299
cursor.insertRow([nomBranche, seuil[0], seuil[1], seuil[2], seuil[3]])
300300
del cursor
301-
301+
302302
edit.stopOperation()
303303
edit.startOperation()
304-
304+
305305
logger.info("Casier_Loi")
306306
with arcpy.da.InsertCursor(TABLE_CASIER_LOI, ["Nom_casier", "Xt", "Cote"]) as cursor:
307307
for nomCasier in sous_modele.casiers:
308308
casier = sous_modele.casiers[nomCasier]
309-
if len(casier.profils_casier) > 1 :
309+
310+
if len(casier.profils_casier) > 1:
310311
logger.debug("Casier_Loi - Fusion - " + nomCasier)
311312
casier.fusion_profil_casiers()
312-
313-
if len(casier.profils_casier) > 0 :
313+
314+
if len(casier.profils_casier) > 0:
314315
logger.debug("Casier_Loi - " + nomCasier)
315316
for xz in casier.profils_casier[0].xz:
316-
cursor.insertRow([nomCasier, xz[0], xz[1]])
317+
cursor.insertRow([nomCasier, xz[0], xz[1]])
317318
del cursor
318-
319+
319320
edit.stopOperation()
320-
321+
321322
logger.info("Enregistrement")
322323
edit.stopEditing(True)
323-
324+
324325

325326
except ExceptionCrue10 as e:
326327
# edit.stopOperation()
327328
# edit.stopEditing(False)
328329
logger.critical(e)
329-
330-
330+
331+
331332
except Exception as ex:
332333
# edit.stopOperation()
333334
# edit.stopEditing(False)
334335
logger.critical(ex)
335336
traceback.print_exc()
336-
337337

338-
logger.info("Fin du traitement")
338+
339+
logger.info("## Fin du traitement ##")

0 commit comments

Comments
 (0)