Skip to main content

SedonaRaster

A raster value from a Sedona raster column. DataFrame.collect() and Python UDFs receive raster column values as SedonaRaster objects. Read the pixels with as_numpy or as_rasterio, and the georeferencing with affine_trans and crs_wkt. Call close, or use the raster as a context manager, to release the resources it holds. Sedona creates these objects when it reads a raster value; you do not construct them yourself.

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

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.

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.
Optional[Union[float, Sequence[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.

AffineTransform

Import from sedona.spark.raster.meta.
Affine transform from pixel coordinates to world coordinates. The pixel at column col and row row maps to x = ip_x + col * scale_x + row * skew_x and y = ip_y + col * skew_y + row * scale_y. repr() shows the transform as a 3x3 matrix.

Parameters

float
required
Pixel width in world units.
float
required
Change in y per column; 0 for a raster without rotation.
float
required
Change in x per row; 0 for a raster without rotation.
float
required
Pixel height in world units, negative for a north-up raster.
float
required
X coordinate of the upper-left pixel.
float
required
Y coordinate of the upper-left pixel.
PixelAnchor
required
Whether ip_x and ip_y refer to the center or the upper-left corner of that pixel.

translate()

Return the transform of a raster whose origin is offset by whole pixels.

Parameters

float
required
Offset in pixel columns.
float
required
Offset in pixel rows.

Returns

AffineTransform
A new transform whose origin is pixel (offset_x, offset_y) of this one, for example the transform of a tile cut from the raster.

with_anchor()

Return the same transform expressed for another pixel anchor.

Parameters

PixelAnchor
required
The pixel anchor of the returned transform.

Returns

AffineTransform
This transform if it already uses pixel_anchor; otherwise a new transform whose origin is shifted by half a pixel.

PixelAnchor

Import from sedona.spark.raster.meta. Anchor of the pixel cell. GeoTools anchors the coordinates at the center of pixels, while GDAL anchors the coordinates at the upper-left corner of the pixels. This difference requires us to convert the affine transformation between these conventions.

Values

PixelAnchor
1
PixelAnchor
2

SampleDimension

Import from sedona.spark.raster.meta.
Raster band metadata.

Parameters

str
required
Description of the band.
float
required
Offset of the band: a stored pixel value means value * scale + offset.
float
required
Scale of the band.
float
required
NODATA value of the band, or NaN if the band has none.

SedonaUtils

Import from sedona.spark.raster_utils.SedonaUtils.
Notebook display helpers for Sedona DataFrames.

display_image()

Display raster images in a Jupyter notebook. Accepts DataFrames with either:
  • A raster column (GridCoverage2D) — auto-applies RS_AsImage
  • An HTML image column from RS_AsImage() — renders directly
Falls back to the SedonaMapUtils HTML table path for other DataFrames.

Parameters

pyspark.sql.DataFrame
required
The DataFrame to display. All of its rows are collected to the driver, so limit large DataFrames first.