๐ Fast, Accurate Python library for Raster Operations
โก Extensible with Numba
โฉ Scalable with Dask
๐ Free of GDAL / GEOS Dependencies
๐ General-Purpose Spatial Processing, Geared Towards GIS Professionals
Xarray-Spatial implements common raster analysis functions using Numba and provides an easy-to-install, easy-to-extend codebase for raster analysis.
# via pip
pip install xarray-spatial
# via conda
conda install -c conda-forge xarray-spatial
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
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 / GEOS, which makes it fully extensible in Python but does limit the breadth of operations that can be covered. xarray-spatial is meant to include the core raster-analysis functions needed for GIS developers / analysts, implemented independently of the non-Python geo stack.
Our documentation is still under constructions, but docs can be found here.
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.)
Name | NumPy xr.DataArray | Dask xr.DataArray | CuPy GPU xr.DataArray | Dask GPU xr.DataArray |
---|---|---|---|---|
Equal Interval | โ ๏ธ | โ | โ | โ |
Natural Breaks | โ ๏ธ | โ | โ | โ |
Reclassify | โ ๏ธ | โ | โ | โ |
Quantile | โ ๏ธ | โ | โ | โ |
Name | NumPy xr.DataArray | Dask xr.DataArray | CuPy GPU xr.DataArray | Dask GPU xr.DataArray |
---|---|---|---|---|
Apply | โ ๏ธ | โ | โ | โ |
Hotspots | โ ๏ธ | โ | โ | โ |
Mean | โ ๏ธ | โ | โ | โ |
Focal Statistics | โ ๏ธ | โ | โ ๏ธ | โ |
Name | NumPy xr.DataArray | Dask xr.DataArray | CuPy GPU xr.DataArray | Dask GPU xr.DataArray |
---|---|---|---|---|
Atmospherically Resistant Vegetation Index (ARVI) | โ ๏ธ | โ | โ ๏ธ | โ |
Enhanced Built-Up and Bareness Index (EBBI) | โ ๏ธ | โ | โ ๏ธ | โ |
Enhanced Vegetation Index (EVI) | โ ๏ธ | โ | โ ๏ธ | โ |
Green Chlorophyll Index (GCI) | โ ๏ธ | โ | โ ๏ธ | โ |
Normalized Burn Ratio (NBR) | โ ๏ธ | โ | โ ๏ธ | โ |
Normalized Burn Ratio 2 (NBR2) | โ ๏ธ | โ | โ ๏ธ | โ |
Normalized Difference Moisture Index (NDMI) | โ ๏ธ | โ | โ ๏ธ | โ |
Normalized Difference Vegetation Index (NDVI) | โ ๏ธ | โ | โ ๏ธ | โ |
Soil Adjusted Vegetation Index (SAVI) | โ ๏ธ | โ | โ ๏ธ | โ |
Structure Insensitive Pigment Index (SIPI) | โ ๏ธ | โ | โ ๏ธ | โ |
Name | NumPy xr.DataArray | Dask xr.DataArray | CuPy GPU xr.DataArray | Dask GPU xr.DataArray |
---|---|---|---|---|
A* Pathfinding | โ ๏ธ | โ | โ | โ |
Name | NumPy xr.DataArray | Dask xr.DataArray | CuPy GPU xr.DataArray | Dask GPU xr.DataArray |
---|---|---|---|---|
Allocation | โ ๏ธ | โ | โ | โ |
Direction | โ ๏ธ | โ | โ | โ |
Proximity | โ ๏ธ | โ | โ | โ |
Name | NumPy xr.DataArray | Dask xr.DataArray | CuPy GPU xr.DataArray | Dask GPU xr.DataArray |
---|---|---|---|---|
Aspect | โ ๏ธ | โ ๏ธ | โ ๏ธ | |
Curvature | โ ๏ธ | โ | โ | |
Hillshade | โ ๏ธ | โ ๏ธ | โ | โ |
Slope | โ ๏ธ | โ ๏ธ | โ ๏ธ | |
Terrain Generation | โ ๏ธ | โ | โ | โ |
Viewshed | โ ๏ธ | โ | โ | โ |
Perlin Noise | โ ๏ธ | โ | โ | โ |
Bump Mapping | โ ๏ธ | โ | โ | โ |
Name | NumPy xr.DataArray | Dask xr.DataArray | CuPy GPU xr.DataArray | Dask GPU xr.DataArray |
---|---|---|---|---|
Apply | โ ๏ธ | โ | โ | โ |
Crop | โ ๏ธ | โ | โ | โ |
Regions | โ ๏ธ | โ | โ | โ |
Trim | โ ๏ธ | โ | โ | โ |
Zonal Statistics | โ ๏ธ | โ | โ | โ |
Zonal Cross Tabulate | โ ๏ธ | โ | โ | โ |
import xarray as xr
from xrspatial import hillshade
my_dataarray = xr.DataArray(...)
hillshaded_dataarray = hillshade(my_dataarray)
Check out the user guide here.
Check out Xarray-Spatial on YouTube
xarray-spatial
currently depends on Datashader, but will soon be updated to depend only on xarray
and numba
, while still being able to make use of Datashader output when available.
Within the Python ecosystem, many geospatial libraries interface with the GDAL C++ library for raster and vector input, output, and analysis (e.g. rasterio, rasterstats, geopandas). GDAL is robust, performant, and has decades of great work behind it. For years, off-loading expensive computations to the C/C++ level in this way has been a key performance strategy for Python libraries (obviously...Python itself is implemented in C!).
However, wrapping GDAL has a few drawbacks for Python developers and data scientists:
- GDAL can be a pain to build / install.
- GDAL is hard for Python developers/analysts to extend, because it requires understanding multiple languages.
- GDAL's data structures are defined at the C/C++ level, which constrains how they can be accessed from Python.
With the introduction of projects like Numba, Python gained new ways to provide high-performance code directly in Python, without depending on or being constrained by separate C/C++ extensions. xarray-spatial
implements algorithms using Numba and Dask, making all of its source code available as pure Python without any "black box" barriers that obscure what is going on and prevent full optimization. Projects can make use of the functionality provided by xarray-spatial
where available, while still using GDAL where required for other tasks.
- @brendancol
- @thuydotm
- @jbednar
- @pablomakepath
- @kristinepetrosyan
- @sjsrey
- @giancastro
- @ocefpaf
- @rsignell-usgs
- @marcozimmermannpm
- @jthetzel
- @chase-dwelle