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.path.expanduser('~/Downloads')
dem = os.path.join(out_dir, 'dem.tif')
if not os.path.exists(dem):
dem_url = 'https://drive.google.com/file/d/1vRkAWQYsLWCi6vcTMk8vLxoXMFbdMFn8/view?usp=sharing'
leafmap.download_from_gdrive(dem_url, 'dem.tif', out_dir, unzip=False)
out_dir = os.path.expanduser('~/Downloads')
dem = os.path.join(out_dir, 'dem.tif')
if not os.path.exists(dem):
dem_url = 'https://drive.google.com/file/d/1vRkAWQYsLWCi6vcTMk8vLxoXMFbdMFn8/view?usp=sharing'
leafmap.download_from_gdrive(dem_url, 'dem.tif', out_dir, unzip=False)
Create an interactive map.
In [4]:
Copied!
Map = leafmap.Map()
Map
Map = leafmap.Map()
Map
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
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()
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:
2022-03-14