[!IMPORTANT]
xarray-spatial uses AI assistance. Before opening a PR, read the AI-Assisted Contribution Policy and run your changes through the project's approved AI review workflow (see the command suite in the xarray-spatial-skills repo). PRs that ignore the workflow are likely to be rejected.
Feature freeze in effect. The project is working toward its first major release (1.0.0). Until 1.0.0 ships, only bug fixes, test coverage, performance work, and documentation PRs will be considered. New feature proposals will be triaged but not implemented until after the release.
Contributors Wanted!. xarray-spatial is currently looking for contributors to help run pre-defined AI-assisted workflows as we approach v1.0.0. If you are interested, please add an issue and flag @brendancol and we can chat.
Latest Release
Downloads
License
People
Build Status
Coverage
:round_pushpin: Fast, Accurate Python library for Raster Operations
:desktop_computer: GPU-accelerated with CuPy and Numba CUDA
:confetti_ball: Free of GDAL / GEOS Dependencies
:earth_africa: General-Purpose Spatial Processing, Geared Towards GIS Professionals
Xarray-Spatial is a Python library for raster analysis built on xarray. It has 150+ functions for surface analysis, hydrology (D8, D-infinity, MFD), fire behavior, flood modeling, multispectral indices, proximity, classification, pathfinding, and interpolation. Functions dispatch automatically across four backends (NumPy, Dask, CuPy, Dask+CuPy). A built-in GeoTIFF/COG reader and writer handles raster I/O without GDAL.
Installation
# via pip
pip install xarray-spatial
# with plotting helpers (matplotlib)
pip install xarray-spatial[plot]
# with vector rasterization (shapely): rasterize, polygonize
pip install xarray-spatial[vector]
# via conda
conda install -c conda-forge xarray-spatial
Downloading our starter examples and data
Once you have xarray-spatial installed in your environment, you can use one of the following in your terminal (with the environment active) to download our examples and/or sample data into your local directory.
xrspatial examples : Download the examples notebooks and the data used.
xrspatial copy-examples : Download the examples notebooks but not the data. Note: you won't be able to run many of the examples.
xrspatial fetch-data : Download just the data and not the notebooks.
In all the above, the command will download and store the files into your current directory inside a folder named 'xrspatial-examples'.
xarray-spatial grew out of the Datashader project, which provides fast rasterization of vector data (points, lines, polygons, meshes, and rasters) for use with xarray-spatial.
xarray-spatial does not depend on GDAL or GEOS. Raster I/O, reprojection, compression codecs, and coordinate handling are all pure Python and Numba -- no C/C++ bindings anywhere in the stack.
Rasters are regularly gridded datasets like GeoTIFFs, JPGs, and PNGs.
In the GIS world, rasters are used for representing continuous phenomena (e.g. elevation, rainfall, distance), either directly as numerical values, or as RGB images created for humans to view. Rasters typically have two spatial dimensions, but may have any number of other dimensions (time, type of measurement, etc.)
Supported Spatial Functions with Supported Inputs
Each cell shows the feature tier for that function on that backend (see issue #2415). A blank cell means no implementation on that backend; a path that was previously documented as a CPU fallback is reported here as advanced (it works as a documented execution mode, but is not native-parity tested).
Native GeoTIFF and Cloud Optimized GeoTIFF reader/writer. No GDAL required.
VRT is supported as a conservative advanced feature for simple GeoTIFF mosaics, not as a full GDAL VRT replacement. See the VRT support matrix for the supported subset and what is out of scope.
open_geotiff and to_geotiff select the backend from their parameters
(gpu=, chunks=, .vrt path); GPU read/write is reached with gpu=True,
not a separate function:
from xrspatial.geotiff import open_geotiff, to_geotiff
open_geotiff('dem.tif') # NumPy
open_geotiff('dem.tif', chunks=512) # Dask
open_geotiff('dem.tif', gpu=True) # CuPy (nvCOMP + GDS)
open_geotiff('dem.tif', gpu=True, chunks=512) # Dask + CuPy
open_geotiff('https://example.com/cog.tif') # HTTP COG
open_geotiff('s3://bucket/dem.tif') # Cloud (S3/GCS/Azure)
open_geotiff('mosaic.vrt') # VRT mosaic (auto-detected)
to_geotiff(cupy_array, 'out.tif') # auto-detects GPU
to_geotiff(data, 'out.tif', gpu=True) # force GPU compress
to_geotiff(data, 'out.tif', compression='zstd') # ZSTD for smaller files
to_geotiff(data, 'cog.tif', cog=True) # COG with auto overviews
to_geotiff(data, 'cog.tif', cog=True, # COG with explicit levels
overview_levels=[2, 4, 8],
overview_resampling='nearest')
to_geotiff(data, 'mosaic.vrt') # write a tiled VRT mosaic
open_geotiff('dem.tif', dtype='float32') # half memory
open_geotiff('dem.tif', dtype='float32', chunks=512) # Dask + half memory
to_geotiff(data, 'out.tif', compression_level=1) # fast scratch write
to_geotiff(data, 'out.tif', compression_level=22) # max compression
to_geotiff(dask_da, 'out.tif') # stream Dask to single TIFF
to_geotiff(dask_da, 'mosaic.vrt') # stream Dask to VRT
# Accessor methods
da.xrs.to_geotiff('out.tif', compression='lzw') # write from DataArray
ds.xrs.open_geotiff('large_dem.tif') # read windowed to Dataset extent
# xarray backend engine
import xarray as xr
xr.open_dataset('dem.tif', engine='xrspatial') # open as a Dataset
xr.open_mfdataset('*.tif', engine='xrspatial', # share one var name
backend_kwargs={'default_name': 'band_data'})
Compression codecs: Deflate, LZW (Numba JIT), ZSTD, PackBits, JPEG (Pillow, internal-only: requires allow_internal_only_jpeg=True and is not readable by GDAL), JPEG 2000 (glymur, experimental: requires allow_experimental_codecs=True), uncompressed
GPU codecs: Deflate and ZSTD via nvCOMP batch API; JPEG 2000 via nvJPEG2000; LZW via Numba CUDA kernels
Reprojects a raster to a new CRS with Numba JIT / CUDA coordinate transforms and resampling. Supports vertical datums (EGM96, EGM2008) and horizontal datum shifts (NAD27, OSGB36, etc.)
Merges multiple rasters into a single mosaic with configurable overlap strategy. Same-CRS tiles skip reprojection and are placed by direct coordinate alignment
Standard (mosaic)
🔼
🔼
🔼
🔼
Built-in Numba JIT and CUDA projection kernels bypass pyproj for per-pixel coordinate transforms. pyproj is used only for CRS metadata parsing (~1ms, once per call) and output grid boundary estimation (~500 control points, once per call). Any CRS pair without a built-in kernel falls back to pyproj automatically.
Projection
EPSG examples
CPU Numba
CUDA GPU
Web Mercator
3857
✅️
✅️
UTM / Transverse Mercator
326xx, 327xx, State Plane
✅️
✅️
Ellipsoidal Mercator
3395
✅️
✅️
Lambert Conformal Conic
2154, 2229, State Plane
✅️
✅️
Albers Equal Area
5070
✅️
✅️
Cylindrical Equal Area
6933
✅️
✅️
Sinusoidal
MODIS grids
✅️
✅️
Lambert Azimuthal Equal Area
3035, 6931, 6932
✅️
✅️
Polar Stereographic
3031, 3413, 3996
✅️
✅️
Oblique Stereographic
custom WGS84
✅️
pyproj fallback
Oblique Mercator (Hotine)
3375 (RSO)
implemented, disabled
pyproj fallback
Vertical datum support:geoid_height, ellipsoidal_to_orthometric, orthometric_to_ellipsoidal convert between ellipsoidal (GPS) and orthometric (map/MSL) heights using EGM96 (vendored, 2.6MB) or EGM2008 (77MB, downloaded on first use). Reproject can apply vertical shifts during reprojection via the vertical_crs parameter.
Datum shift support: Reprojection from non-WGS84 datums (NAD27, OSGB36, DHDN, MGI, ED50, BD72, CH1903, D73, AGD66, Tokyo) applies grid-based shifts from PROJ CDN (sub-metre accuracy) with 7-parameter Helmert fallback (1-5m accuracy). 14 grids are registered covering North America, UK, Germany, Austria, Spain, Netherlands, Belgium, Switzerland, Portugal, and Australia.
ITRF frame support:itrf_transform converts between ITRF2000, ITRF2008, ITRF2014, and ITRF2020 using 14-parameter time-dependent Helmert transforms from PROJ data files. Shifts are mm-level.
Empty study-area grid for a named region (CONUS, NYC, ...), a world city (London, Tokyo, ... in its UTM zone), a country code, or a whole-world projection (web_mercator, wgs84/latlon, equal_earth); preserve='area'/'shape' picks an EPSG projection by property; list_templates() lists every accepted name
Composites red, green, and blue bands into a natural color image
Standard
✅
🔼
🔼
🔼
For a broader catalog of spectral indices and sensor-specific band combinations, see awesome-spectral-indices and its companion xarray library spyndex.
Checks that disaggregated pixel sums match the original zone totals
Standard
✅
🔼
🔼
🔼
Usage
Quick Start
Importing xrspatial registers an .xrs accessor on DataArrays and Datasets, giving you tab-completable access to every spatial operation:
import xrspatial as xrs
from xrspatial.geotiff import open_geotiff, to_geotiff
# Read a GeoTIFF (no GDAL required)
elevation = open_geotiff('dem.tif')
# Surface analysis
slope = elevation.xrs.slope()
hillshaded = elevation.xrs.hillshade(azimuth=315, angle_altitude=45)
aspect = elevation.xrs.aspect()
# Reproject and write as a Cloud Optimized GeoTIFF
dem_wgs84 = elevation.xrs.reproject(target_crs='EPSG:4326')
to_geotiff(dem_wgs84, 'output.tif', cog=True)
# Classification
classes = elevation.xrs.equal_interval(k=5)
breaks = elevation.xrs.natural_breaks(k=10)
# Proximity
distance = elevation.xrs.proximity(target_values=[1])
# Multispectral
vegetation = nir.xrs.ndvi(red)
enhanced_vi = nir.xrs.evi(red, blue)
Dataset Support
The .xrs accessor works on Datasets too. Single-input functions apply the operation to each data variable. Multi-input functions (multispectral indices) accept string kwargs that map band aliases to variable names:
ds = xr.Dataset({'band_4': red, 'band_5': nir})
# Single-input: slope computed for each variable
slope_ds = ds.xrs.slope()
# Multi-input: map variable names to band parameters
ndvi_result = ds.xrs.ndvi(nir='band_5', red='band_4')
Function Import Style
All operations are also available as standalone functions:
libnvcomp and kvikio are not pulled in by the gpu extra. They are runtime
dependencies of the GeoTIFF GPU read path and must be installed separately
(typically via conda from the rapidsai/nvidia channels), since libnvcomp
ships as a system library and kvikio requires a matching CUDA toolkit.
Notes on GDAL
xarray-spatial does not depend on GDAL. The built-in GeoTIFF/COG reader and writer (xrspatial.geotiff) handles raster I/O natively using only numpy, numba, and the standard library. This means:
Zero GDAL installation hassle.pip install xarray-spatial gets you everything needed to read and write GeoTIFFs, COGs, and VRT files.
Pure Python, fully extensible. All codec, header parsing, and metadata code is readable Python/Numba, not wrapped C/C++.
GPU-accelerated reads. With optional nvCOMP and nvJPEG2000, compressed tiles decompress directly on the GPU via CUDA -- something GDAL cannot do.
The native reader is pixel-exact against rasterio/GDAL across Landsat 8, Copernicus DEM, USGS 1-arc-second, and USGS 1-meter DEMs.