Skip to main content

OutDbSedonaRasterBase

Base class of out-db rasters, whose pixels stay in a file outside the DataFrame. An out-db raster value references a source file, such as a GeoTIFF on S3, and the bands to read from it. as_numpy and as_rasterio read the pixels from that file when called, so the Python process needs access to it. For S3 paths, Sedona builds the credentials from the Spark session’s spark.hadoop.fs.s3a.* configuration; see sedona.spark.raster.gdal_conf. Like the JVM reader, the pixel values have the source’s scale and offset applied, unless the raster.reader.auto-rescale reader parameter (or the session’s spark.hadoop.raster.reader.auto-rescale) turns rescaling off. with_bands is not supported; convert the raster with RS_AsInDb in SQL first.

Parameters

int
required
Width of the raster in pixels.
int
required
Height of the raster in pixels.
List[SampleDimension]
required
Metadata of each band.
AffineTransform
required
Transform from pixel coordinates to world coordinates.
str
required
CRS of the raster as a WKT string.

affine_trans

Geo transform of the raster

bands_meta

Metadata of bands, including nodata value for each band

crs_wkt

CRS of the raster as a WKT string

height

Height of the raster in pixel

outdb_meta

Where the pixels of this raster are stored: the source path, the band indices, the data type and the reader parameters.

path

Path of the source file of this raster.

width

Width of the raster in pixel

as_numpy()

Get the bands data as an numpy array in CHW layout

as_numpy_masked()

Get the bands data as an numpy array in CHW layout, with nodata values masked as nan.

as_rasterio()

Retrieve the raster as an rasterio DatasetReader

close()

Release all resources allocated for this sedona raster. The rasterio DatasetReader returned by as_rasterio() will also be closed.

set_path()

Point this raster at another copy of its source file. Call it before reading the pixels: once this raster has opened its source, it keeps reading from it.

Parameters

str
required
The new source path, for example a local copy of the file.

with_bands()

Replace pixel data, preserving spatial metadata. Only supported on in-db rasters (InDbSedonaRaster); other rasters raise TypeError.

Parameters

np.ndarray
required
New pixel data, of shape (height, width) for a single band or (bands, height, width). Height and width must match this raster; the band count and dtype may differ.
float or sequence of float
default:"None"
NODATA value of the output bands: a scalar for every band, or one value per band. Use float('nan') for a band without NODATA. When omitted, the output bands inherit NODATA from the source bands.

Returns

SedonaRaster
A new raster with the given pixel data and the same spatial metadata.

OutDbSedonaRaster

An out-db raster whose size, georeferencing and band metadata are known. The raster can cover part of the source file, such as a tile, or a subset of its bands. In that case as_rasterio returns a dataset backed by an in-memory VRT that reads that region and those bands from the source.

Parameters

int
required
Width of the raster in pixels.
int
required
Height of the raster in pixels.
List[SampleDimension]
required
Metadata of each band.
AffineTransform
required
Transform from pixel coordinates to world coordinates.
str
required
CRS of the raster as a WKT string.
OutDbMeta
required
Where the pixels of this raster are stored.

affine_trans

Geo transform of the raster

bands_meta

Metadata of bands, including nodata value for each band

crs_wkt

CRS of the raster as a WKT string

height

Height of the raster in pixel

outdb_meta

Where the pixels of this raster are stored: the source path, the band indices, the data type and the reader parameters.

path

Path of the source file of this raster.

width

Width of the raster in pixel

as_numpy()

Get the bands data as an numpy array in CHW layout

as_numpy_masked()

Get the bands data as an numpy array in CHW layout, with nodata values masked as nan.

as_rasterio()

Retrieve the raster as an rasterio DatasetReader

close()

Release all resources allocated for this sedona raster. The rasterio DatasetReader returned by as_rasterio() will also be closed.

generate_vrt_xml()

Assemble a VRT reading band_indices of a region of src_path. With band_rescale, each band reads value * scale + offset through a ComplexSource. Stored nodata is matched exactly before rescaling and becomes NaN, as on the JVM. Nonzero finite nodata needs GDAL’s native replace_nodata pixel function (GDAL >= 3.5). The padding outside the source reads the NoDataValue too, or 0 for a band without one.

