raster_tools.distance.pa_direction#

raster_tools.distance.pa_direction(raster, target_values=None, distance_metric='euclidean', max_distance=inf, double_precision=False)[source]#

Compute the direction of each cell to the closest source cell.

This function takes a source raster and uses it to compute a direction raster. Each cell contains the direction in degrees to the nearest source cell as determined by the distance metric. distance_metric selects the function to use for calculating distances between cells. Directions are in degrees on the range [0, 360]. 0 indicates that a source cell. 360 is North, 90 East, 180 South, and 270 indicates West. They indicate the direction to, not from, the nearest source cell.

This is very similar to ESRI’s Euclidean Direction tool.

Parameters
  • raster (Raster, path str) – The input source raster. If target_values is not specified or empty, any non-null, finite, non-zero cell is considered a source. If target_values is specified, it will be used to find source cells with the given values.

  • target_values (array-like, optional) – A 1D sequence of values to use to find source cells in raster. If not specified, all non-null, finite, non-zero cells are considered sources.

  • max_distance (scalar, optional) – The maximum distance (in georeferenced units) to consider when computing proximities. Distances greater than this value will not be computed and the corresponding cells will be skipped. This value also determines how much of raster is loaded into memory when carrying out the computation. A larger value produces a larger memory footprint. The default is infinity which causes the entire raster to be loaded at computation time. No cells will be skipped in this case.

  • distance_metric (str) –

    The name of the distance metric to use for computing distances. Default is ‘euclidean’.

    ’euclidean’

    The euclidean distance between two points: sqrt((x1 - x2)^2 + (y1 - y2)^2)

    ’taxi’ ‘taxicab’ ‘manhatten’ ‘city_block’

    The taxicab distance between two points: |x1 - x2| + |y1 - y2|

    ’chebyshev’ ‘chessboard’

    The chebyshev or chessboard distance: max(|x1 - x2|, |y1 - y2|)

    ’haversine’ ‘great_circle’

    The great circle distance between points on a sphere. This implementation uses the WGS84 mean earth radius of 6,371,009 m. Coordinates are assumed to be in degrees. Latitude must be in the range [-90, 90] and longitude must be in the range [-180, 180].

  • double_precision (bool) – If True, distances will will be computed with 64-bit precision, otherwise 32-bit floats are used. Default is False.

Returns

The direction raster.

Return type

Raster

References