RasterioSource#
- class RasterioSource[source]#
Bases:
RasterSource
A rasterio-based
RasterSource
.This RasterSource can read any file that can be opened by Rasterio/GDAL.
If there are multiple image files that cover a single scene, you can pass the corresponding list of URIs, and read them as if it were a single stitched-together image.
It can also read non-georeferenced images such as
.tif
,.png
, and.jpg
files. This is useful for oblique drone imagery, biomedical imagery, and any other (potentially massive!) non-georeferenced images.If channel_order is None, then use non-alpha channels. This also sets any masked or NODATA pixel values to be zeros.
Attributes
Associated
CRSTransformer
.numpy.dtype
of the chips read from this source.Extent of the RasterSource.
Number of channels in the chips read from this source.
Shape of the raster as a (height, width, num_channels) tuple.
- __init__(uris: Union[str, List[str]], raster_transformers: List[RasterTransformer] = [], allow_streaming: bool = False, channel_order: Optional[Sequence[int]] = None, extent: Optional[Box] = None, tmp_dir: Optional[str] = None)[source]#
Constructor.
- Parameters
uris (Union[str, List[str]]) – One or more URIs of images. If more than one, the images will be mosaiced together using GDAL.
raster_transformers (List['RasterTransformer']) – RasterTransformers to use to trasnform chips after they are read.
allow_streaming (bool) – If True, read data without downloading the entire file first. Defaults to False.
channel_order (Optional[Sequence[int]]) – List of indices of channels to extract from raw imagery. Can be a subset of the available channels. If None, all channels available in the image will be read. Defaults to None.
extent (Optional[Box], optional) – Use-specified extent. If None, the full extent of the raster source is used.
tmp_dir (Optional[str]) – Directory to use for storing the VRT (needed if multiple uris or allow_streaming=True). If None, will be auto-generated. Defaults to None.
Methods
__init__
(uris[, raster_transformers, ...])Constructor.
download_data
([vrt_dir, stream])Download any data needed for this raster source.
get_chip
(window[, bands, out_shape])Read a chip specified by a window from the file.
Return entire transformed image array.
get_raw_chip
(window)Return raw chip without applying channel_order or transforms.
Return raw image for the full extent.
- __init__(uris: Union[str, List[str]], raster_transformers: List[RasterTransformer] = [], allow_streaming: bool = False, channel_order: Optional[Sequence[int]] = None, extent: Optional[Box] = None, tmp_dir: Optional[str] = None)[source]#
Constructor.
- Parameters
uris (Union[str, List[str]]) – One or more URIs of images. If more than one, the images will be mosaiced together using GDAL.
raster_transformers (List['RasterTransformer']) – RasterTransformers to use to trasnform chips after they are read.
allow_streaming (bool) – If True, read data without downloading the entire file first. Defaults to False.
channel_order (Optional[Sequence[int]]) – List of indices of channels to extract from raw imagery. Can be a subset of the available channels. If None, all channels available in the image will be read. Defaults to None.
extent (Optional[Box], optional) – Use-specified extent. If None, the full extent of the raster source is used.
tmp_dir (Optional[str]) – Directory to use for storing the VRT (needed if multiple uris or allow_streaming=True). If None, will be auto-generated. Defaults to None.
- download_data(vrt_dir: Optional[str] = None, stream: bool = False) str [source]#
Download any data needed for this raster source.
Return a single local path representing the image or a VRT of the data.
- get_chip(window: Box, bands: Optional[Union[Sequence[int], slice]] = None, out_shape: Optional[Tuple[int, ...]] = None) ndarray [source]#
Read a chip specified by a window from the file.
- Parameters
window (Box) – Bounding box of chip in pixel coordinates.
bands (Optional[Union[Sequence[int], slice]], optional) – Subset of bands to read. Note that this will be applied on top of the channel_order (if specified). So if this is an RGB image and channel_order=[2, 1, 0], then using bands=[0] will return the B-channel. Defaults to None.
out_shape (Optional[Tuple[int, ...]], optional) – (hieght, width) of
None (the output chip. If) –
None. (no resizing is done. Defaults to) –
- Returns
A chip of shape (height, width, channels).
- Return type
np.ndarray
- get_image_array() np.ndarray #
Return entire transformed image array.
Warning
Not safe to call on very large RasterSources.
- Returns
Array of shape (height, width, channels).
- Return type
np.ndarray
- get_raw_chip(window: Box) np.ndarray #
Return raw chip without applying channel_order or transforms.
- Parameters
window (Box) – The window for which to get the chip.
- Returns
Array of shape (height, width, channels).
- Return type
np.ndarray
- get_raw_image_array() np.ndarray #
Return raw image for the full extent.
Warning
Not safe to call on very large RasterSources.
- Returns
Array of shape (height, width, channels).
- Return type
np.ndarray
- property crs_transformer: RasterioCRSTransformer#
Associated
CRSTransformer
.