pyorps.raster.handler

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

Functions

create_test_tiff(output_path[, width, ...])

Creates a synthetic GeoTIFF file for testing with different patterns.

Classes

RasterHandler(raster_source, source_coords, ...)

Class for efficiently working with raster data while preserving geographic transformation information.

class pyorps.raster.handler.RasterHandler(raster_source, source_coords, target_coords, search_space_buffer_m=None, input_crs=None, apply_mask=True, outside_value=None, bands=None)[source]

Bases: object

Class for efficiently working with raster data while preserving geographic transformation information. Can be initialized with either a file path or directly with raster data, CRS, and transform.

Initialize a RasterHandler for working with raster data and coordinate transformations.

Creates a window and buffer geometry based on source and target coordinates: - If source and target are single coordinates: creates a line buffer - If source and/or target are lists of coordinates: creates a polygon buffer

Parameters:
  • raster_source (RasterDataset) – Either: - Path to the raster file (str), or - Tuple of (data_array, crs, transform)

  • source_coords (Tuple[float, float] | List[Tuple[float, float]]) – Source point(s) as (x, y) tuple or list of tuples

  • target_coords (Tuple[float, float] | List[Tuple[float, float]]) – Target point(s) as (x, y) tuple or list of tuples

  • search_space_buffer_m (float) – Buffer distance in map units (typically meters)

  • input_crs (str | None) – CRS of the input coordinates (e.g., ‘EPSG:4326’). If None, assumes same as raster

  • apply_mask (bool) – If True, apply the buffer mask after loading data

  • outside_value (Any | None) – Value to set for pixels outside the buffer (defaults to max value of the data type)

  • bands (List[int] | None) – List of bands to modify if apply_mask is True (1-based). If None, all bands are modified

search_space_buffer_m: float
buffer_geometry: Polygon
window: Window
window_transform: Affine
data: ndarray
__init__(raster_source, source_coords, target_coords, search_space_buffer_m=None, input_crs=None, apply_mask=True, outside_value=None, bands=None)[source]

Initialize a RasterHandler for working with raster data and coordinate transformations.

Creates a window and buffer geometry based on source and target coordinates: - If source and target are single coordinates: creates a line buffer - If source and/or target are lists of coordinates: creates a polygon buffer

Parameters:
  • raster_source (RasterDataset) – Either: - Path to the raster file (str), or - Tuple of (data_array, crs, transform)

  • source_coords (Tuple[float, float] | List[Tuple[float, float]]) – Source point(s) as (x, y) tuple or list of tuples

  • target_coords (Tuple[float, float] | List[Tuple[float, float]]) – Target point(s) as (x, y) tuple or list of tuples

  • search_space_buffer_m (float | None) – Buffer distance in map units (typically meters)

  • input_crs (str | None) – CRS of the input coordinates (e.g., ‘EPSG:4326’). If None, assumes same as raster

  • apply_mask (bool) – If True, apply the buffer mask after loading data

  • outside_value (Any | None) – Value to set for pixels outside the buffer (defaults to max value of the data type)

  • bands (List[int] | None) – List of bands to modify if apply_mask is True (1-based). If None, all bands are modified

raster_dataset: RasterDataset
estimate_buffer_width(source_coords, target_coords, min_buffer=200, max_buffer=4000, sample_radius=50)[source]

Estimate an appropriate buffer width for path finding based on terrain characteristics.

Parameters:
Returns:

Estimated optimal buffer width in meters

static max_distance_pair(coords1, coords2)[source]

Find the pair of coordinates (one from coords1, one from coords2) with the highest Euclidean distance.

Parameters:
Returns:

A tuple containing the two points with the maximum distance (point1, point2)

apply_geometry_mask(geometry, outside_value=None, bands=None)[source]

Set pixel values outside the given geometry to the specified value.

Parameters:
  • geometry (Polygon) – A shapely geometry object (Polygon)

  • outside_value (int | None) – Value to set for pixels outside the geometry

  • bands (list[int] | int | None) – List of bands to modify (1-based). If None, all bands are modified.

coords_to_indices(coords)[source]

Convert geographic coordinates to pixel row/column indices within this raster section.

Parameters:

coords (tuple[float, float] | list[float] | list[tuple[float, float] | list[float]]) – List of (x, y) coordinate tuples or a single coordinate tuple

Returns:

Array of (row, col) pixel indices

Return type:

numpy.ndarray

indices_to_coords(indices)[source]

Convert pixel indices to geographic coordinates.

Parameters:

indices (List[Tuple[int, int]]) – List of (row, col) pixel indices

Returns:

Array of (x, y) coordinates

Return type:

numpy.ndarray

save_section_as_raster(output_path)[source]

Save the section as a new raster file with proper geo referencing.

Parameters:

output_path (str) – Path for the output raster file

pyorps.raster.handler.create_test_tiff(output_path, width=100, height=100, transform=None, crs='EPSG:32632', pattern='random', bands=1, nodata=None)[source]

Creates a synthetic GeoTIFF file for testing with different patterns.

Parameters:
  • output_path (str) – Path to save the test GeoTIFF file

  • width (int) – Width of the raster in pixels

  • height (int) – Height of the raster in pixels

  • transform (Affine | None) – Affine transformation for the raster

  • crs – Coordinate reference system

  • pattern (str) – Data pattern - “random”, “gradient”, or “checkerboard”

  • bands (int) – Number of bands to create

  • nodata (int | None) – No data value

Returns:

An array which can be used as a test raster