python library Whitebox

Published: Tue 04 November 2025
By Alex

In python.

Python Library Whitebox

Here is an example of n methods that I discovered recently in Python library Whitebox.

Well I am interested in processing geotiff and want to use whitebox for that. Get the library here. Here is a good place to start: WhiteboxTools Python API Documentation or [jupyter notebook examples](https://colab.research.google.com/github/giswqs/whitebox-python/blob/master/examples/whitebox.ipynb

My First Case

Read a geotiff file and get its basic info:

from whitebox.whitebox_tools import WhiteboxTools

wbt = WhiteboxTools()
wbt.set_working_dir("C:\\thisAKcode.github.io\\Pelican\\content\\other")
wbt.read_geotiff("Terrain_S_878.tif")
etc
etc
In [1]:
# the Jupyter Notebook server can use a different Python interpreter for its kernel 
# than the iterpreter used to launch the server itself. 
import sys
print(sys.executable)
C:\Python39\python.exe
In [ ]:
import rasterio
import whitebox
from whitebox.whitebox_tools import WhiteboxTools


print(whitebox.__file__)

wbt = WhiteboxTools()

# wbt = whitebox.WhiteboxTools()

# testdata_path = files("whitebox").joinpath("data")
wbt.set_working_dir("C:\\thisAKcode.github.io\\Pelican\\content\\other")
tif_file = "Terrain_S_878.tif"
# load a GeoTIFF file
# call whiteboxtool

wbt.feature_preserving_smoothing("DEM.tif", "smoothed.tif", filter=9)
wbt.breach_depressions("smoothed.tif", "breached.tif")
wbt.d_inf_flow_accumulation("breached.tif", "flow_accum.tif")
import rasterio
import matplotlib.pyplot as plt

tif_path = r"C:\thisAKcode.github.io\Pelican\content\other\Terrain_S_878.tif"

with rasterio.open(tif_path) as src:
    band1 = src.read(1)  # Read the first band

plt.imshow(band1, cmap='terrain')
plt.title("Terrain_S_878.tif")
plt.colorbar()
plt.show()
C:\Python39\lib\site-packages\whitebox\__init__.py
.\whitebox_tools.exe --run="FeaturePreservingSmoothing" --wd="C:\thisAKcode.github.io\Pelican\content\other" --dem='DEM.tif' --output='smoothed.tif' --filter=9 --norm_diff=15.0 --num_iter=3 --max_diff=0.5 -v --compress_rasters=False

*****************************************
* Welcome to FeaturePreservingSmoothing *
* Powered by WhiteboxTools              *
* www.whiteboxgeo.com                   *
*****************************************
Reading data...
thread 'main' panicked at whitebox-tools-app\src\main.rs:72:21:
The system cannot find the file specified. (os error 2)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
.\whitebox_tools.exe --run="BreachDepressions" --wd="C:\thisAKcode.github.io\Pelican\content\other" --dem='smoothed.tif' --output='breached.tif' -v --compress_rasters=False

********************************
* Welcome to BreachDepressions *
* Powered by WhiteboxTools     *
* www.whiteboxgeo.com          *
********************************
Reading data...
thread 'main' panicked at whitebox-tools-app\src\main.rs:72:21:
The system cannot find the file specified. (os error 2)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
.\whitebox_tools.exe --run="DInfFlowAccumulation" --wd="C:\thisAKcode.github.io\Pelican\content\other" --input='breached.tif' --output='flow_accum.tif' --out_type=Specific Contributing Area -v --compress_rasters=False

***********************************
* Welcome to DInfFlowAccumulation *
* Powered by WhiteboxTools        *
* www.whiteboxgeo.com             *
***********************************
Reading data...
thread 'main' panicked at whitebox-tools-app\src\main.rs:72:21:
The system cannot find the file specified. (os error 2)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
In [ ]:
 
In [ ]:
 

links

social