geoutils.Raster.reduce_points

geoutils.Raster.reduce_points#

Raster.reduce_points(points, reducer_function=<numpy.ma.core._frommethod object>, window=None, input_latlon=False, band=None, masked=False, return_window=False, as_array=False, boundless=True)[source]#

Reduce raster values around point coordinates.

By default, samples pixel value of each band. Can be passed a band index to sample from.

Uses Rasterio’s windowed reading to keep memory usage low (for a raster not loaded).

Parameters:
  • points (tuple[Union[Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], complex, bytes, str, _NestedSequence[complex | bytes | str]], Union[Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], complex, bytes, str, _NestedSequence[complex | bytes | str]]] | PointCloud) – Point(s) at which to interpolate raster value. Can be either a tuple of array-like of X/Y coordinates (same CRS as raster or latitude/longitude, see “input_latlon”) or a pointcloud in any CRS. If points fall outside of image, value returned is nan.

  • reducer_function (Callable[[ndarray[tuple[Any, ...], dtype[Union[floating[Any], integer[Any]]]]], float]) – Reducer function to apply to the values in window (defaults to np.mean).

  • window (int | None) – Window size to read around coordinates. Must be odd.

  • input_latlon (bool) – (Only for tuple point input) Whether to convert input coordinates from latlon to raster CRS.

  • band (int | None) – Band number to extract from (from 1 to self.count).

  • masked (bool) – Whether to return a masked array, or classic array.

  • return_window (bool) – Whether to return the windows (in addition to the reduced value).

  • as_array (bool) – Whether to return an array of reduced values (defaults to a point cloud containing input coordinates).

  • boundless (bool) – Whether to allow windows that extend beyond the extent.

Return type:

Any

Returns:

Point cloud of interpolated points, or 1D array of interpolated values. In addition, if return_window=True, return tuple of (values, arrays).

Examples:
>>> self.value_at_coords(-48.125, 67.8901, window=3)
Returns mean of a 3*3 window:
    v v v                 v c v  | = float(mean)
    v v v /
(c = provided coordinate, v= value of surrounding coordinate)