diff --git a/wntr/gis/network.py b/wntr/gis/network.py index fd70ec924..86f399e30 100644 --- a/wntr/gis/network.py +++ b/wntr/gis/network.py @@ -203,7 +203,7 @@ def _create_wn(self, append=None): assert 'end_node_name' in element.columns df = element.reset_index() df.rename(columns={'index':'name'}, inplace=True) - # TODO: create vertices from LineString geometry + df['vertices'] = df.apply(lambda row: list(row.geometry.coords)[1:-1], axis=1) df.drop(columns=['geometry'], inplace=True) wn_dict['links'].extend(df.to_dict('records')) diff --git a/wntr/tests/test_gis.py b/wntr/tests/test_gis.py index b56b6b616..9772ceaec 100644 --- a/wntr/tests/test_gis.py +++ b/wntr/tests/test_gis.py @@ -43,6 +43,10 @@ def setUpClass(self): self.results = sim.run_sim() self.gis_data = self.wn.to_gis() + vertex_inp_file = join(datadir, "io.inp") + self.vertex_wn = self.wntr.network.WaterNetworkModel(vertex_inp_file) + self.vertex_gis_data = self.vertex_wn.to_gis() + polygon_pts = [[(25,80), (65,80), (65,60), (25,60)], [(25,60), (80,60), (80,30), (25,30)], [(40,50), (60,65), (60,15), (40,15)]] @@ -102,6 +106,11 @@ def test_gis_to_wn(self): G2 = wn2.to_graph() assert nx.is_isomorphic(G1, G2) + + # test vertices + vertex_wn2 = wntr.network.io.from_gis(self.vertex_gis_data) + for name, link in vertex_wn2.links(): + assert link.vertices == self.vertex_wn.get_link(name).vertices def test_intersect_points_with_polygons(self):