LiDAR Layer Example¶
This notebook demonstrates LiDAR point cloud visualization using the maplibre-gl-lidar package.
Key features:
- Load LAS, LAZ, and COPC (Cloud-Optimized Point Cloud) files
- Color schemes: elevation, intensity, classification, RGB
- Interactive control panel with classification filtering
- Streaming support for large COPC files
- Point picking with attribute tooltips
In [ ]:
Copied!
# %pip install anymap-ts
# %pip install anymap-ts
Basic LiDAR with MapLibre (Interactive Control Panel)¶
In [ ]:
Copied!
from anymap_ts import MapLibreMap
# Create map centered on Autzen Stadium, Eugene, Oregon
m = MapLibreMap(center=[-123.07, 44.05], zoom=15, pitch=60, bearing=-20, height="800px")
m.add_basemap("CartoDB.DarkMatter")
# Add the LiDAR control panel
# Users can load files via the UI, change color schemes, filter classifications, etc.
m.add_lidar_control(
position="top-left",
collapsed=False,
color_scheme="classification",
pickable=True,
point_size=2,
panel_max_height=600,
)
m
from anymap_ts import MapLibreMap
# Create map centered on Autzen Stadium, Eugene, Oregon
m = MapLibreMap(center=[-123.07, 44.05], zoom=15, pitch=60, bearing=-20, height="800px")
m.add_basemap("CartoDB.DarkMatter")
# Add the LiDAR control panel
# Users can load files via the UI, change color schemes, filter classifications, etc.
m.add_lidar_control(
position="top-left",
collapsed=False,
color_scheme="classification",
pickable=True,
point_size=2,
panel_max_height=600,
)
m
Programmatic LiDAR Loading from URL¶
Load LiDAR data directly from a URL without the control panel UI.
In [ ]:
Copied!
from anymap_ts import MapLibreMap
# Autzen Stadium COPC dataset
AUTZEN_URL = "https://s3.amazonaws.com/hobu-lidar/autzen-classified.copc.laz"
m2 = MapLibreMap(
center=[-123.07, 44.05],
zoom=15,
pitch=60,
)
m2.add_basemap("CartoDB.DarkMatter")
# Load LiDAR from URL
m2.add_lidar_layer(
source=AUTZEN_URL,
name="autzen",
color_scheme="elevation",
point_size=2,
opacity=1.0,
pickable=True,
auto_zoom=True,
streaming_mode=True,
)
m2
from anymap_ts import MapLibreMap
# Autzen Stadium COPC dataset
AUTZEN_URL = "https://s3.amazonaws.com/hobu-lidar/autzen-classified.copc.laz"
m2 = MapLibreMap(
center=[-123.07, 44.05],
zoom=15,
pitch=60,
)
m2.add_basemap("CartoDB.DarkMatter")
# Load LiDAR from URL
m2.add_lidar_layer(
source=AUTZEN_URL,
name="autzen",
color_scheme="elevation",
point_size=2,
opacity=1.0,
pickable=True,
auto_zoom=True,
streaming_mode=True,
)
m2
Color Scheme: Classification with Layer Control¶
Visualize LiDAR data colored by classification codes (ground, vegetation, buildings, etc.). The layer control allows toggling visibility and adjusting opacity of the LiDAR layer.
In [ ]:
Copied!
from anymap_ts import MapLibreMap
m3 = MapLibreMap(
center=[-123.07, 44.05],
zoom=15,
pitch=60,
)
m3.add_basemap("CartoDB.DarkMatter")
# Classification color scheme shows different land cover types
m3.add_lidar_layer(
source="https://s3.amazonaws.com/hobu-lidar/autzen-classified.copc.laz",
name="autzen-classification",
color_scheme="classification", # Ground, vegetation, buildings, etc.
point_size=2,
pickable=True,
)
# Add layer control to manage LiDAR visibility
# Note: add_layer_control should be called AFTER add_lidar_layer
m3.add_layer_control(position="top-right", collapsed=False)
m3
from anymap_ts import MapLibreMap
m3 = MapLibreMap(
center=[-123.07, 44.05],
zoom=15,
pitch=60,
)
m3.add_basemap("CartoDB.DarkMatter")
# Classification color scheme shows different land cover types
m3.add_lidar_layer(
source="https://s3.amazonaws.com/hobu-lidar/autzen-classified.copc.laz",
name="autzen-classification",
color_scheme="classification", # Ground, vegetation, buildings, etc.
point_size=2,
pickable=True,
)
# Add layer control to manage LiDAR visibility
# Note: add_layer_control should be called AFTER add_lidar_layer
m3.add_layer_control(position="top-right", collapsed=False)
m3
Color Scheme: Intensity¶
Visualize LiDAR data colored by return intensity values.
In [ ]:
Copied!
from anymap_ts import MapLibreMap
m4 = MapLibreMap(
center=[-123.07, 44.05],
zoom=15,
pitch=60,
)
m4.add_basemap("CartoDB.DarkMatter")
# Intensity color scheme highlights reflectivity
m4.add_lidar_layer(
source="https://s3.amazonaws.com/hobu-lidar/autzen-classified.copc.laz",
name="autzen-intensity",
color_scheme="intensity",
point_size=2,
pickable=True,
)
m4
from anymap_ts import MapLibreMap
m4 = MapLibreMap(
center=[-123.07, 44.05],
zoom=15,
pitch=60,
)
m4.add_basemap("CartoDB.DarkMatter")
# Intensity color scheme highlights reflectivity
m4.add_lidar_layer(
source="https://s3.amazonaws.com/hobu-lidar/autzen-classified.copc.laz",
name="autzen-intensity",
color_scheme="intensity",
point_size=2,
pickable=True,
)
m4
Change Color Scheme Dynamically¶
In [ ]:
Copied!
# Change the color scheme of an existing LiDAR layer
m2.set_lidar_color_scheme("classification")
# Change the color scheme of an existing LiDAR layer
m2.set_lidar_color_scheme("classification")
In [ ]:
Copied!
# Change to intensity
m2.set_lidar_color_scheme("intensity")
# Change to intensity
m2.set_lidar_color_scheme("intensity")
In [ ]:
Copied!
# Change back to elevation
m2.set_lidar_color_scheme("elevation")
# Change back to elevation
m2.set_lidar_color_scheme("elevation")
Adjust Point Size and Opacity¶
In [ ]:
Copied!
# Increase point size
m2.set_lidar_point_size(4)
# Increase point size
m2.set_lidar_point_size(4)
In [ ]:
Copied!
# Decrease opacity
m2.set_lidar_opacity(0.7)
# Decrease opacity
m2.set_lidar_opacity(0.7)
In [ ]:
Copied!
# Reset to defaults
m2.set_lidar_point_size(2)
m2.set_lidar_opacity(1.0)
# Reset to defaults
m2.set_lidar_point_size(2)
m2.set_lidar_opacity(1.0)
Remove LiDAR Layer¶
In [ ]:
Copied!
# Remove a specific LiDAR layer
m2.remove_lidar_layer("autzen")
# Remove a specific LiDAR layer
m2.remove_lidar_layer("autzen")
Export to HTML¶
In [ ]:
Copied!
m3.to_html("lidar_layer_example.html")
m3.to_html("lidar_layer_example.html")