Skip to content

Commit

Permalink
Merge pull request #388 from kbonney/gis_vertices
Browse files Browse the repository at this point in the history
add vertices from line string geometries when convering GIS object to…
  • Loading branch information
kaklise authored Nov 2, 2023
2 parents fb3c07b + bdea21e commit 6b63bae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion wntr/gis/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down
9 changes: 9 additions & 0 deletions wntr/tests/test_gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]]
Expand Down Expand Up @@ -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):

Expand Down

0 comments on commit 6b63bae

Please sign in to comment.