Skip to content

Commit

Permalink
plotting.geo: add a function to set line_geodata from bus geodata
Browse files Browse the repository at this point in the history
  • Loading branch information
rbolgaryn committed Feb 21, 2022
1 parent caa7c60 commit c268d59
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion pandapower/plotting/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and Energy System Technology (IEE), Kassel. All rights reserved.

import sys
from numpy import array
from numpy import array, setdiff1d

from pandapower.auxiliary import soft_dependency_error

Expand Down Expand Up @@ -102,6 +102,33 @@ def _convert_xy_epsg(x, y, epsg_in=4326, epsg_out=31467):
return transform(in_proj, out_proj, x, y)


def set_line_geodata_from_bus_geodata(net, line_index=None, overwrite=False):
"""
Sets coordinates in net.line_geodata based on the from_bus and to_bus x,y coordinates
in net.bus_geodata
:param net: pandapowerNet
:param line_index: index of lines, coordinates of which will be set from bus geodata (all lines if None)
:param overwrite: whether the existing coordinates in net.line_geodata must be overwritten
:return: None
"""
line_index = line_index if line_index is not None else net.line.index
if not overwrite:
line_index = setdiff1d(line_index, net.line_geodata.index)
failed = []
for lidx in line_index:
b1 = net.line.from_bus.at[lidx]
b2 = net.line.to_bus.at[lidx]
if b1 in net.bus_geodata.index and b2 in net.bus_geodata.index:
coords = [(net.bus_geodata.x.at[int(b1)], net.bus_geodata.y.at[int(b1)]),
(net.bus_geodata.x.at[int(b2)], net.bus_geodata.y.at[int(b2)])]
net.line_geodata.loc[lidx, "coords"] = coords
else:
failed.append(lidx)

if len(failed) > 0:
logger.info(f"failed to set coordinates of {len(failed)} lines")


def convert_gis_to_geodata(net, node_geodata=True, branch_geodata=True):
"""
Extracts information on bus and line geodata from the geometries of a geopandas geodataframe.
Expand Down

0 comments on commit c268d59

Please sign in to comment.