gemgis.raster.sample_from_rasterio
gemgis.raster.sample_from_rasterio#
- gemgis.raster.sample_from_rasterio(raster: rasterio.io.DatasetReader, point_x: Union[float, int, list, numpy.ndarray], point_y: Union[float, int, list, numpy.ndarray], sample_outside_extent: bool = True, sample_all_bands: bool = False) Union[list, float] #
Sampling the value of a rasterio object at a given point within the extent of the raster
- Parameters
raster (rasterio.io.DatasetReader) – Rasterio Object containing the height information
point_x (list, np.ndarray, float, int) – Object containing the x coordinates of a point or points at which the array value is obtained, e.g.
point_x=100
point_y (list, np.ndarray, float, int) – Object containing the y coordinates of a point or points at which the array value is obtained, e.g.
point_y=100
sample_outside_extent (bool) – Allow sampling outside the extent of the rasterio object. Options include:
True
orFalse
, default set toTrue
sample_all_bands (bool) – Allow sampling from all bands returning Options include:
True
orFalse
, default set toFalse
- Returns
sample – Value/s of the raster at the provided position/s
- Return type
list, float
New in version 1.0.x.
Example
>>> # Loading Libraries and File >>> import gemgis as gg >>> import rasterio >>> raster = rasterio.open(fp='raster.tif')
>>> # Sampling values from a rasterio object >>> value = gg.raster.sample_from_rasterio(raster=raster, point_x=500, point_y=500) >>> value 561.646728515625
See also
sample_from_array
Sample values from NumPy array
sample_randomly
Sample randomly from rasterio object or NumPy array
sample_orientations
Sample orientations from raster
sample_interfaces
Sample interfaces from raster