08 whitebox
In [1]:
Copied!
# !pip install leafmap
# !pip install leafmap
In [2]:
Copied!
import os
import leafmap
import os
import leafmap
Download a sample DEM dataset.
In [3]:
Copied!
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)
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)
dem.tif already exists. Skip downloading. Set overwrite=True to overwrite.
Out[3]:
'/home/runner/work/leafmap/leafmap/docs/notebooks/dem.tif'
Create an interactive map.
In [4]:
Copied!
Map = leafmap.Map()
Map
Map = leafmap.Map()
Map
Out[4]:
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.
In [5]:
Copied!
leafmap.whiteboxgui()
leafmap.whiteboxgui()
Downloading WhiteboxTools pre-compiled binary for first time use ... Decompressing WhiteboxTools_linux_amd64.zip ... WhiteboxTools package directory: /usr/share/miniconda3/envs/test/lib/python3.10/site-packages/whitebox Downloading testdata ...
Display the toolbox using the collapsible tree mode. Note that the tree mode does not support Google Colab.
In [6]:
Copied!
leafmap.whiteboxgui(tree=True)
leafmap.whiteboxgui(tree=True)
Perform geospatial analysis using the whitebox package.
In [7]:
Copied!
import os
import pkg_resources
import os
import pkg_resources
In [8]:
Copied!
wbt = leafmap.WhiteboxTools()
wbt.verbose = False
wbt = leafmap.WhiteboxTools()
wbt.verbose = False
In [9]:
Copied!
# 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")
# 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")
Out[9]:
0
Last update:
2023-09-22
Created: 2023-09-22
Created: 2023-09-22