Skip to content

Commit 25ff02d

Browse files
first running version with z coords
1 parent a23c8db commit 25ff02d

3 files changed

+50
-11
lines changed

g_s_various_functions.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ def use_z_if_available(
6060
if geom_type == 'lines':
6161
if use_z_bool:
6262
# if not na
63-
#replace_lst = [res[l_name]['Z_Coord'].tolist()[0] for l_name in df_multi['Name']]
64-
df['InOffset'] = [res[l_name]['Z_Coord'].tolist()[0] for l_name in df_multi['Name']]
65-
df['OutOffset'] = [res[l_name]['Z_Coord'].tolist()[-1] for l_name in df_multi['Name']]
63+
df['InOffset'] = [coords[l_name]['Z_Coord'].tolist()[0] for l_name in df['Name']]
64+
df['OutOffset'] = [coords[l_name]['Z_Coord'].tolist()[-1] for l_name in df['Name']]
6665
coords = {
6766
l_name: df_coord[
6867
['X_Coord', 'Y_Coord']
@@ -195,7 +194,7 @@ def extract_xy_from_area(geom_row):
195194
:return: pd.DataFrame
196195
"""
197196
xy_list = [[str(v.x()), str(v.y())] for v in geom_row.vertices()]
198-
xy_df = pd.DataFrame(xy_list, columns=['x', 'y'])
197+
xy_df = pd.DataFrame(xy_list, columns=['X_Coord', 'Y_Coord'])
199198
return xy_df
200199

201200
# functions for data in tables

g_s_write_inp.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ def compose_dict_text(dict_i, section, inflow_keys_dict):
348348
for vert_key in vertices_dict.keys():
349349
vert_df = vertices_dict[vert_key].copy()
350350
vert_df['vertice'] = vert_key
351-
vert_df = vert_df[['vertice', 'x', 'y']]
351+
print(vert_df)
352+
vert_df = vert_df[['vertice', 'X_Coord', 'Y_Coord']]
352353
file1.write(vert_df.to_string(header=False, index=False))
353354
file1.write('\n')
354355
file1.write('\n')
@@ -361,7 +362,7 @@ def compose_dict_text(dict_i, section, inflow_keys_dict):
361362
for pol_key in polygons_dict.keys():
362363
pol_df = polygons_dict[pol_key].copy()
363364
pol_df['subcatch']=pol_key
364-
pol_df = pol_df[['subcatch', 'x', 'y']]
365+
pol_df = pol_df[['subcatch', 'X_Coord', 'Y_Coord']]
365366
file1.write(pol_df.to_string(header=False, index=False))
366367
file1.write('\n')
367368
file1.write('\n')

generate_swmm_inp_file.py

+44-5
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ def processAlgorithm(self, parameters, context, feedback):
352352
file_transects = self.parameterAsString(parameters, self.FILE_TRANSECTS, context)
353353
file_streets = self.parameterAsString(parameters, self.FILE_STREETS, context)
354354

355+
355356
# options table
356357
if file_options != '':
357358
raw_data_dict['options_df'] = read_data_from_table_direct(
@@ -448,6 +449,42 @@ def get_annotations_from_raw_df(df_raw):
448449
)
449450
options_df, main_infiltration_method = get_options_from_table(raw_data_dict['options_df'].copy())
450451
inp_dict['OPTIONS'] = {'data': options_df}
452+
453+
454+
# main handler
455+
def layers_export_handler(section):
456+
# data/section in raw_data_dict.keys?
457+
# check columns
458+
## what to check
459+
if tables:
460+
cols_to_check = list(def_tables_dict[section]['tables'][subtable].keys())
461+
f_name = str(section)+' file' # replace with filename
462+
else:
463+
cols_to_check = list(def_qgis_fields_dict[section].keys())
464+
check_columns(
465+
f_name,
466+
cols_to_check,
467+
raw_data_dict['options_df'].keys()
468+
)
469+
# data preparation
470+
processed_df = None
471+
if geometry:
472+
# extract geometry
473+
sections_coords = get_coords_from_geometry(raw_df)
474+
use_z_if_available()
475+
adjust_geometry()
476+
# annotations
477+
annotations_df = get_annotations_from_raw_df(
478+
raw_data_dict['conduits_raw'].copy()
479+
)
480+
if annotations_df is not None:
481+
annotations = True
482+
else:
483+
annotations = False
484+
# write to inp dict
485+
inp_dict[section] = {'data': processed_df}
486+
if annotations:
487+
inp_dict[section]['annotations'] = annotations_df
451488

452489
# subcatchments
453490
if 'subcatchments_raw' in raw_data_dict.keys():
@@ -496,7 +533,7 @@ def get_annotations_from_raw_df(df_raw):
496533
conduits_verts,
497534
use_z_bool,
498535
feedback,
499-
'Lines',
536+
'lines',
500537
layer_name='conduits_layer'
501538
)
502539
conduits_verts = {k: del_first_last_vt(v) for k, v in conduits_verts.items() if len(v) > 2} # first and last vertices are in nodes coordinates anyway
@@ -525,6 +562,7 @@ def get_annotations_from_raw_df(df_raw):
525562
pumps_verts,
526563
False,
527564
feedback,
565+
geom_type = 'lines'
528566
)
529567
pumps_verts = {k: del_first_last_vt(v) for k, v in pumps_verts.items() if len(v) > 2}
530568
pumps_inp_cols = def_sections_dict['PUMPS']
@@ -548,6 +586,7 @@ def get_annotations_from_raw_df(df_raw):
548586
weirs_verts,
549587
False,
550588
feedback,
589+
geom_type = 'lines'
551590
)
552591
weirs_verts = {k: del_first_last_vt(v) for k, v in weirs_verts.items() if len(v) > 2} # first and last vertices are in nodes coordinates anyway
553592
inp_dict['VERTICES']['data'].update(weirs_verts)
@@ -578,6 +617,7 @@ def get_annotations_from_raw_df(df_raw):
578617
outlets_verts,
579618
False,
580619
feedback,
620+
geom_type = 'lines'
581621
)
582622
outlets_verts = {k: del_first_last_vt(v) for k, v in outlets_verts.items() if len(v) > 2}
583623
inp_dict['VERTICES']['data'].update(outlets_verts)
@@ -611,6 +651,7 @@ def get_annotations_from_raw_df(df_raw):
611651
orifices_verts,
612652
False,
613653
feedback,
654+
geom_type = 'lines'
614655
)
615656
orifices_verts = {k: del_first_last_vt(v) for k, v in orifices_verts.items() if len(v) > 2} # first and last vertices are in nodes coordinates anyway
616657
inp_dict['VERTICES']['data'].update(orifices_verts)
@@ -647,8 +688,7 @@ def get_annotations_from_raw_df(df_raw):
647688
junctions_annot = get_annotations_from_raw_df(
648689
raw_data_dict['junctions_raw'].copy()
649690
)
650-
junctions_df['X_Coord'], junctions_df['Y_Coord'] = get_coords_from_geometry(junctions_df)
651-
junctions_coords = junctions_df[['Name', 'X_Coord', 'Y_Coord']]
691+
junctions_coords = get_coords_from_geometry(junctions_df)
652692
junctions_inp_cols = def_sections_dict['JUNCTIONS']
653693
junctions_df, junctions_coords = use_z_if_available(
654694
junctions_df,
@@ -678,8 +718,7 @@ def get_annotations_from_raw_df(df_raw):
678718
)
679719
from .g_s_nodes import get_outfalls_from_shapefile
680720
outfalls_df = get_outfalls_from_shapefile(raw_data_dict['outfalls_raw'].copy())
681-
outfalls_df['X_Coord'], outfalls_df['Y_Coord'] = get_coords_from_geometry(outfalls_df)
682-
outfalls_coords = outfalls_df[['Name', 'X_Coord', 'Y_Coord']]
721+
outfalls_coords = get_coords_from_geometry(outfalls_df)
683722
outfalls_annot = get_annotations_from_raw_df(
684723
raw_data_dict['outfalls_raw'].copy()
685724
)

0 commit comments

Comments
 (0)