48 lidar
Visualizing LiDAR data in 3D with only one line of code
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# !pip install leafmap
# !pip install leafmap
In [2]:
Copied!
# !pip install leafmap[lidar] open3d
# !pip install leafmap[lidar] open3d
In [3]:
Copied!
import os
import leafmap
import os
import leafmap
Download a sample LiDAR dataset from Google Drive. The zip file is 52.1 MB and the uncompressed LAS file is 109 MB.
In [4]:
Copied!
url = "https://open.gishub.org/data/lidar/madison.zip"
filename = "madison.las"
url = "https://open.gishub.org/data/lidar/madison.zip"
filename = "madison.las"
In [5]:
Copied!
leafmap.download_file(url, "madison.zip", unzip=True)
leafmap.download_file(url, "madison.zip", unzip=True)
Downloading... From: https://open.gishub.org/data/lidar/madison.zip To: /home/runner/work/leafmap/leafmap/docs/notebooks/madison.zip
0%| | 0.00/54.7M [00:00<?, ?B/s]
58%|█████▊ | 31.5M/54.7M [00:00<00:00, 310MB/s]
100%|██████████| 54.7M/54.7M [00:00<00:00, 303MB/s]
Extracting files...
Out[5]:
'/home/runner/work/leafmap/leafmap/docs/notebooks/madison.zip'
Read the LiDAR data
In [6]:
Copied!
las = leafmap.read_lidar(filename)
las = leafmap.read_lidar(filename)
The LAS header.
In [7]:
Copied!
las.header
las.header
Out[7]:
<LasHeader(1.3, <PointFormat(1, 0 bytes of extra dims)>)>
The number of points.
In [8]:
Copied!
las.header.point_count
las.header.point_count
Out[8]:
4068294
The list of features.
In [9]:
Copied!
list(las.point_format.dimension_names)
list(las.point_format.dimension_names)
Out[9]:
['X', 'Y', 'Z', 'intensity', 'return_number', 'number_of_returns', 'scan_direction_flag', 'edge_of_flight_line', 'classification', 'synthetic', 'key_point', 'withheld', 'scan_angle_rank', 'user_data', 'point_source_id', 'gps_time']
Inspect data.
In [10]:
Copied!
las.X
las.X
Out[10]:
array([5324343, 5324296, 5323993, ..., 5784049, 5784359, 5784667], dtype=int32)
In [11]:
Copied!
las.Y
las.Y
Out[11]:
array([8035264, 8035347, 8035296, ..., 7550110, 7550066, 7550026], dtype=int32)
In [12]:
Copied!
las.Z
las.Z
Out[12]:
array([36696, 34835, 34826, ..., 36839, 36858, 36842], dtype=int32)
In [13]:
Copied!
las.intensity
las.intensity
Out[13]:
array([ 9, 41, 24, ..., 87, 80, 95], dtype=uint16)
Visualize LiDAR data using the pyvista backend.
In [14]:
Copied!
leafmap.view_lidar(filename, cmap="terrain", backend="pyvista")
leafmap.view_lidar(filename, cmap="terrain", backend="pyvista")
Visualize LiDAR data using the ipygany backend.
In [15]:
Copied!
leafmap.view_lidar(filename, backend="ipygany", background="white")
leafmap.view_lidar(filename, backend="ipygany", background="white")
Visualize LiDAR data using the panel backend.
In [16]:
Copied!
leafmap.view_lidar(filename, cmap="terrain", backend="panel", background="white")
leafmap.view_lidar(filename, cmap="terrain", backend="panel", background="white")
Visualize LiDAR data using the open3d backend.
In [17]:
Copied!
leafmap.view_lidar(filename, backend="open3d")
leafmap.view_lidar(filename, backend="open3d")