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)
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()
In [ ]:
In [ ]: