pyorps.core.path

PYORPS: An Open-Source Tool for Automated Power Line Routing

Reference: [1] Hofmann, M., Stetz, T., Kammer, F., Repo, S.: ‘PYORPS: An Open-Source Tool for

Automated Power Line Routing’, CIRED 2025 - 28th Conference and Exhibition on Electricity Distribution, 16 - 19 June 2025, Geneva, Switzerland

Classes

Path(source, target, algorithm, graph_api, ...)

Dataclass representing a path in a raster graph.

PathCollection()

Container for Path objects with O(1) retrieval by path ID and O(n) lookup for source and target information.

class pyorps.core.path.Path(source, target, algorithm, graph_api, path_indices, path_coords, path_geometry, euclidean_distance, runtimes, path_id, search_space_buffer_m, neighborhood, total_length=None, total_cost=None, length_by_category=None, length_by_category_percent=None)[source]

Bases: object

Dataclass representing a path in a raster graph. Used as container for all path metrics and information.

Parameters:
source: tuple[float, float] | list[float]
target: tuple[float, float] | list[float]
algorithm: str
graph_api: str
path_indices: list[int | int32 | int64 | uint32 | uint64] | ndarray[int]
path_coords: list[tuple[float, float] | list[float]]
path_geometry: LineString
euclidean_distance: float
runtimes: dict[str, float]
path_id: int
search_space_buffer_m: float
neighborhood: str
total_length: float | None = None
total_cost: float | None = None
length_by_category: dict[float, float] | None = None
length_by_category_percent: dict[float, float] | None = None
to_geodataframe_dict()[source]

Convert Path object to a dictionary suitable for GeoDataFrame creation.

Returns:

dictionary with path data formatted for GeoDataFrame

Return type:

dict

__str__()[source]

Return a string representation of the path including the path_id, source and target, as well as the path’s total length and total cost.

Returns:

A string representation of the path.

Return type:

str

__repr__()[source]

Return a detailed string representation of the path.

Return type:

str

__eq__(other)[source]

Check for equality between two paths.

Parameters:

other (Any)

Return type:

bool

__init__(source, target, algorithm, graph_api, path_indices, path_coords, path_geometry, euclidean_distance, runtimes, path_id, search_space_buffer_m, neighborhood, total_length=None, total_cost=None, length_by_category=None, length_by_category_percent=None)
Parameters:
Return type:

None

class pyorps.core.path.PathCollection[source]

Bases: object

Container for Path objects with O(1) retrieval by path ID and O(n) lookup for source and target information. Paths can be added with new id by replacing a Path object with the same ID already existing in th PathCollection.

Create an empty PathCollection for collecting Paths with their IDs in a dictionary.

__init__()[source]

Create an empty PathCollection for collecting Paths with their IDs in a dictionary.

add(path, replace=False)[source]

Add a path to the PathCollection. If the Path’s path_id is None or if replace is False, the path_id of the Path object will set to self._next_id and self._next_id will be incremented. If the Path’s path_id is not None and replace is True, a Path with the same path_id (if present) will be replaced with the new Path object.

Parameters:
  • path (Path) – A Path object which should be added to the PathCollection.

  • replace (bool) – Whether to replace an existing Path object with the same path_id (if present) or not.

Return type:

None

get(path_id=None, source=None, target=None)[source]

Retrieve a stored path by ID, or by source AND target.

Parameters:
  • path_id (int) – The ID of the Path object to retrieve (must be None if path should be found by source and target)

  • source (Any) – The source Path object to retrieve (only used if path_id is None and target os set too; neglected otherwise)

  • target (Any) – The target Path object to retrieve (only used if path_id is None and target os set too; neglected otherwise)

Returns:

The Path object with the specified ID or source/target pair. None if no such path exists.

Return type:

Path | None

to_geodataframe_records()[source]

Convert all paths to a list of dictionaries suitable for a GeoDataFrame.

Returns:

List of dictionaries with path data formatted for a GeoDataFrame

Return type:

list

__iter__()[source]

Iterate through all paths in the PathCollection.

__len__()[source]

Return the number of paths in the PathCollection.

__getitem__(path_id)[source]

Get path by path_id of the Path object from the PathCollection.

__str__()[source]

Return a string representation of the path collection.

Return type:

str

__repr__()[source]

Return a detailed string representation of the path collection.

Return type:

str

property all

Return all Path objects from the values of the PathCollection’s _paths dictionary as a list.

Returns:

A list of all Path objects in the PathCollection.

__eq__(other)[source]

Check if PathCollections are equal. They do not have to be in the same order to be equal!

Return type:

bool