Skip to content

08 whitebox

image image image

Using WhiteboxTools with leafmap

Uncomment the following line to install leafmap if needed.

1
# !pip install leafmap
1
2
import os
import leafmap

Download a sample DEM dataset.

1
2
3
4
5
6
out_dir = os.getcwd()
dem = os.path.join(out_dir, "dem.tif")
dem_url = (
    "https://drive.google.com/file/d/1vRkAWQYsLWCi6vcTMk8vLxoXMFbdMFn8/view?usp=sharing"
)
leafmap.download_file(dem_url, "dem.tif", unzip=False)

Create an interactive map.

1
2
Map = leafmap.Map()
Map

Use the built-in toolbox to perform geospatial analysis. For example, you can perform depression filling using the sample DEM dataset downloaded in the above step.

Display the toolbox using the default mode.

1
leafmap.whiteboxgui()

Display the toolbox using the collapsible tree mode. Note that the tree mode does not support Google Colab.

1
leafmap.whiteboxgui(tree=True)

Perform geospatial analysis using the whitebox package.

1
2
import os
import pkg_resources
1
2
wbt = leafmap.WhiteboxTools()
wbt.verbose = False
1
2
3
4
5
6
# identify the sample data directory of the package
data_dir = os.path.dirname(pkg_resources.resource_filename("whitebox", "testdata/"))
wbt.set_working_dir(data_dir)

wbt.feature_preserving_smoothing("DEM.tif", "smoothed.tif", filter=9)
wbt.breach_depressions("smoothed.tif", "breached.tif")