122 lidar
LiDAR data analysis and visualization with whitebox and geemap
Create a new conda env to install required packages:
conda create -n geo python
conda activate geo
conda install -c conda-forge mamba
mamba install -c conda-forge pygis
pip install laspy[lazrs]
Uncomment the following line to install packages in Google Colab.
In [ ]:
Copied!
# !pip install geemap[lidar]
# !pip install geemap[lidar]
Import libraries¶
In [ ]:
Copied!
import os
import geemap
import whitebox
import os
import geemap
import whitebox
Set up whitebox¶
In [ ]:
Copied!
wbt = whitebox.WhiteboxTools()
wbt.set_working_dir(os.getcwd())
wbt.set_verbose_mode(False)
wbt = whitebox.WhiteboxTools()
wbt.set_working_dir(os.getcwd())
wbt.set_verbose_mode(False)
Download sample data¶
In [ ]:
Copied!
url = "https://github.com/giswqs/data/raw/main/lidar/madison.laz"
if not os.path.exists("madison.laz"):
geemap.download_file(url)
url = "https://github.com/giswqs/data/raw/main/lidar/madison.laz"
if not os.path.exists("madison.laz"):
geemap.download_file(url)
Read LAS/LAZ data¶
In [ ]:
Copied!
laz = geemap.read_lidar("madison.laz")
laz = geemap.read_lidar("madison.laz")
In [ ]:
Copied!
laz
laz
In [ ]:
Copied!
str(laz.header.version)
str(laz.header.version)
Upgrade file version¶
In [ ]:
Copied!
las = geemap.convert_lidar(laz, file_version="1.4")
las = geemap.convert_lidar(laz, file_version="1.4")
In [ ]:
Copied!
str(las.header.version)
str(las.header.version)
Write LAS data¶
In [ ]:
Copied!
geemap.write_lidar(las, "madison.las")
geemap.write_lidar(las, "madison.las")
Histogram analysis¶
In [ ]:
Copied!
wbt.lidar_histogram("madison.las", "histogram.html")
wbt.lidar_histogram("madison.las", "histogram.html")
Visualize LiDAR data¶
In [ ]:
Copied!
geemap.view_lidar("madison.las")
geemap.view_lidar("madison.las")
Remove outliers¶
In [ ]:
Copied!
wbt.lidar_elevation_slice("madison.las", "madison_rm.las", minz=0, maxz=450)
wbt.lidar_elevation_slice("madison.las", "madison_rm.las", minz=0, maxz=450)
Visualize LiDAR data after removing outliers¶
In [ ]:
Copied!
geemap.view_lidar("madison_rm.las", cmap="terrain")
geemap.view_lidar("madison_rm.las", cmap="terrain")
Create DSM¶
In [ ]:
Copied!
wbt.lidar_digital_surface_model(
"madison_rm.las", "dsm.tif", resolution=1.0, minz=0, maxz=450
)
wbt.lidar_digital_surface_model(
"madison_rm.las", "dsm.tif", resolution=1.0, minz=0, maxz=450
)
In [ ]:
Copied!
geemap.add_crs("dsm.tif", epsg=2255)
geemap.add_crs("dsm.tif", epsg=2255)
Visualize DSM¶
In [ ]:
Copied!
m = geemap.Map()
m.add_raster("dsm.tif", colormap="terrain", layer_name="DSM")
m
m = geemap.Map()
m.add_raster("dsm.tif", colormap="terrain", layer_name="DSM")
m
Create DEM¶
In [ ]:
Copied!
wbt.remove_off_terrain_objects("dsm.tif", "dem.tif", filter=25, slope=15.0)
wbt.remove_off_terrain_objects("dsm.tif", "dem.tif", filter=25, slope=15.0)
Visualize DEM¶
In [ ]:
Copied!
m.add_raster("dem.tif", colormap="terrain", layer_name="DEM")
m
m.add_raster("dem.tif", colormap="terrain", layer_name="DEM")
m
Create CHM¶
In [ ]:
Copied!
chm = wbt.subtract("dsm.tif", "dem.tif", "chm.tif")
chm = wbt.subtract("dsm.tif", "dem.tif", "chm.tif")
In [ ]:
Copied!
m.add_raster("chm.tif", colormap="gist_earth", layer_name="CHM")
m
m.add_raster("chm.tif", colormap="gist_earth", layer_name="CHM")
m