xrspatial.cost_distance.cost_distance#

xrspatial.cost_distance.cost_distance(raster: DataArray, friction: DataArray, x: str = 'x', y: str = 'y', target_values: list = [], max_cost: float = inf, connectivity: int = 8) DataArray[source]#

Compute accumulated cost-distance through a friction surface.

For every pixel, computes the minimum accumulated traversal cost to reach the nearest target pixel, where traversal cost along each edge equals geometric_distance * mean_friction_of_endpoints.

Parameters:
  • raster (xr.DataArray or xr.Dataset) – 2-D source raster. Target pixels are identified by non-zero finite values (or values in target_values).

  • friction (xr.DataArray) – 2-D friction (cost) surface. Must have the same shape and coordinates as raster. Values must be positive and finite for passable cells; NaN or <= 0 marks impassable barriers.

  • x (str, default='x') – Name of the x coordinate.

  • y (str, default='y') – Name of the y coordinate.

  • target_values (list, optional) – Specific pixel values in raster to treat as sources. If empty, all non-zero finite pixels are sources.

  • max_cost (float, default=np.inf) – Maximum accumulated cost. Pixels whose least-cost path exceeds this budget are set to NaN. A finite value enables efficient Dask parallelisation via map_overlap.

  • connectivity (int, default=8) – Pixel connectivity: 4 (cardinal only) or 8 (cardinal + diagonal).

Returns:

2-D array of accumulated cost-distance values (float32). Source pixels have cost 0. Unreachable pixels are NaN.

Return type:

xr.DataArray or xr.Dataset