Skip to content

makepath/xarray-spatial

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

* chore: Remove numpy pin and pin datashader

Datashader 0.15.0 removes error numpy.warnings removal:
holoviz/datashader#1176

* chore: Require Python >= 3.8
27ab0c8

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
img
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Latest Release
pypi version
Downloads
License MIT People GitHub contributors
Build Status Coverage

History of OS GIS Timeline


title

πŸ“ 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.

Installation

# via pip
pip install xarray-spatial

# 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 / 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 construction, but docs can be found here.

Raster-huh?

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


Classification

Name NumPy xr.DataArray Dask xr.DataArray CuPy GPU xr.DataArray Dask GPU xr.DataArray
Equal Interval βœ…οΈ βœ… βœ… ️
Natural Breaks βœ…οΈ ️
Reclassify βœ…οΈ βœ… βœ… βœ…
Quantile βœ…οΈ βœ… βœ… ️

Focal

Name NumPy xr.DataArray Dask xr.DataArray CuPy GPU xr.DataArray Dask GPU xr.DataArray
Apply βœ…οΈ βœ…οΈ
Hotspots βœ…οΈ βœ…οΈ βœ…οΈ
Mean βœ…οΈ βœ…οΈ βœ…οΈ
Focal Statistics βœ…οΈ βœ…οΈ βœ…οΈ

Multispectral

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) βœ…οΈ βœ…οΈ βœ…οΈ βœ…οΈ
True Color βœ…οΈ ️ βœ…οΈ ️

Pathfinding

Name NumPy xr.DataArray Dask xr.DataArray CuPy GPU xr.DataArray Dask GPU xr.DataArray
A* Pathfinding βœ…οΈ

Proximity

Name NumPy xr.DataArray Dask xr.DataArray CuPy GPU xr.DataArray Dask GPU xr.DataArray
Allocation βœ…οΈ βœ…
Direction βœ…οΈ βœ…
Proximity βœ…οΈ βœ…

Raster to vector

Name NumPy xr.DataArray Dask xr.DataArray CuPy GPU xr.DataArray Dask GPU xr.DataArray
Polygonize βœ…οΈ

Surface

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 βœ…οΈ

Zonal

Name NumPy xr.DataArray Dask xr.DataArray CuPy GPU xr.DataArray Dask GPU xr.DataArray
Apply βœ…οΈ βœ…οΈ
Crop βœ…οΈ
Regions
Trim βœ…οΈ
Zonal Statistics βœ…οΈ βœ…οΈ
Zonal Cross Tabulate βœ…οΈ βœ…οΈ

Local

Name NumPy xr.DataArray Dask xr.DataArray CuPy GPU xr.DataArray Dask GPU xr.DataArray
Cell Stats βœ…οΈ
Combine βœ…οΈ
Lesser Frequency βœ…οΈ
Equal Frequency βœ…οΈ
Greater Frequency βœ…οΈ
Lowest Position βœ…οΈ
Highest Position βœ…οΈ
Popularity βœ…οΈ
Rank βœ…οΈ

Usage

Basic Pattern
import xarray as xr
from xrspatial import hillshade

my_dataarray = xr.DataArray(...)
hillshaded_dataarray = hillshade(my_dataarray)

Check out the user guide here.


title title

Dependencies

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.

title

Notes on GDAL

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.

Citation

Cite our code:

makepath/xarray-spatial, https://github.com/makepath/xarray-spatial, Β©2020-2023.