gemgis.raster.sample_randomly#

gemgis.raster.sample_randomly(raster: Union[numpy.ndarray, rasterio.io.DatasetReader], n: int = 1, extent: Optional[Sequence[float]] = None, seed: int = None) tuple#

Sampling randomly from a raster (array or rasterio object) using sample_from_array or sample_from_rasterio and a randomly drawn point within the array/raster extent

Parameters
  • raster (Union[np.ndarray, rasterio.io.DatasetReader]) – NumPy Array or rasterio object containing the raster values

  • n (int) – Number of samples to be drawn, e.g. n=10, default 1

  • extent (Optional[Sequence[float]]) – List containing the values for the extent of the array (minx,maxx,miny,maxy), default is None, e.g. extent=[0, 972, 0, 1069]

  • seed (int) – Seed for the random variable for reproducibility, e.g. seed=1, default is None

Returns

sample – Float of sampled raster value and list containing the x- and y-points of the point where sample was drawn

Return type

tuple

New in version 1.0.x.

Example

>>> # Loading Libraries and File
>>> import gemgis as gg
>>> import rasterio
>>> raster = rasterio.open(fp='raster.tif')
>>> # Sampling randomly from an array or rasterio object
>>> value = gg.raster.sample_randomly(raster=raster, n=1)
>>> value
(617.0579833984375, [529.5110732824818, 717.7358438674542])

See also

sample_from_array

Sample values from NumPy array

sample_from_rasterio

Sample values from rasterio object

sample_orientations

Sample orientations from raster

sample_interfaces

Sample interfaces from raster