{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/gee-community/geemap/blob/master/examples/notebooks/55_lidar.ipynb)\n", "[![image](https://mybinder.org/badge_logo.svg)](https://gishub.org/geemap-binder)\n", "\n", "**LiDAR data analysis and visualization with whitebox and geemap**\n", "\n", "Create a new conda env to install required packages:\n", "\n", "```bash\n", "conda create -n geo python\n", "conda activate geo\n", "conda install -c conda-forge mamba\n", "mamba install -c conda-forge pygis\n", "pip install laspy[lazrs]\n", "```\n", "\n", "Uncomment the following line to install packages in Google Colab." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install geemap[lidar]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import libraries" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import geemap\n", "import whitebox" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Set up whitebox" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wbt = whitebox.WhiteboxTools()\n", "wbt.set_working_dir(os.getcwd())\n", "wbt.set_verbose_mode(False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download sample data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = 'https://github.com/giswqs/data/raw/main/lidar/madison.laz'\n", "if not os.path.exists('madison.laz'):\n", " geemap.download_file(url)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read LAS/LAZ data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "laz = geemap.read_lidar('madison.laz')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "laz" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "str(laz.header.version)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Upgrade file version" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "las = geemap.convert_lidar(laz, file_version='1.4')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "str(las.header.version)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Write LAS data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.write_lidar(las, 'madison.las')" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## Histogram analysis" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wbt.lidar_histogram('madison.las', 'histogram.html')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualize LiDAR data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.view_lidar('madison.las')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Remove outliers" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wbt.lidar_elevation_slice(\"madison.las\", \"madison_rm.las\", minz=0, maxz=450)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualize LiDAR data after removing outliers" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.view_lidar('madison_rm.las', cmap='terrain')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create DSM" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wbt.lidar_digital_surface_model(\n", " 'madison_rm.las', 'dsm.tif', resolution=1.0, minz=0, maxz=450\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "jp-MarkdownHeadingCollapsed": true, "tags": [] }, "outputs": [], "source": [ "geemap.add_crs(\"dsm.tif\", epsg=2255)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualize DSM" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_raster('dsm.tif', palette='terrain', layer_name='DSM')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create DEM" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wbt.remove_off_terrain_objects('dsm.tif', 'dem.tif', filter=25, slope=15.0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualize DEM" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.add_raster('dem.tif', palette='terrain', layer_name='DEM')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create CHM" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "chm = wbt.subtract('dsm.tif', 'dem.tif', 'chm.tif')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.add_raster('chm.tif', palette='gist_earth', layer_name='CHM')\n", "m" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }