variete.VRaster#
VRaster#
- class variete.VRaster(steps=None)[source]#
Bases:
objectA “Virtual Raster” containing information on how to process a raster on disk.
A VRaster has no data loaded in memory, other than the processing steps to take when evaluating. Evaluation is mainly done through the VRaster.read() or VRaster.write() functions.
- property bounds: BoundingBox#
- property last: VRTDataset#
- read(band=None, out=None, window=None, masked=False, **kwargs)[source]#
Read the contents of a VRaster into memory.
- Parameters
band (
UnionType[int,list[int],None]) – A band index or a list of indices to load. Defaults to all bands.out (
Union[_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],bool,int,float,complex,str,bytes,_NestedSequence[Union[bool,int,float,complex,str,bytes]],None]) – Optional: The destination array to read to.window (
Optional[Window]) – Optional: Read only a part of the VRaster (see the rasterio Window documentation)masked (
bool) – Return a masked array where all nodata values are masked.**kwargs (
dict[str,Any]) – Optional keyword arguments to supply the rio.DatasetReader.read method.
- Return type
A numpy array of shape (bands, height, width) or a numpy masked_array
- sample(x_coord, y_coord, band=1, masked=False)[source]#
Sample values at the given georeferenced coordinates of a VRaster.
- Parameters
x_coord (
Union[float,Iterable[float]]) – The x (easting/longitude) coordinate(s) to sampley_coord (
Union[float,Iterable[float]]) – The x (northing/latitude) coordinate(s) to sampleband (
int|list[int]) – The band(s) to sample from. Defaults to the first.masked (
bool) – Return a masked array with nodata values masked out.
- Return type
int|float|ndarray[Any,dtype[Any]] |MaskedArray[Any,Any]- Returns
If one coordinate and one band – One sampled value
If multiple coordinates and/or multiple bands – An array of coordinates
- sample_rowcol(row, col, band=1, masked=False)[source]#
Sample values at the given row(s) and column(s) of a VRaster.
- save_vrt(filepath)[source]#
Save the VRaster as a VRT or a stack of VRTs.
If the VRaster is nested (depends on more than one VRTDataset), all dependents will be saved too.
-
steps:
list[VRasterStep]#
- property transform: Affine#
- warp(reference=None, crs=None, res=None, shape=None, bounds=None, transform=None, resampling='bilinear', dst_nodata=None, multithread=False)[source]#
Warp the VRaster to new bounds, resolutions and/or coordinate systems.
This wraps the functionality of gdal.Warp
- Parameters
reference (
Optional[VRaster]) – Optional: A reference VRaster to get the CRS, transform and shape from. Note: It silently overrides the shape, crs and transform arguments. If only parts of the reference parameters should be used, supply them directly instead (e.g. VRaster.crs).crs (
UnionType[CRS,int,str,None]) – The target coordinate reference system (CRS). If an integer is given, it’s parsed as an EPSG code (e.g. 4326 -> WGS84).res (
UnionType[tuple[float,float],float,None]) – The target resolution in georeferenced units. If only one value is given, it is used for both axes.shape (
Optional[tuple[int,int]]) – The target shape of the VRaster in pixels as (height, width).bounds (
UnionType[BoundingBox,list[float],None]) – The target corner bounds of the VRaster. If a list is given, it’s parsed as [xmin, ymin, xmax, ymax]transform (
Optional[Affine]) – The target affine transform of the VRaster.resampling (
Resampling|str) – The target resampling algorithm, e.g. “bilinear” or “cubic_spline”. See rio.warp.Resampling for all available algorithms.dst_nodata (
UnionType[int,float,None]) – Destination nodata value to use after warping. Defaults to the source nodata value.multithread (
bool) – Use multithreading for the warp operation.
- Return type
A new VRaster
- write(filepath, format=None, tiled=None, compress='deflate', predictor=None, zlevel=None, creation_options=None, progress=False, callback=None)[source]#
Write the VRaster to a file.
- Parameters
filepath (
Path|str) – The output filepath to write the file.format (
Optional[str]) – The output format (e.g. “GTiff”). If not given, the format is inferred from the filename.tiled (
Optional[bool]) – Whether to write the blocks in tiles (True) or in strips (False)compress (
Optional[str]) – What compression algorithm to use.predictor (
Union[Literal[1],Literal[2],Literal[3],None]) – Which compression predictor to use (only valid in some compression schemes).zlevel (
UnionType[int,str,None]) – The level of compression to use. For deflate, valid numbers range between 1 and 12creation_options (
Optional[dict[str,str|int|bool]]) – Other creation options to provide to GDAL as a {key: value} dictionaryprogress (
bool) – Whether to show a tqdm progress bar. tqdm needs to be installed for this to work.callback (
Optional[Callable[[float,Any,Any],Any]]) – A callback function for the writer that takes three positional arguments. The first argument is the progress, ranging from 0-1.
- Raises
AssertionError – If any requirement for file creation is not filled.
ValueError – If the provided arguments are incompatible.
- Return type