from salome.hydrotools.hydroGeoMeshUtils import loadImage, GeolocaliseImageCoords, GeolocaliseImageReference
from salome.hydrotools.hydroGeoMeshUtils import importPolylines, importBathymetry, createImmersibleZone, mergePolylines, getChildrenInStudy
+from salome.hydrotools.hydroGeoMeshUtils import loadStricklerTable, loadLandCoverMap
hydro_doc = HYDROData_Document.Document()
litMajeur = createImmersibleZone(hydro_doc, "litMajeur", lits_majeur[0], garonne_point_L93, True, 3)
litMineur = createImmersibleZone(hydro_doc, "litMineur", garonnes[0], garonne_point_L93, True, 4)
-def_strickler_table_06 = hydro_doc.CreateObject( KIND_STRICKLER_TABLE )
-def_strickler_table_06.Import(os.path.join(HYDRO_RESOURCES, "def_strickler_table_06.txt"))
-def_strickler_table_06.SetName( "def_strickler_table_06" )
-def_strickler_table_06.SetAttrName( "CODE_06" )
-def_strickler_table_06.Update()
-
-import shapefile
-sf = shapefile.Reader(os.path.join(HYDRO_SAMPLES, 'HYDRO', "CLC_decoupe.shp"))
-#print(sf)
-fields = sf.fields
-records = sf.records()
-fieldNames = [a[0] for a in fields]
-'CODE_06' in fieldNames
-dic = {}
-for r in records:
- code = r.as_dict()['CODE_06']
- if code in dic:
- dic[code] = dic[code] + 1
- else:
- dic[code] = 1
-attr_values = [a for a in dic]
-
-alltypes = []
-allvalues = []
-code = ""
-l = 0
-with open(os.path.join(HYDRO_RESOURCES, "def_strickler_table_06.txt")) as f:
- for line in f:
- items = line.split('"')
- if l ==0:
- code = line.split()[0]
- else:
- alltypes.append(items[1])
- itm2 = items[-1].split()
- allvalues.append(itm2[-1])
- l = l + 1
-
-while code[0] != 'C':
- code = code[1:] # get rid of encoding
-
-types = [t for v,t in zip(allvalues, alltypes) if v in attr_values]
-
-CLC_decoupe = hydro_doc.CreateObject( KIND_LAND_COVER_MAP )
-CLC_decoupe.SetName( "CLC_decoupe" )
-CLC_decoupe.SetZLevel( 13 )
-if not CLC_decoupe.ImportSHP( os.path.join(HYDRO_SAMPLES, 'HYDRO', 'CLC_decoupe.shp')):
- raise ValueError('problem while loading LandCoverMap shape')
-#if CLC_decoupe.ImportDBF( os.path.join(HYDRO_SAMPLES, 'HYDRO', 'CLC_decoupe.dbf'), 'CODE_06', attr_values, types ) != CLC_decoupe.DBFStatus_OK:
-if CLC_decoupe.ImportDBF( os.path.join(HYDRO_SAMPLES, 'HYDRO', 'CLC_decoupe.dbf'), code, allvalues, alltypes ) != CLC_decoupe.DBFStatus_OK:
- raise ValueError('problem while loading LandCoverMap data base')
-CLC_decoupe.Update()
-
-
+tableStrickler, codeStrickler = loadStricklerTable(hydro_doc, os.path.join(HYDRO_RESOURCES, "def_strickler_table_06.txt"))
+landCoverMap = loadLandCoverMap(hydro_doc, os.path.join(HYDRO_SAMPLES, 'HYDRO', 'CLC_decoupe.shp'),
+ os.path.join(HYDRO_RESOURCES, "def_strickler_table_06.txt"), 10)
# Calculation case
garonne_1 = hydro_doc.CreateObject( KIND_CALCULATION )
garonne_1.AddGeometryGroup( case_geom_group )
case_geom_group = litMajeur.GetGroup( 0 )
garonne_1.AddGeometryGroup( case_geom_group )
-garonne_1.SetBoundaryPolyline( domaine )
-garonne_1.SetStricklerTable( def_strickler_table_06 )
-garonne_1.SetLandCoverMap( CLC_decoupe )
+garonne_1.SetBoundaryPolyline( limites_domaine[0] )
+garonne_1.SetStricklerTable( tableStrickler )
+garonne_1.SetLandCoverMap( landCoverMap )
# Start the algorithm of the partition and assignment
garonne_1.Update()
embankment.Update()
return embankment
+def loadStricklerTable(document, stricklerFile):
+ """
+ Load a table of Corine Land Cover types and codes, used for Strickler coefficients (editable text format)
+ parameters:
+ document: current HYDROData document
+ stricklerFile: full path of the table (*.txt)
+ return:
+ table loaded, code corresponding to Corine Land Cover used for the table ('CODE_06', 'CODE_12'...)
+ """
+ code = ""
+ with open(stricklerFile) as f:
+ line = f.readline()
+ code = line.split()[0]
+ a = os.path.splitext(stricklerFile)
+ stricklerName = os.path.basename(a[0])
+ strickler_table = document.CreateObject( KIND_STRICKLER_TABLE )
+ strickler_table.Import(stricklerFile)
+ strickler_table.SetName(stricklerName)
+ strickler_table.SetAttrName(code)
+ strickler_table.Update()
+ return strickler_table, code
+
+def loadLandCoverMap(document, landCoverFile, stricklerFile, displayLevel):
+ """
+ Load a Corine Land Cover Map
+ parameters:
+ document: current HYDROData document
+ landCoverFile: shapeFile defining the map (*.shp)
+ stricklerFile: full path of the table (*.txt)
+ displayLevel : z level for 2D representation: high values are drawn above low values
+ return:
+ land cover map loaded
+ """
+ alltypes = []
+ allvalues = []
+ code = ""
+ l = 0
+ with open(stricklerFile) as f:
+ for line in f:
+ items = line.split('"')
+ if l ==0:
+ code = line.split()[0]
+ else:
+ alltypes.append(items[1])
+ itm2 = items[-1].split()
+ allvalues.append(itm2[-1])
+ l = l + 1
+ print(alltypes)
+ print(allvalues)
+ while code[0] != 'C': # the code begins with 'C'
+ code = code[1:] # get rid of encoding
+ print (code)
+ a = os.path.splitext(landCoverFile)
+ landCoverName = os.path.basename(a[0])
+ landCoverDB = a[0] + '.dbf'
+ landCover = document.CreateObject(KIND_LAND_COVER_MAP)
+ print(landCoverFile)
+ print(landCoverDB)
+ print(landCoverName)
+ landCover.SetName(landCoverName)
+ landCover.SetZLevel(displayLevel)
+ if not landCover.ImportSHP(landCoverFile):
+ raise ValueError('problem while loading LandCoverMap shape')
+ if landCover.ImportDBF(landCoverDB, code, allvalues, alltypes ) != landCover.DBFStatus_OK:
+ raise ValueError('problem while loading LandCoverMap data base')
+ landCover.Update()
+ return landCover
+
+
+
+
+