Skip to content

Commit

Permalink
I fixed bugs to export shapefiles of valve and pumps. The script is g…
Browse files Browse the repository at this point in the history
…oing to update node id of pipeline which intersects valve and pump.
  • Loading branch information
Jin IGARASHI committed Oct 28, 2019
1 parent c15cbbe commit 57dcabb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
20 changes: 19 additions & 1 deletion epanet/layer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,22 @@ def createProjection(self, output_dir):
shutil.copy("./templates/wgs84_4326.prj","{0}.prj".format(output_dir))

def get_file_path(self, f):
return "{0}/{1}".format(f.name.replace(".inp", ""), self.layer)
return "{0}/{1}".format(f.name.replace(".inp", ""), self.layer)

def updatePipeNode(self, obj):
'''
To update pipe node which intersects valve or pump node.
:param obj: valve object or pump object shall be here
:return:
'''
target_key = ",".join([str(obj.lon), str(obj.lat)])
if target_key in self.coords.coordMap and self.coords.coordMap[target_key]:
coord = self.coords.coordMap[target_key]
nodeid = coord.id
for pipe in self.pipes:
if nodeid == pipe.node1:
pipe.set_node(obj.id, pipe.node2)
coord.id = obj.id
elif nodeid == pipe.node2:
pipe.set_node(pipe.node1, obj.id)
coord.id = obj.id
4 changes: 4 additions & 0 deletions epanet/pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def __init__(self, id, node1, node2, length, diameter):
self.minorloss = 0
self.status = "Open"

def set_node(self, node1, node2):
self.node1 = node1
self.node2 = node2

@staticmethod
def create_header(f):
f.writelines("[PIPES]\n")
Expand Down
1 change: 1 addition & 0 deletions epanet/pumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,6 @@ def export_shapefile(self, f):
for p in self.pumps:
_shp.point(float(p.lon), float(p.lat))
_shp.record(p.id, p.elevation, p.curve.head, p.curve.flow, None, "POWER {0}".format(str(1)))
self.updatePipeNode(p)
_shp.close()
self.createProjection(filename)
6 changes: 3 additions & 3 deletions epanet/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def execute(self):
tanks.export(f)
#join lists of pipes id which duplicates from pumps and valves.
del_pipes_id = []
del_pipes_id.extend( pumps.get_del_pipes_id_for_inp())
del_pipes_id.extend(pumps.get_del_pipes_id_for_inp())
del_pipes_id.extend(valves.get_del_pipes_id_for_inp())
pipes.export(f, del_pipes_id)
pumps.export(f)
Expand All @@ -101,10 +101,10 @@ def execute(self):
del_coords_id = []
del_coords_id.extend(pumps.get_del_coords_id_for_inp())
del_coords_id.extend(valves.get_del_coords_id_for_inp())
coords.export_shapefile(f, del_coords_id)
pipes.export_shapefile(f)
tanks.export_shapefile(f)
reservoirs.export_shapefile(f)
pumps.export_shapefile(f)
valves.export_shapefile(f)
coords.export_shapefile(f, del_coords_id)
pipes.export_shapefile(f)
shutil.copy("./templates/template_qgs_project.qgz", "{0}/{1}_{2}.qgz".format(f.name.replace(".inp", ""), self.wss_id, self.wss_name))
2 changes: 2 additions & 0 deletions epanet/valves.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,7 @@ def export_shapefile(self, f):
for v in self.valves:
_shp.point(float(v.lon), float(v.lat))
_shp.record(v.id, v.elevation, v.diameter, v.valve_type, v.setting, v.minor_loss)
self.updatePipeNode(v)
_shp.close()
self.createProjection(filename)

0 comments on commit 57dcabb

Please sign in to comment.