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
|
Creates a synthetic GeoTIFF file for testing with different patterns. |
Classes
|
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:
objectClass 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
- window_transform: Affine
- __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:
source_coords (tuple[float, float] | list[float] | list[tuple[float, float] | list[float]]) – (x, y) coordinates of the source point
target_coords (tuple[float, float] | list[float] | list[tuple[float, float] | list[float]]) – (x, y) coordinates of the target point
min_buffer (float) – Minimum buffer width to consider (meters)
max_buffer (float) – Maximum buffer width to consider (meters)
sample_radius (float) – Radius for sampling around the straight line to assess terrain complexity
- 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:
coords1 (tuple[float, float] | list[float] | list[tuple[float, float] | list[float]]) – Either a single coordinate tuple (x, y, …) or a list of coordinate tuples
coords2 (tuple[float, float] | list[float] | list[tuple[float, float] | list[float]]) – Either a single coordinate tuple (x, y, …) or a list of coordinate tuples
- 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.
- coords_to_indices(coords)[source]
Convert geographic coordinates to pixel row/column indices within this raster section.
- 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