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[lidar] open3d
# !pip install leafmap[lidar] open3d
In [2]:
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 [3]:
Copied!
url = (
'https://drive.google.com/file/d/1H_X1190vL63BoFYa_cVBDxtIa8rG-Usb/view?usp=sharing'
)
filename = 'madison.las'
url = (
'https://drive.google.com/file/d/1H_X1190vL63BoFYa_cVBDxtIa8rG-Usb/view?usp=sharing'
)
filename = 'madison.las'
In [4]:
Copied!
if not os.path.exists(filename):
leafmap.download_file(url, 'madison.zip', unzip=True)
if not os.path.exists(filename):
leafmap.download_file(url, 'madison.zip', unzip=True)
Downloading... From: https://drive.google.com/uc?id=1H_X1190vL63BoFYa_cVBDxtIa8rG-Usb To: /home/runner/work/geospatial-notebooks/geospatial-notebooks/docs/leafmap/madison.zip 100%|██████████| 54.7M/54.7M [00:00<00:00, 221MB/s]
Extracting files...
Read the LiDAR data
In [5]:
Copied!
las = leafmap.read_lidar(filename)
las = leafmap.read_lidar(filename)
The LAS header.
In [6]:
Copied!
las.header
las.header
Out[6]:
<LasHeader(1.3, <PointFormat(1, 0 bytes of extra dims)>)>
The number of points.
In [7]:
Copied!
las.header.point_count
las.header.point_count
Out[7]:
4068294
The list of features.
In [8]:
Copied!
list(las.point_format.dimension_names)
list(las.point_format.dimension_names)
Out[8]:
['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 [9]:
Copied!
las.X
las.X
Out[9]:
array([5324343, 5324296, 5323993, ..., 5784049, 5784359, 5784667], dtype=int32)
In [10]:
Copied!
las.Y
las.Y
Out[10]:
array([8035264, 8035347, 8035296, ..., 7550110, 7550066, 7550026], dtype=int32)
In [11]:
Copied!
las.Z
las.Z
Out[11]:
array([36696, 34835, 34826, ..., 36839, 36858, 36842], dtype=int32)
In [12]:
Copied!
las.intensity
las.intensity
Out[12]:
array([ 9, 41, 24, ..., 87, 80, 95], dtype=uint16)
Visualize LiDAR data using the pyvista backend.
In [13]:
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 [14]:
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 [15]:
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 [16]:
Copied!
# leafmap.view_lidar(filename, backend='open3d')
# leafmap.view_lidar(filename, backend='open3d')
Last update:
2022-03-14