Parameters

str
required
Path of the source dataset, in GDAL form (for example /vsis3/...).
str
required
GDAL data type of the VRT bands, such as "Float64".
int
required
Width of the VRT in pixels.
int
required
Height of the VRT in pixels.
str
required
GDAL geotransform of the VRT, as six comma-separated numbers.
str
required
CRS of the VRT as a WKT string, or None or empty for none.
int
required
Column of the source where the region starts.
int
required
Row of the source where the region starts.
list of int
required
Zero-based indices of the source bands to read.
list of float
required
Stored NODATA value of each band, or None for a band without one.
Optional[List[BandRescale]]
default:"None"
(scale, offset) of each band, applied while reading.

Returns

bytes
The VRT XML document.

is_vrt_needed()

Whether reading this raster from the source dataset ds needs a VRT. A VRT is needed when this raster covers only part of the source, or a different set of its bands.

Parameters

DatasetReader
required
The opened source dataset.

Returns

bool

set_path()

Point this raster at another copy of its source file. Call it before reading the pixels: once this raster has opened its source, it keeps reading from it.

Parameters

str
required
The new source path, for example a local copy of the file.

with_bands()

Replace pixel data, preserving spatial metadata. Only supported on in-db rasters (InDbSedonaRaster); other rasters raise TypeError.

Parameters

np.ndarray
required
New pixel data, of shape (height, width) for a single band or (bands, height, width). Height and width must match this raster; the band count and dtype may differ.
float or sequence of float
default:"None"
NODATA value of the output bands: a scalar for every band, or one value per band. Use float('nan') for a band without NODATA. When omitted, the output bands inherit NODATA from the source bands.

Returns

SedonaRaster
A new raster with the given pixel data and the same spatial metadata.

LazyLoadOutDbSedonaRaster

An out-db raster that references a whole source file not opened yet. Sedona returns this for a raster value that holds only a source path and reader parameters. The first access to its size, georeferencing, band metadata or pixels opens the file and reads its metadata.

Parameters

str
required
Path of the source file.
Optional[Dict[str, str]]
required
Reader parameters of the raster, such as raster.reader.auto-rescale.

affine_trans

Geo transform of the raster

bands_meta

Metadata of bands, including nodata value for each band

crs_wkt

CRS of the raster as a WKT string

height

Height of the raster in pixel

outdb_meta

Where the pixels of this raster are stored: the source path, the band indices, the data type and the reader parameters.

path

Path of the source file of this raster.

width

Width of the raster in pixel

as_numpy()

Get the bands data as an numpy array in CHW layout

as_numpy_masked()

Get the bands data as an numpy array in CHW layout, with nodata values masked as nan.

as_rasterio()

Retrieve the raster as an rasterio DatasetReader

close()

Release all resources allocated for this sedona raster. The rasterio DatasetReader returned by as_rasterio() will also be closed.

set_path()

Point this raster at another copy of its source file.

Parameters

str
required
The new source path, for example a local copy of the file.

Raises

  • RuntimeError: If this raster has already opened its source.

with_bands()

Replace pixel data, preserving spatial metadata. Only supported on in-db rasters (InDbSedonaRaster); other rasters raise TypeError.

Parameters

np.ndarray
required
New pixel data, of shape (height, width) for a single band or (bands, height, width). Height and width must match this raster; the band count and dtype may differ.
float or sequence of float
default:"None"
NODATA value of the output bands: a scalar for every band, or one value per band. Use float('nan') for a band without NODATA. When omitted, the output bands inherit NODATA from the source bands.

Returns

SedonaRaster
A new raster with the given pixel data and the same spatial metadata.

OutDbMeta

Import from sedona.spark.raster.meta.
Metadata of out-db raster.

Parameters

int
required
Data type of the pixels, as a DataBuffer type code.
list of int
required
Zero-based indices of the bands of the source file that this raster reads.
str
required
Path of the source file.
dict of str to str
required
Reader parameters of the raster, such as raster.reader.auto-rescale.