API Reference
Engine entrypoint
The xarray engine itself. Most users invoke it via
xr.open_dataset(path, engine="gdalxarray", ...) rather than directly.
Bases: BackendEntrypoint
xarray backend for reading geospatial files via GDAL.
guess_can_open(filename_or_obj)
Conservative heuristic for xarray's engine auto-discovery.
open_dataset(filename_or_obj, *, drop_variables=None, chunks=None, multidim=True, group=None, band_as_dim=True)
Open a dataset using GDAL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename_or_obj
|
str
|
Path or GDAL-recognised URI ( |
required |
drop_variables
|
iterable of hashable
|
Variables to omit from the returned Dataset. |
None
|
chunks
|
dict
|
Chunk sizes for Dask arrays. |
None
|
multidim
|
bool
|
If True, use GDAL's multidimensional API
( |
True
|
group
|
str
|
Group path for multidim datasets (e.g. |
None
|
band_as_dim
|
bool
|
Classic-raster only. If True, bands become an xarray |
True
|
Recipe builders
Helper functions that build GDAL configuration recipes - VRT strings, typically - for downstream consumption by the engine.
Lazy warp-VRT recipe construction.
The :func:warp function builds a description of a warp operation —
target CRS, resolution, bounds, GCP/RPC/geoloc transformer, cutline,
etc. — and returns it as VRT XML text. The result composes with
:class:GDALBackendEntrypoint::
>>> import gdalxarray
>>> import xarray as xr
>>> vrt = gdalxarray.warp(source, crs="+proj=laea")
>>> ds = xr.open_dataset(vrt, engine="gdalxarray", multidim=False)
No pixels are read or written by warp() — the VRT is a recipe.
Bytes flow only when the consumer (xarray, gdalwarp, gdal_translate)
asks for a window.
warp(source, *, crs=None, bbox=None, shape=None, resolution=None, resampling='near', nodata=None, src_nodata=None, bands=None, **warp_options)
Build a warped-VRT recipe string.
Wraps :func:gdal.Warp with format="VRT" to produce a textual
description of a reprojection / regrid / warp. The result is a
self-contained VRT XML string that downstream tools can read lazily.
The named keyword arguments cover the common cases. Any further
:func:gdal.WarpOptions keyword can be passed as an additional
keyword argument and is forwarded verbatim — see GDAL's
gdal.WarpOptions documentation for the full list (transformer
options for RPC/GCPs/geolocation arrays, cutlines, alpha-band
handling, working type, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
GDAL-recognised source path or URI. Anything |
required |
crs
|
str or int
|
Target CRS as PROJ string, WKT, or EPSG code. Maps to GDAL's
|
None
|
bbox
|
sequence of 4 floats
|
Output bounding box |
None
|
shape
|
tuple of 2 ints
|
Output |
None
|
resolution
|
float or tuple of 2 floats
|
Output resolution. A scalar means isotropic |
None
|
resampling
|
str
|
Resampling algorithm: |
``"near"``
|
nodata
|
float
|
Output nodata value. Maps to GDAL's |
None
|
src_nodata
|
float
|
Override the source nodata value. Maps to GDAL's |
None
|
bands
|
list of int
|
Subset of source bands to warp (1-based). Maps to GDAL's
|
None
|
**warp_options
|
Any other keyword argument is forwarded to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
VRT XML describing the warped output. Suitable for
|
Notes
Runtime-only options (multithread, warpMemoryLimit,
creationOptions, callback, callback_data) are not
serialised into the VRT description — they affect how a warp is
executed, not what the warp produces. Passing them to warp()
emits a :class:UserWarning and they are dropped. To control
runtime behaviour for the eventual read, set GDAL config options
on the consumer side, e.g.::
gdal.SetConfigOption("GDAL_NUM_THREADS", "4")
ds = xr.open_dataset(vrt, engine="gdalxarray")
Examples:
Reproject anything to Lambert Azimuthal Equal Area, lazily::
vrt = warp(src, crs="+proj=laea")
ds = xr.open_dataset(vrt, engine="gdalxarray", multidim=False)
Specific target grid::
vrt = warp(
src,
crs="EPSG:3577",
bbox=(-2000000, -5000000, 2000000, -1000000),
resolution=1000,
resampling="bilinear",
)
Drone imagery with GCPs, warped via thin-plate splines::
vrt = warp(src, crs="EPSG:32755", tps=True)
Satellite Level-1B product with RPCs and a DEM::
vrt = warp(
src,
crs="EPSG:4326",
rpc=True,
transformerOptions=["RPC_DEM=/path/to/dem.tif"],
)