gemgis.raster.sample_from_array
gemgis.raster.sample_from_array#
- gemgis.raster.sample_from_array(array: numpy.ndarray, extent: Sequence[float], point_x: Union[float, int, list, numpy.ndarray], point_y: Union[float, int, list, numpy.ndarray]) Union[numpy.ndarray, float] #
Sampling the value of a np.ndarray at a given point and given the arrays true extent
- Parameters
array (np.ndarray) – Array containing the raster values
extent (list) – List containing the values for the extent of the array (minx,maxx,miny,maxy), e.g.
extent=[0, 972, 0, 1069]
point_x (Union[float, int, list, np.ndarray]) – Object containing the x coordinates of a point or points at which the array value is obtained, e.g.
point_x=100
point_y (Union[float, int, list, np.ndarray]) – Object containing the y coordinates of a point or points at which the array value is obtained, e.g.
point_y=100
- Returns
sample – Value/s of the raster at the provided position/s
- Return type
Union[np.ndarray, float]
New in version 1.0.x.
Example
>>> # Loading Libraries and File >>> import gemgis as gg >>> import rasterio >>> raster = rasterio.open(fp='raster.tif')
>>> # Getting array data >>> array = raster.read()
>>> # Sampling values from an array >>> value = gg.raster.sample_from_array(array=array, extent=[0, 972, 0, 1069], point_x=500, point_y=500) >>> value 562.0227
See also
sample_from_rasterio
Sample values from rasterio object
sample_randomly
Sample randomly from rasterio object or NumPy array
sample_orientations
Sample orientations from raster
sample_interfaces
Sample interfaces from raster