Skip to content

Commit dcda2de

Browse files
authored
Fixes #733: add cost_distance() for weighted proximity (#859)
* Fixes #733: add cost_distance() for weighted proximity via multi-source Dijkstra New cost_distance() function computes minimum accumulated traversal cost through a friction surface to reach the nearest target pixel, the raster equivalent of GRASS r.cost / ArcGIS Cost Distance. Supports numpy and dask+numpy backends, 4/8-connectivity, max_cost truncation for dask scalability, and xr.Dataset input via @supports_dataset. Includes 19 tests and an example notebook comparing cost_distance with proximity. * Add cost_distance to README feature matrix * Add k-d tree dask path for unbounded proximity to avoid single-chunk rechunk The existing dask proximity path rechunked the entire raster into one chunk when max_distance was unbounded, defeating dask's out-of-core purpose. This adds a two-phase scipy.spatial.cKDTree approach: Phase 1 streams chunks to collect target coordinates, Phase 2 queries the tree per-chunk via map_blocks. Exact results, memory proportional to targets not raster size. Supports EUCLIDEAN and MANHATTAN metrics; GREAT_CIRCLE/ALLOCATION/DIRECTION fall back to the existing single-chunk path. Gracefully degrades when scipy is absent.
1 parent 97e28c4 commit dcda2de

File tree

8 files changed

+1608
-10
lines changed

8 files changed

+1608
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ In the GIS world, rasters are used for representing continuous phenomena (e.g. e
192192
| Name | Description | NumPy xr.DataArray | Dask xr.DataArray | CuPy GPU xr.DataArray | Dask GPU xr.DataArray |
193193
|:----------:|:------------|:----------------------:|:--------------------:|:-------------------:|:------:|
194194
| [Allocation](xrspatial/proximity.py) | Assigns each cell to the identity of the nearest source feature | ✅️ || | |
195+
| [Cost Distance](xrspatial/cost_distance.py) | Computes minimum accumulated cost to the nearest source through a friction surface | ✅️ || | |
195196
| [Direction](xrspatial/proximity.py) | Computes the direction from each cell to the nearest source feature | ✅️ || | |
196197
| [Proximity](xrspatial/proximity.py) | Computes the distance from each cell to the nearest source feature | ✅️ || | |
197198

0 commit comments

Comments
 (0)